浏览代码

clean transforms

main
Steve Ruiz 4 年前
父节点
当前提交
3310f1a94c
共有 2 个文件被更改,包括 20 次插入26 次删除
  1. 7
    13
      lib/shape-utils/rectangle.tsx
  2. 13
    13
      state/sessions/transform-session.ts

+ 7
- 13
lib/shape-utils/rectangle.tsx 查看文件

@@ -1,14 +1,11 @@
1 1
 import { v4 as uuid } from "uuid"
2 2
 import * as vec from "utils/vec"
3
-import { RectangleShape, ShapeType, Corner, Edge } from "types"
3
+import { RectangleShape, ShapeType } from "types"
4 4
 import { registerShapeUtils } from "./index"
5 5
 import { boundsCollidePolygon, boundsContainPolygon } from "utils/bounds"
6 6
 import {
7 7
   getBoundsFromPoints,
8 8
   getRotatedCorners,
9
-  getRotatedSize,
10
-  lerp,
11
-  rotateBounds,
12 9
   translateBounds,
13 10
 } from "utils/utils"
14 11
 
@@ -98,16 +95,9 @@ const rectangle = registerShapeUtils<RectangleShape>({
98 95
 
99 96
   transform(shape, bounds, { initialShape, transformOrigin, scaleX, scaleY }) {
100 97
     if (shape.rotation === 0) {
101
-      shape.size = [bounds.width, bounds.height]
102 98
       shape.point = [bounds.minX, bounds.minY]
99
+      shape.size = [bounds.width, bounds.height]
103 100
     } else {
104
-      // Size
105
-      shape.size = vec.mul(
106
-        initialShape.size,
107
-        Math.min(Math.abs(scaleX), Math.abs(scaleY))
108
-      )
109
-
110
-      // Point
111 101
       shape.point = [
112 102
         bounds.minX +
113 103
           (bounds.width - shape.size[0]) *
@@ -117,7 +107,11 @@ const rectangle = registerShapeUtils<RectangleShape>({
117 107
             (scaleY < 0 ? 1 - transformOrigin[1] : transformOrigin[1]),
118 108
       ]
119 109
 
120
-      // Rotation
110
+      shape.size = vec.mul(
111
+        initialShape.size,
112
+        Math.min(Math.abs(scaleX), Math.abs(scaleY))
113
+      )
114
+
121 115
       shape.rotation =
122 116
         (scaleX < 0 && scaleY >= 0) || (scaleY < 0 && scaleX >= 0)
123 117
           ? -initialShape.rotation

+ 13
- 13
state/sessions/transform-session.ts 查看文件

@@ -66,19 +66,6 @@ export default class TransformSession extends BaseSession {
66 66
 
67 67
       const shape = shapes[id]
68 68
 
69
-      // const transformOrigins = {
70
-      //   [Edge.Top]: [0.5, 1],
71
-      //   [Edge.Right]: [0, 0.5],
72
-      //   [Edge.Bottom]: [0.5, 0],
73
-      //   [Edge.Left]: [1, 0.5],
74
-      //   [Corner.TopLeft]: [1, 1],
75
-      //   [Corner.TopRight]: [0, 1],
76
-      //   [Corner.BottomLeft]: [1, 0],
77
-      //   [Corner.BottomRight]: [0, 0],
78
-      // }
79
-
80
-      // const origin = transformOrigins[this.transformType]
81
-
82 69
       getShapeUtils(shape).transform(shape, newShapeBounds, {
83 70
         type: this.transformType,
84 71
         initialShape,
@@ -177,3 +164,16 @@ export function getTransformSnapshot(
177 164
 }
178 165
 
179 166
 export type TransformSnapshot = ReturnType<typeof getTransformSnapshot>
167
+
168
+// const transformOrigins = {
169
+//   [Edge.Top]: [0.5, 1],
170
+//   [Edge.Right]: [0, 0.5],
171
+//   [Edge.Bottom]: [0.5, 0],
172
+//   [Edge.Left]: [1, 0.5],
173
+//   [Corner.TopLeft]: [1, 1],
174
+//   [Corner.TopRight]: [0, 1],
175
+//   [Corner.BottomLeft]: [1, 0],
176
+//   [Corner.BottomRight]: [0, 0],
177
+// }
178
+
179
+// const origin = transformOrigins[this.transformType]

正在加载...
取消
保存