Open prasad1120 opened 4 years ago
This is a strange one. It may take me a while to find the root cause, but in playing around with it I found that reversing the splitterPath with bezierPathByReversingPath
gives the correct results of 2 shapes.
I think I have found what was wrong. In the splittingPath, there is a place where the end of addLine
doesn't end at the point from where addArc
is supposed to start. I'm not aware how this fix that I made affected the splitting process. I'm able to get desired results now even without using bezierPathByReversingPath
.
Glad you found a way to get it to work. Can you post the splitter and splitting paths that don't work unless you make that 1 adjustment to the addLine call? and post the fixed splitting path too? that'll help me track down the problem when i have the test case for fail/succeed with that one small change. thanks!
No change was made in splitterPath
splitterPath.debugDescription:
path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(35.000000, 49.497475)];
[path addLineToPoint:CGPointMake(185.000000, 49.497475)];
[path addLineToPoint:CGPointMake(185.000000, 105.000000)];
[path addLineToPoint:CGPointMake(35.000000, 105.000000)];
[path closePath];
(before correction) splittingPath
that returns 1 value after splitting:
path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(35.000000, 55.000000)];
[path addCurveToPoint:CGPointMake(35.000000, 55.000000) controlPoint1:CGPointMake(35.000000, 55.000000) controlPoint2:CGPointMake(35.000000, 55.000000)];
[path addLineToPoint:CGPointMake(35.000000, 35.000000)];
[path addLineToPoint:CGPointMake(35.000000, 105.000000)];
[path addCurveToPoint:CGPointMake(35.000000, 105.000000) controlPoint1:CGPointMake(35.000000, 105.000000) controlPoint2:CGPointMake(35.000000, 105.000000)];
[path addLineToPoint:CGPointMake(185.000000, 105.000000)];
[path addLineToPoint:CGPointMake(185.000000, 105.000000)];
[path addCurveToPoint:CGPointMake(185.000000, 105.000000) controlPoint1:CGPointMake(185.000000, 105.000000) controlPoint2:CGPointMake(185.000000, 105.000000)];
[path addLineToPoint:CGPointMake(185.000000, 55.000000)];
[path addLineToPoint:CGPointMake(185.000000, 55.000000)];
[path addCurveToPoint:CGPointMake(185.000000, 55.000000) controlPoint1:CGPointMake(185.000000, 55.000000) controlPoint2:CGPointMake(185.000000, 55.000000)];
[path addLineToPoint:CGPointMake(220.000000, 55.000000)];
[path addLineToPoint:CGPointMake(200.000000, 47.577787)];
[path addCurveToPoint:CGPointMake(173.786797, 55.000000) controlPoint1:CGPointMake(192.117733, 52.430540) controlPoint2:CGPointMake(183.043110, 55.000000)];
[path addLineToPoint:CGPointMake(35.000000, 55.000000)];
[path closePath];
(after correction) splittingPath
that returns 2 values after splitting:
path = [UIBezierPath bezierPath];
[path moveToPoint:CGPointMake(35.000000, 55.000000)];
[path addCurveToPoint:CGPointMake(35.000000, 55.000000) controlPoint1:CGPointMake(35.000000, 55.000000) controlPoint2:CGPointMake(35.000000, 55.000000)];
[path addLineToPoint:CGPointMake(35.000000, 105.000000)];
[path addLineToPoint:CGPointMake(35.000000, 105.000000)];
[path addCurveToPoint:CGPointMake(35.000000, 105.000000) controlPoint1:CGPointMake(35.000000, 105.000000) controlPoint2:CGPointMake(35.000000, 105.000000)];
[path addLineToPoint:CGPointMake(185.000000, 105.000000)];
[path addLineToPoint:CGPointMake(185.000000, 105.000000)];
[path addCurveToPoint:CGPointMake(185.000000, 105.000000) controlPoint1:CGPointMake(185.000000, 105.000000) controlPoint2:CGPointMake(185.000000, 105.000000)];
[path addLineToPoint:CGPointMake(185.000000, 55.000000)];
[path addLineToPoint:CGPointMake(185.000000, 55.000000)];
[path addCurveToPoint:CGPointMake(185.000000, 55.000000) controlPoint1:CGPointMake(185.000000, 55.000000) controlPoint2:CGPointMake(185.000000, 55.000000)];
[path addLineToPoint:CGPointMake(220.000000, 55.000000)];
[path addLineToPoint:CGPointMake(200.000000, 47.577787)];
[path addCurveToPoint:CGPointMake(173.786797, 55.000000) controlPoint1:CGPointMake(192.117733, 52.430540) controlPoint2:CGPointMake(183.043110, 55.000000)];
[path addLineToPoint:CGPointMake(35.000000, 55.000000)];
[path closePath];
I hope this helps :)
awesome :) many thanks for this test case
Hi, I am trying to split the green part into 2 by considering the black box as the splitter path using
uniqueShapesCreatedFromSlicing
. It is working in most cases but there are some corner cases where it doesn't. Here,uniqueShapesCreatedFromSlicing
returns 1 value in the array instead of 2.Note: Consider the black box to be complete.
subShapes[0]!.fullPath().debugDescription:
splitterPath.debugDescription:
splittingPath.debugDescription: