Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clip or subtract a CGMutablePathRf by another CGMutalbePathRef?

I have a rectangular CGMutablePathRef and I want to subtract a circle which lays exactly on centered on one edge of that rectangle, so the edge does not cross the circle anymore.

There seem to be no functions to intersect or subtract paths from another. How can I do it?

like image 634
Proud Member Avatar asked Jan 24 '26 14:01

Proud Member


1 Answers

You need to look at the CGContext you are drawing into and use the clipping on the context rather than the path. Apple's documentation is here.

If I understand your question, you can draw your rectangle into the context and then "clip out" the circle path. If you are filling the paths, you'll need to pay attention to the winding rules.

Alternatively, you can make your path with a series of commands such as CGPathAddLineToPoint, CGPathAddArcToPoint, etc and then stoke the path in your context. If you use this approach, you can then apply transforms to the final path for scaling and rotating as needed. Depending on what you are trying to accomplish, this may be the better approach.

like image 174
Chip Coons Avatar answered Jan 26 '26 05:01

Chip Coons



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!