fix: add random tiny offsets to avoid linear elements from being clipped (#5615)

Co-authored-by: Ryan Di <ryandi@Ryans-MacBook-Pro.local>
This commit is contained in:
Ryan Di 2022-08-23 21:52:15 +08:00 committed by GitHub
parent 5aed159991
commit 33300d19f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -152,6 +152,11 @@ const getCubicBezierCurveBound = (
return [minX, minY, maxX, maxY];
};
// TODO: https://github.com/excalidraw/excalidraw/issues/5617
const getRandomOffset = () => {
return Math.random() / 1000000;
};
const getMinMaxXYFromCurvePathOps = (
ops: Op[],
transformXY?: (x: number, y: number) => [number, number],
@ -168,9 +173,19 @@ const getMinMaxXYFromCurvePathOps = (
// move operation does not draw anything; so, it always
// returns false
} else if (op === "bcurveTo") {
const _p1 = [data[0], data[1]] as Point;
const _p2 = [data[2], data[3]] as Point;
const _p3 = [data[4], data[5]] as Point;
// random offset is needed to fix https://github.com/excalidraw/excalidraw/issues/5585
const _p1 = [
data[0] + getRandomOffset(),
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 p2 = transformXY ? transformXY(..._p2) : _p2;