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:
@@ -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 [];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user