mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Get three solutions for curve-line intersections to avoid issue with high inclination intersectors
This commit is contained in:
parent
b33cc74183
commit
979fff566c
3 changed files with 9 additions and 17 deletions
|
@ -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 [];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue