Get three solutions for curve-line intersections to avoid issue with high inclination intersectors

This commit is contained in:
Mark Tolmacs 2025-03-24 15:24:06 +01:00
parent 4d1e2c2bbb
commit 4ee99de2fb
3 changed files with 9 additions and 17 deletions

View file

@ -157,22 +157,13 @@ export function curveIntersectLineSegment<
return bezierEquation(c, t); return bezierEquation(c, t);
}; };
let solution = calculate(initial_guesses[0]); const solutions = [
if (solution) { calculate(initial_guesses[0]),
return [solution]; calculate(initial_guesses[1]),
} calculate(initial_guesses[2]),
].filter((x, i, a): x is Point => x !== null && a.indexOf(x) === i);
solution = calculate(initial_guesses[1]); return solutions;
if (solution) {
return [solution];
}
solution = calculate(initial_guesses[2]);
if (solution) {
return [solution];
}
return [];
} }
/** /**

View file

@ -91,9 +91,10 @@ export function isPoint(p: unknown): p is LocalPoint | GlobalPoint {
export function pointsEqual<Point extends GlobalPoint | LocalPoint>( export function pointsEqual<Point extends GlobalPoint | LocalPoint>(
a: Point, a: Point,
b: Point, b: Point,
precision: number = PRECISION,
): boolean { ): boolean {
const abs = Math.abs; const abs = Math.abs;
return abs(a[0] - b[0]) < PRECISION && abs(a[1] - b[1]) < PRECISION; return abs(a[0] - b[0]) < precision && abs(a[1] - b[1]) < precision;
} }
/** /**

View file

@ -6,7 +6,7 @@ export const clamp = (value: number, min: number, max: number) => {
export const round = ( export const round = (
value: number, value: number,
precision: number, precision: number = (Math.log(1 / PRECISION) * Math.LOG10E + 1) | 0,
func: "round" | "floor" | "ceil" = "round", func: "round" | "floor" | "ceil" = "round",
) => { ) => {
const multiplier = Math.pow(10, precision); const multiplier = Math.pow(10, precision);