开发者

How to figure out that given point is inside the rectangle or not

开发者 https://www.devze.com 2023-03-17 16:37 出处:网络
i am working on app in which i want to draw an Rectangle.for draw a rectangle i have two CGRECT point.after draw a rectangle i have to pass a point and check whether the given point is lying inside th

i am working on app in which i want to draw an Rectangle.for draw a rectangle i have two CGRECT point.after draw a rectangle i have to pass a point and check whether the given point is lying inside the rectangle or not.can someone help me.Thanks

-(void)touchBeganAtPoint:(CGPoint)point{

    if (isDrawingCompleted) {        
        match = NSNotFound;

        for (NSInteger i = 0; i < [pointArray count]; i++)
        {
            NSValue *touchPointValue = [pointArray objectAtIndex:i];
            CGPoint currentPoint = [touchPointValue CGPointValue];
            CGRect controlPointRect = [self controlPointRectForPoint:currentPoint];

            if (CGRectContainsPoint(controlPointRect, point))
            {
      开发者_StackOverflow中文版          match = i;
                break;
            }
        }
    }
}

point is the variable which i have to check lie inside the rectangle which will make with two point store in point array.point array have always two point.


Use CGRectContainsPoint.

bool CGRectContainsPoint (
   CGRect rect,
   CGPoint point
);


Use CGRectContainsPoint function

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号