Why doesn't CGPathIsRect work? Why doesn't CGPathContainsPoint work?
-
11-11-2019 - |
Question
I am making a CGPoint and a CGPathRef then trying to find if the CGPoint is inside the CGPathRef. Here is the code:
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 0, 0);
CGPathMoveToPoint(path, NULL, 200, 0);
CGPathMoveToPoint(path, NULL, 200, 200);
CGPathMoveToPoint(path, NULL, 0, 200);
CGPathCloseSubpath(path);
CGPoint hitPoint = CGPointMake(77, 77);
if ( CGPathIsEmpty(path) )
NSLog(@"Path Is Empty!");
else
{
if ( CGPathIsRect(path, NULL) )
NSLog(@"Path is a Rectangle!");
else
{
NSLog(@"Path is NOT a Rectangle!");
if (CGPathContainsPoint(path, NULL, hitPoint, FALSE)) // FALSE or TRUE - same result
NSLog(@"Hit Point Inside: x=%f, y=%f", hitPoint.x, hitPoint.y);
else
NSLog(@"Hit Point Outside: x=%f, y=%f", hitPoint.x, hitPoint.y);
}
}
The output reads:
Path is NOT a Rectangle!
Hit Point Outside: x=77.000000, y=77.000000
The path obviously is a rectangle and the point is inside the closed path. Please clue me in on what I am doing wrong here.
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow