ClippingBezier
ClippingBezier copied to clipboard
Wrong clipping at a right angle
Hi Adam,
If I have a right angle on both paths, in some positions the path is not being split correctly.
At first I have a working example.
Path to be split:
UIBezierPath *tilePath = [UIBezierPath bezierPath];
[tilePath moveToPoint:CGPointMake(2943, 228)];
[tilePath addLineToPoint:CGPointMake(3189, 228)];
[tilePath addLineToPoint:CGPointMake(3189, 892)];
[tilePath addLineToPoint:CGPointMake(2943, 892)];
[tilePath closePath];
Path to do the slice:
UIBezierPath *areaPath = [UIBezierPath bezierPath];
[areaPath moveToPoint:CGPointMake(0, 0)];
[areaPath addLineToPoint:CGPointMake(0, 1310)];
[areaPath addLineToPoint:CGPointMake(550, 1310)];
[areaPath addLineToPoint:CGPointMake(1490, 2240)];
[areaPath addLineToPoint:CGPointMake(1490, 2790)];
[areaPath addLineToPoint:CGPointMake(2810, 2790)];
[areaPath addLineToPoint:CGPointMake(2810, 2545)];
[areaPath addLineToPoint:CGPointMake(4190, 2545)];
[areaPath addLineToPoint:CGPointMake(4190, 890)];
[areaPath addLineToPoint:CGPointMake(3140, 890)];
[areaPath addLineToPoint:CGPointMake(3140, 0)];
[areaPath closePath];
After calling the uniqueShapesCreatedFromSlicingWithUnclosedPath I get two shapes.
NSArray* shapes = [tilePath uniqueShapesCreatedFromSlicingWithUnclosedPath:areaPath];
if(shapes.count == 2)
{
// It's perfect ;-)
}
Everything's okay here:
Now the case that doesn't work properly:
I move the tile one pixel/unit down:
UIBezierPath *tilePath = [UIBezierPath bezierPath];
[tilePath moveToPoint:CGPointMake(2943, 227)];
[tilePath addLineToPoint:CGPointMake(3189, 227)];
[tilePath addLineToPoint:CGPointMake(3189, 891)];
[tilePath addLineToPoint:CGPointMake(2943, 891)];
[tilePath closePath];
Now after calling the uniqueShapesCreatedFromSlicingWithUnclosedPath I only get one shape.
NSArray* shapes = [tilePath uniqueShapesCreatedFromSlicingWithUnclosedPath:areaPath];
if(shapes.count == 1)
{
// It's not perfect ;-(
}
Now a part of the tile is missing: