fix: Curve endpoint intersection (#10640)

* fix: Curve endpoint intersection

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>

* fix debug

---------

Signed-off-by: Mark Tolmacs <mark@lazycat.hu>
Co-authored-by: dwelle <5153846+dwelle@users.noreply.github.com>
This commit is contained in:
Márk Tolmács
2026-01-12 15:02:56 +01:00
committed by GitHub
parent b9a255407f
commit da59205846
2 changed files with 24 additions and 6 deletions
+18
View File
@@ -1,6 +1,7 @@
import { isPoint, pointDistance, pointFrom, pointFromVector } from "./point";
import { vector, vectorNormal, vectorNormalize, vectorScale } from "./vector";
import { LegendreGaussN24CValues, LegendreGaussN24TValues } from "./constants";
import { lineSegment, lineSegmentIntersectionPoints } from "./segment";
import type { Curve, GlobalPoint, LineSegment, LocalPoint } from "./types";
@@ -174,6 +175,23 @@ export function curveIntersectLineSegment<
return [solution];
}
// Fallback: approximate the curve with short segments to catch near-endpoint hits.
const startHit = lineSegmentIntersectionPoints(
lineSegment(bezierEquation(c, 0), bezierEquation(c, 1 / 20)),
l,
);
if (startHit) {
return [startHit];
}
const endHit = lineSegmentIntersectionPoints(
lineSegment(bezierEquation(c, 19 / 20), bezierEquation(c, 1)),
l,
);
if (endHit) {
return [endHit];
}
return [];
}