From 88b2f4707dbaa68085bb9e540ee86ef97f69ccd2 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Tue, 29 Nov 2022 16:41:02 +0530 Subject: [PATCH] refactor: remove unnecessary code (#5933) --- src/element/resizeElements.ts | 103 ---------------------------------- 1 file changed, 103 deletions(-) diff --git a/src/element/resizeElements.ts b/src/element/resizeElements.ts index 5f2d93a01..ff7956f38 100644 --- a/src/element/resizeElements.ts +++ b/src/element/resizeElements.ts @@ -12,7 +12,6 @@ import { ExcalidrawTextElement, NonDeletedExcalidrawElement, NonDeleted, - ExcalidrawElement, } from "./types"; import { getElementAbsoluteCoords, @@ -26,7 +25,6 @@ import { isTextElement, } from "./typeChecks"; import { mutateElement } from "./mutateElement"; -import { getPerfectElementSize } from "./sizeHelpers"; import { getFontString } from "../utils"; import { updateBoundElements } from "./binding"; import { @@ -76,21 +74,6 @@ export const transformElements = ( shouldRotateWithDiscreteAngle, ); updateBoundElements(element); - } else if ( - isLinearElement(element) && - element.points.length === 2 && - (transformHandleType === "nw" || - transformHandleType === "ne" || - transformHandleType === "sw" || - transformHandleType === "se") - ) { - reshapeSingleTwoPointElement( - element, - resizeArrowDirection, - shouldRotateWithDiscreteAngle, - pointerX, - pointerY, - ); } else if ( isTextElement(element) && (transformHandleType === "nw" || @@ -174,92 +157,6 @@ const rotateSingleElement = ( } }; -// used in DEV only -const validateTwoPointElementNormalized = ( - element: NonDeleted, -) => { - if ( - element.points.length !== 2 || - element.points[0][0] !== 0 || - element.points[0][1] !== 0 || - Math.abs(element.points[1][0]) !== element.width || - Math.abs(element.points[1][1]) !== element.height - ) { - throw new Error("Two-point element is not normalized"); - } -}; - -const getPerfectElementSizeWithRotation = ( - elementType: ExcalidrawElement["type"], - width: number, - height: number, - angle: number, -): [number, number] => { - const size = getPerfectElementSize( - elementType, - ...rotate(width, height, 0, 0, angle), - ); - return rotate(size.width, size.height, 0, 0, -angle); -}; - -export const reshapeSingleTwoPointElement = ( - element: NonDeleted, - resizeArrowDirection: "origin" | "end", - shouldRotateWithDiscreteAngle: boolean, - pointerX: number, - pointerY: number, -) => { - if (process.env.NODE_ENV !== "production") { - validateTwoPointElementNormalized(element); - } - const [x1, y1, x2, y2] = getElementAbsoluteCoords(element); - const cx = (x1 + x2) / 2; - const cy = (y1 + y2) / 2; - // rotation pointer with reverse angle - const [rotatedX, rotatedY] = rotate( - pointerX, - pointerY, - cx, - cy, - -element.angle, - ); - let [width, height] = - resizeArrowDirection === "end" - ? [rotatedX - element.x, rotatedY - element.y] - : [ - element.x + element.points[1][0] - rotatedX, - element.y + element.points[1][1] - rotatedY, - ]; - if (shouldRotateWithDiscreteAngle) { - [width, height] = getPerfectElementSizeWithRotation( - element.type, - width, - height, - element.angle, - ); - } - const [nextElementX, nextElementY] = adjustXYWithRotation( - resizeArrowDirection === "end" - ? { s: true, e: true } - : { n: true, w: true }, - element.x, - element.y, - element.angle, - 0, - 0, - (element.points[1][0] - width) / 2, - (element.points[1][1] - height) / 2, - ); - mutateElement(element, { - x: nextElementX, - y: nextElementY, - points: [ - [0, 0], - [width, height], - ], - }); -}; - const rescalePointsInElement = ( element: NonDeletedExcalidrawElement, width: number,