Why does this CGRectContainsPoint fail?
I guess I don't entirely understand the containsPoint method:
// test CGRect compareRect = CGRectMake(-39, -62, 39, 62); CGPoint comparePoint = CGPointMake(3, -27); if( CGRectContainsPoint(compareRect, comparePoint) ) NSLog(@"works"); else NSLog(@"doesn't work");
When I plot it the point is inside the rectangle. But it returns "doesn't work."
The 3rd and 4th parameter for CGRectMake is width, height. So compareRect is from (-39, -62) to (0, 0) which does not contain (3, -27). It's a common mistake to think that the parameters are (x1, y1, x2, y2), but they are not. Actually they are (x, y, w, h).