mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
fix: hand-drawn lines shift after flipping
This commit is contained in:
parent
0ba1a1a00b
commit
a87004918c
1 changed files with 30 additions and 0 deletions
|
@ -20,6 +20,7 @@ import {
|
||||||
getCommonBounds,
|
getCommonBounds,
|
||||||
getResizedElementAbsoluteCoords,
|
getResizedElementAbsoluteCoords,
|
||||||
getCommonBoundingBox,
|
getCommonBoundingBox,
|
||||||
|
getElementPointsCoords,
|
||||||
} from "./bounds";
|
} from "./bounds";
|
||||||
import {
|
import {
|
||||||
isArrowElement,
|
isArrowElement,
|
||||||
|
@ -720,6 +721,35 @@ export const resizeMultipleElements = (
|
||||||
update.baseline = textMeasurements?.baseline ?? element.baseline;
|
update.baseline = textMeasurements?.baseline ?? element.baseline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO remove this after solving the issue with changing bounds of linear
|
||||||
|
// elements with roughness > 0
|
||||||
|
if (isLinearElement(element) && (isFlippedByX || isFlippedByY)) {
|
||||||
|
const origBounds = getElementPointsCoords(element, element.points);
|
||||||
|
const newBounds = getElementPointsCoords(
|
||||||
|
{ ...element, x, y },
|
||||||
|
rescaledPoints.points!,
|
||||||
|
);
|
||||||
|
const origXY = [element.x, element.y];
|
||||||
|
const newXY = [x, y];
|
||||||
|
|
||||||
|
const calculateCorrenction = (axis: "x" | "y") => {
|
||||||
|
const i = axis === "x" ? 0 : 1;
|
||||||
|
const delta1 =
|
||||||
|
newBounds[i + 2] - newXY[i] - (origXY[i] - origBounds[i]) * scale;
|
||||||
|
const delta2 =
|
||||||
|
(origBounds[i + 2] - origXY[i]) * scale - (newXY[i] - newBounds[i]);
|
||||||
|
return (delta1 + delta2) / 2;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (isFlippedByX) {
|
||||||
|
update.x -= calculateCorrenction("x");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isFlippedByY) {
|
||||||
|
update.y -= calculateCorrenction("y");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
updateBoundElements(latestElement, { newSize: { width, height } });
|
updateBoundElements(latestElement, { newSize: { width, height } });
|
||||||
mutateElement(latestElement, update);
|
mutateElement(latestElement, update);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue