3

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 ?

the_critic
  • 12,720
  • 19
  • 67
  • 115

3 Answers3

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.

Community
  • 1
  • 1
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • 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