CGPointとCGPathRefを作成してから、CGPointがCGPathRef内にあるかどうかを調べようとしています。コードは次のとおりです。
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);
}
}
出力は次のようになります。
Path is NOT a Rectangle!
Hit Point Outside: x=77.000000, y=77.000000
パスは明らかに長方形であり、ポイントは閉じたパスの内側にあります。ここで私が間違っていることを教えてください。