ClippingBezier
ClippingBezier copied to clipboard
How union two UIBezierPath together
How union two UIBezierPath together using your framework?
There's not an explicit union method. You can try using intersectionWithPath:
and differenceWithPath:
to build the union.
UIBezierPath* pathA;
UIBezierPath* pathB;
UIBezierPath* intersection = [pathA intersectionWithPath:pathB];
UIBezierPath* diffL = [pathA differenceWithPath:pathB];
UIBezierPath* diffR = [pathB differenceWithPath:pathA];
UIBezierPath* union = [UIBezierPath bezierPath];
[union appendPath:intersection];
[union appendPath:diffL];
[union appendPath:diffR];
I think that'll do roughly want you want, though it'll have path lins at the intersections of the two paths instead of a smooth union. stroked path would look odd, but filled path would be ok I believe.
I found the union path method in the latest library, but an error result is returned.
UIBezierPath *pathA = [UIBezierPath bezierPath];
[pathA addArcWithCenter:CGPointMake(100, 100) radius:100 startAngle:0 endAngle:M_PI*2 clockwise:YES];
[pathA closePath];
UIBezierPath *pathB = [UIBezierPath bezierPath];
[pathB addArcWithCenter:CGPointMake(100, 102) radius:100 startAngle:0 endAngle:M_PI*2 clockwise:YES];
[pathB closePath];
NSArray *result = [pathA unionWithPath:pathB];
@adamwulf
Unfortunately there's some problems with paths that have very close derivatives. these two circles meet at almost tange points, and i suspect that's some of the issue. does it return the correct results if the two circles are further apart so that they're intersections have a wider angle?
@ArtMartiros @Adenc ~~Maybe this repo can solve the issue.~~
Update
Since iOS 16 (or macOS 13), CGPath provides path calculations like union
which you can use directly and more performant than some third party libraries.