thelonious / kld-intersections

A library of intersection algorithms covering all SVG shape types
BSD 3-Clause "New" or "Revised" License
343 stars 55 forks source link

intersectBezier2Circle and intersectBeziers2Rectangle return not expected result for horizontal and vertical lines #48

Open olivTo opened 4 years ago

olivTo commented 4 years ago

I'm having an issue for some particular cases of intersection with Bezier curve, when the curve is actually a line (same abscissa or same ordinate for start point, end point and control point). The return using and intersectBezier2Circle is empty. The returned point using and intersectBeziers2Rectangle is the end point. For the moment i use a work around consisting in delegate the compute to intersectCircleLine and intersectLineRectangle, but i think it would be better if these limit cases will be managed.

The use cases :

intersectBezier2Circle

const start = new Point2D(-621.1, 629);
const control = new Point2D(-461.70000000000005, 629);
const end = new Point2D(-302.3, 629);
const radius = 38.9;
Intersection.intersectBezier2Circle(start, control, end, end, radius);
result = [];

intersectBeziers2Rectangle

const start = new Point2D(-621.1, 629);
const control = new Point2D(-461.70000000000005, 629);
const end = new Point2D(-302.3, 629);
const r1 = new Point2D(-321, 609);
const r2: new Point2D(-279, 645);
Intersection.intersectBezier2Rectangle(start, control, end, r1, r2);
result = [Point2D{x: -302.3, y: 629}, Point2D{x: -302.3, y: 629}];