I'm a bit late to this question, but I had to solve something similar recently and this might help for others who stumble in here:
Is point close to the line?
I've just recently open sourced ClippingBezier which may help. It includes a category method on UIBezierPath
to determine how close an input point is to the path:
CGPoint pointOnPath = [path closestPointOnPathTo:touchPoint];
if(distance(pointOnPath, touchPoint) < 30){
// point is close to path
}
This gives you a solution that's similar to Ray's answer. I don't know the performance of CGPathCreateCopyByStrokingPath, but if you need to do this realtime with the gesture, you might want to compare to ClippingBezier as well - it's designed for this sort of realtime use case.
Is point inside minimum bounding box?
Instead, if you want to determine if the point is within the minimum bounding box of the Bezier path, not just 'close' to the path, then that's a bit trickier.
The UIBezierPath
's bounds
property isn't necessarily the minimum bounding box, it's just a bounding box. To find the minimum, I think you'd have to:
- Incrementally rotate the path around its center, checking for the smallest bounds through each degree of 90 degrees of rotation
- Once you've found the smallest rotation, then apply that same transform to the touchPoint
- Then check that transformed touchPoint to the transformed path's bounds
This won't get you the exact minimum bounding box, but it'll be close enough in practice. To get the exact minimum bounding box, it'd take a lot more math, as described in this SO answer.