adamwulf / ClippingBezier

ClippingBezier calculates intersection points, paths, and shapes between two UIBezierPaths
http://getlooseleaf.com/opensource/
MIT License
254 stars 34 forks source link

Wrong intersect result for Quad curve #13

Closed Realank closed 3 years ago

Realank commented 4 years ago

        shapePath1 = [UIBezierPath bezierPath];
        [shapePath1 moveToPoint:CGPointMake(100, 100)];
        [shapePath1 addQuadCurveToPoint:CGPointMake(300, 100) controlPoint:CGPointMake(200, 200)];

        [[UIColor purpleColor] setStroke];
        [shapePath1 setLineWidth:3];
        [shapePath1 stroke];

        shapePath2 = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(190, 90, 20, 220)];

        [[UIColor greenColor] setStroke];
        [shapePath2 setLineWidth:3];
        [shapePath2 stroke];

        BOOL contains = NO;
        NSArray *intersections = [shapePath1 findIntersectionsWithClosedPath:shapePath2 andBeginsInside:&contains];
        NSLog(@"有%ld个点相交,是否内含 %d", intersections.count, contains);

        for (DKUIBezierPathIntersectionPoint *intersection in intersections) {
            [[UIColor redColor] setFill];
            CGPoint p = intersection.location1;

            [[UIBezierPath bezierPathWithArcCenter:p radius:7 startAngle:0 endAngle:2 * M_PI clockwise:YES] fill];
        }

there are 2 intersections but not on curve line

adamwulf commented 4 years ago

Awesome - thanks for the report and test case, i'll take a look

adamwulf commented 3 years ago

Hi Realank! Better late than never I hope!

I've just recently properly fixed the quad intersection issue (in #19 for the curious). When i use your paths in the ClippingExampleApp, i now see the correct 2 locations:

Screen Shot 2020-11-20 at 12 02 25 AM

Many thanks for reporting this and for the clear test case