the_critic
the_critic

Reputation: 12820

Is it possible to detect intersection of CGMutablePathRef and CGRect ?

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 ?

Upvotes: 3

Views: 1228

Answers (3)

David Dunham
David Dunham

Reputation: 8339

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.)

Upvotes: 1

jstevenco
jstevenco

Reputation: 2953

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.

Upvotes: 1

CodeSmile
CodeSmile

Reputation: 64477

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.

Upvotes: 1

Related Questions