Benjohn
Benjohn

Reputation: 13887

Clipping a CGPathRef or UIBezierPath

Given that I have a CGPathRef, or a UIBezierPath, or some other equivalent iOS representation, are there built in library functions that I can use to compute a clip of this object for me?

Note To clarify, I am not asking to be able to draw a path with clipping. I want to obtain an actual clipped path, as a new path.

Upvotes: 1

Views: 853

Answers (1)

adam.wulf
adam.wulf

Reputation: 2169

Check out my similar answer to this other question. I wrote a library that will let you calculate the intersections between any two UIBezierPath and calculate the clipped path between them. The library is at https://github.com/adamwulf/ClippingBezier.

While that other questions deals with the intersection of shapes, you can also simply split two paths into component pieces.

NSArray* clippedPathSegments = [UIBezierPath redAndGreenAndBlueSegmentsCreatedFrom:path1 bySlicingWithPath:path2 andNumberOfBlueShellSegments:NULL];

That method has a bit of an awkward name, it's used internally for the better named uniqueShapesCreatedFromSlicingWithUnclosedPath: method, but should do what you want.

Upvotes: 1

Related Questions