ioscore-graphicsuibezierpath

Union UIBezierPaths rather than apend path


I have an app where I take a UIBezierPath and use it as a brush by a series of appendPath: calls. After a few goes and with really complex brush shapes the memory runs out and the app grinds to a halt. What I really want to do is a full on union exactly like Paint Code does but I can't find any way of doing this.

How would I go about unioning two or more UIBezierPaths?

EDIT:

Here is a visual of what I want to achieve dynamically.

In Paint Code you take two paths and overlap them like this: Overlapping paths in Paint Code

BUT I want to merge / union them into one new single path like:

Merged paths in Paint Code

Note that in the bottom panel of Paint Code there is code for now one single shape and this is what I want to be able to get to programatically with maybe 1000 original paths.


Solution

  • Finally a solution!!

    Using https://github.com/adamwulf/ClippingBezier you can find the intersecting points. Then you can walk through the path, turning left if clockwise or vice-versa to stay on the outside. Then you can generate a new path using the sequence of points.