I have a sprite with its bounding box and I want to detect the intersection of it with a CGMutablePathRef. How would I do that ?
Asked
Active
Viewed 1,217 times
3 Answers
1
There's no readily available solution for that. It also depends on what features of CGPath you are using. If it's just a series of points, you can use a regular line with rectangle intersection test.
Everything else (eg bezier curve and rectangle intersection) is going to be very complicated.
-
Thank you for your response. I indeed do not have a curve but a hexagon shape. Do I have to create these lines separate from the hexagon or are they handled as separate lines anyway ? – the_critic Dec 31 '11 at 16:08
1
If it's a pure rectangular comparison, you can use CGPathGetBoundingBox
to obtain the path's bounding box and then use CGRectIntersectsRect
to determine if the intersection occurs.

jstevenco
- 2,913
- 2
- 25
- 36
-
This is useful too, thank you, but for me it is just a temporary solution as I do not want to detect the path's bounding box, but rather its proper shape. – the_critic Dec 31 '11 at 16:25
1
Depending on performance needs, draw into a 1-bit deep bitmap, clipping to the CGRect. Then scan for a pixel. (This technique tends to be more appropriate for testing to a point.)

David Dunham
- 8,139
- 3
- 28
- 41
-
This approach also appeals to me, thank you very much, I'll try it out. – the_critic Dec 31 '11 at 16:23