fix: a few corner cases for flipping

This commit is contained in:
Alex Kim 2023-02-16 18:31:49 +03:00
parent 69e30b372b
commit 9e1131cf42
No known key found for this signature in database
GPG key ID: CEE74CFA44D238D7

View file

@ -638,15 +638,15 @@ export const resizeMultipleElements = (
const scale = const scale =
Math.max( Math.max(
Math.abs(pointerX - anchorX) / (maxX - minX), Math.abs(pointerX - anchorX) / (maxX - minX) || 0,
Math.abs(pointerY - anchorY) / (maxY - minY), Math.abs(pointerY - anchorY) / (maxY - minY) || 0,
) * (shouldResizeFromCenter ? 2 : 1); ) * (shouldResizeFromCenter ? 2 : 1);
if (scale === 0) { if (scale === 0) {
return; return;
} }
const mapDirectionsToFlipConditions: Record< const mapDirectionsToPointerPositions: Record<
typeof direction, typeof direction,
[x: boolean, y: boolean] [x: boolean, y: boolean]
> = { > = {
@ -659,9 +659,9 @@ export const resizeMultipleElements = (
// to flip an element: // to flip an element:
// 1. mirror x,y relative to the anchor over the x/y/both axis (flipFactor) // 1. mirror x,y relative to the anchor over the x/y/both axis (flipFactor)
// 2. shift by the width/height/both (flipAdjust) or mirror points in case of // 2. shift by the width/height/both (flipAdjust) or mirror points in case of
// linear/free draw element (hasPoints) // linear/free draw element
// 3. adjust the angle // 3. adjust the angle
const [flipFactorX, flipFactorY] = mapDirectionsToFlipConditions[ const [flipFactorX, flipFactorY] = mapDirectionsToPointerPositions[
direction direction
].map((condition) => (condition ? 1 : -1)); ].map((condition) => (condition ? 1 : -1));
const isFlippedByX = flipFactorX < 0; const isFlippedByX = flipFactorX < 0;
@ -681,8 +681,6 @@ export const resizeMultipleElements = (
const x = anchorX + flipFactorX * (offsetX * scale + flipAdjustX); const x = anchorX + flipFactorX * (offsetX * scale + flipAdjustX);
const y = anchorY + flipFactorY * (offsetY * scale + flipAdjustY); const y = anchorY + flipFactorY * (offsetY * scale + flipAdjustY);
// TODO curved lines adjustment
// readjust points for linear & free draw elements
const rescaledPoints = rescalePointsInElement( const rescaledPoints = rescalePointsInElement(
element, element,
width * flipFactorX, width * flipFactorX,
@ -735,7 +733,7 @@ export const resizeMultipleElements = (
baseline: number; baseline: number;
} | null = null; } | null = null;
const boundTextElement = getBoundTextElement(element); const boundTextElement = getBoundTextElement(latestElement);
if (boundTextElement || isTextElement(element)) { if (boundTextElement || isTextElement(element)) {
const optionalPadding = getBoundTextElementOffset(boundTextElement) * 2; const optionalPadding = getBoundTextElementOffset(boundTextElement) * 2;
@ -755,11 +753,16 @@ export const resizeMultipleElements = (
} }
if (boundTextElement) { if (boundTextElement) {
boundTextUpdates = { if (isArrowElement(element)) {
angle, const { angle, fontSize, baseline } = boundTextElement;
fontSize: textMeasurements.size, boundTextUpdates = { angle, fontSize, baseline };
baseline: textMeasurements.baseline, } else {
}; boundTextUpdates = {
angle: update.angle,
fontSize: textMeasurements.size,
baseline: textMeasurements.baseline,
};
}
} }
} }