fix: improve solveQuadratic when a = 0 (#5618)
This commit is contained in:
parent
33300d19f6
commit
720f468f39
@ -107,12 +107,19 @@ const solveQuadratic = (
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const t1 = (-b + Math.sqrt(sqrtPart)) / (2 * a);
|
|
||||||
const t2 = (-b - Math.sqrt(sqrtPart)) / (2 * a);
|
|
||||||
|
|
||||||
let s1 = null;
|
let s1 = null;
|
||||||
let s2 = null;
|
let s2 = null;
|
||||||
|
|
||||||
|
let t1 = Infinity;
|
||||||
|
let t2 = Infinity;
|
||||||
|
|
||||||
|
if (a === 0) {
|
||||||
|
t1 = t2 = -c / b;
|
||||||
|
} else {
|
||||||
|
t1 = (-b + Math.sqrt(sqrtPart)) / (2 * a);
|
||||||
|
t2 = (-b - Math.sqrt(sqrtPart)) / (2 * a);
|
||||||
|
}
|
||||||
|
|
||||||
if (t1 >= 0 && t1 <= 1) {
|
if (t1 >= 0 && t1 <= 1) {
|
||||||
s1 = getBezierValueForT(t1, p0, p1, p2, p3);
|
s1 = getBezierValueForT(t1, p0, p1, p2, p3);
|
||||||
}
|
}
|
||||||
@ -152,11 +159,6 @@ const getCubicBezierCurveBound = (
|
|||||||
return [minX, minY, maxX, maxY];
|
return [minX, minY, maxX, maxY];
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO: https://github.com/excalidraw/excalidraw/issues/5617
|
|
||||||
const getRandomOffset = () => {
|
|
||||||
return Math.random() / 1000000;
|
|
||||||
};
|
|
||||||
|
|
||||||
const getMinMaxXYFromCurvePathOps = (
|
const getMinMaxXYFromCurvePathOps = (
|
||||||
ops: Op[],
|
ops: Op[],
|
||||||
transformXY?: (x: number, y: number) => [number, number],
|
transformXY?: (x: number, y: number) => [number, number],
|
||||||
@ -173,19 +175,9 @@ const getMinMaxXYFromCurvePathOps = (
|
|||||||
// move operation does not draw anything; so, it always
|
// move operation does not draw anything; so, it always
|
||||||
// returns false
|
// returns false
|
||||||
} else if (op === "bcurveTo") {
|
} else if (op === "bcurveTo") {
|
||||||
// random offset is needed to fix https://github.com/excalidraw/excalidraw/issues/5585
|
const _p1 = [data[0], data[1]] as Point;
|
||||||
const _p1 = [
|
const _p2 = [data[2], data[3]] as Point;
|
||||||
data[0] + getRandomOffset(),
|
const _p3 = [data[4], data[5]] as Point;
|
||||||
data[1] + getRandomOffset(),
|
|
||||||
] as Point;
|
|
||||||
const _p2 = [
|
|
||||||
data[2] + getRandomOffset(),
|
|
||||||
data[3] + getRandomOffset(),
|
|
||||||
] as Point;
|
|
||||||
const _p3 = [
|
|
||||||
data[4] + getRandomOffset(),
|
|
||||||
data[5] + getRandomOffset(),
|
|
||||||
] as Point;
|
|
||||||
|
|
||||||
const p1 = transformXY ? transformXY(..._p1) : _p1;
|
const p1 = transformXY ? transformXY(..._p1) : _p1;
|
||||||
const p2 = transformXY ? transformXY(..._p2) : _p2;
|
const p2 = transformXY ? transformXY(..._p2) : _p2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user