Determine if point is within bounding box

后端 未结 7 1939
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 11:02

How would you determine if a given point is within the bounding box?

My point is 48.847172 , 2.386597.

Boundingbox:

    \"48.7998602295\",
           


        
7条回答
  •  心在旅途
    2020-12-08 11:50

    There are quite nice utility methods for CGRect and CGPoint (assuming you don't mind fact that they are using CGFloat for storing coordinates - and looking at your values, you don't :-) ).

    You can do it like that:

    // Create bounding box
    CGRect area = CGRectMake(x, y, width, height);
    
    // Define point
    CGPoint point = CGPointMake(pX, pY);
    
    /Check
    BOOL isInside = CGRectContainsPoint(area, point);
    

提交回复
热议问题