diff --git a/lib/shape-utils/rectangle.tsx b/lib/shape-utils/rectangle.tsx index 6d26c016a..375057984 100644 --- a/lib/shape-utils/rectangle.tsx +++ b/lib/shape-utils/rectangle.tsx @@ -1,14 +1,11 @@ import { v4 as uuid } from "uuid" import * as vec from "utils/vec" -import { RectangleShape, ShapeType, Corner, Edge } from "types" +import { RectangleShape, ShapeType } from "types" import { registerShapeUtils } from "./index" import { boundsCollidePolygon, boundsContainPolygon } from "utils/bounds" import { getBoundsFromPoints, getRotatedCorners, - getRotatedSize, - lerp, - rotateBounds, translateBounds, } from "utils/utils" @@ -98,16 +95,9 @@ const rectangle = registerShapeUtils({ transform(shape, bounds, { initialShape, transformOrigin, scaleX, scaleY }) { if (shape.rotation === 0) { - shape.size = [bounds.width, bounds.height] shape.point = [bounds.minX, bounds.minY] + shape.size = [bounds.width, bounds.height] } else { - // Size - shape.size = vec.mul( - initialShape.size, - Math.min(Math.abs(scaleX), Math.abs(scaleY)) - ) - - // Point shape.point = [ bounds.minX + (bounds.width - shape.size[0]) * @@ -117,7 +107,11 @@ const rectangle = registerShapeUtils({ (scaleY < 0 ? 1 - transformOrigin[1] : transformOrigin[1]), ] - // Rotation + shape.size = vec.mul( + initialShape.size, + Math.min(Math.abs(scaleX), Math.abs(scaleY)) + ) + shape.rotation = (scaleX < 0 && scaleY >= 0) || (scaleY < 0 && scaleX >= 0) ? -initialShape.rotation diff --git a/state/sessions/transform-session.ts b/state/sessions/transform-session.ts index 39c997a35..086a33ea9 100644 --- a/state/sessions/transform-session.ts +++ b/state/sessions/transform-session.ts @@ -66,19 +66,6 @@ export default class TransformSession extends BaseSession { const shape = shapes[id] - // const transformOrigins = { - // [Edge.Top]: [0.5, 1], - // [Edge.Right]: [0, 0.5], - // [Edge.Bottom]: [0.5, 0], - // [Edge.Left]: [1, 0.5], - // [Corner.TopLeft]: [1, 1], - // [Corner.TopRight]: [0, 1], - // [Corner.BottomLeft]: [1, 0], - // [Corner.BottomRight]: [0, 0], - // } - - // const origin = transformOrigins[this.transformType] - getShapeUtils(shape).transform(shape, newShapeBounds, { type: this.transformType, initialShape, @@ -177,3 +164,16 @@ export function getTransformSnapshot( } export type TransformSnapshot = ReturnType + +// const transformOrigins = { +// [Edge.Top]: [0.5, 1], +// [Edge.Right]: [0, 0.5], +// [Edge.Bottom]: [0.5, 0], +// [Edge.Left]: [1, 0.5], +// [Corner.TopLeft]: [1, 1], +// [Corner.TopRight]: [0, 1], +// [Corner.BottomLeft]: [1, 0], +// [Corner.BottomRight]: [0, 0], +// } + +// const origin = transformOrigins[this.transformType]