소스 검색

Removes translateTo, rotateTo

main
Steve Ruiz 4 년 전
부모
커밋
9ab86ba9ae

+ 9
- 8
lib/code/index.ts 파일 보기

@@ -1,12 +1,12 @@
1
-import { Shape } from "types"
1
+import { Shape } from 'types'
2 2
 import shapeUtilityMap, {
3 3
   createShape,
4 4
   getShapeUtils,
5 5
   ShapeUtility,
6
-} from "lib/shape-utils"
7
-import * as vec from "utils/vec"
8
-import Vector from "./vector"
9
-import { vectorToPoint } from "utils/utils"
6
+} from 'lib/shape-utils'
7
+import * as vec from 'utils/vec'
8
+import Vector from './vector'
9
+import { vectorToPoint } from 'utils/utils'
10 10
 
11 11
 export const codeShapes = new Set<CodeShape<Shape>>([])
12 12
 
@@ -29,20 +29,21 @@ export default class CodeShape<T extends Shape> {
29 29
   }
30 30
 
31 31
   moveTo(point: Vector) {
32
-    this.utils.translateTo(this._shape, vectorToPoint(point))
32
+    this.utils.setProperty(this._shape, 'point', vectorToPoint(point))
33 33
     return this
34 34
   }
35 35
 
36 36
   translate(delta: Vector) {
37
-    this.utils.translateTo(
37
+    this.utils.setProperty(
38 38
       this._shape,
39
+      'point',
39 40
       vec.add(this._shape.point, vectorToPoint(delta))
40 41
     )
41 42
     return this
42 43
   }
43 44
 
44 45
   rotate(rotation: number) {
45
-    this.utils.rotateTo(this._shape, rotation)
46
+    this.utils.setProperty(this._shape, 'rotation', rotation)
46 47
     return this
47 48
   }
48 49
 

+ 0
- 13
lib/shape-utils/arrow.tsx 파일 보기

@@ -213,19 +213,6 @@ const arrow = registerShapeUtils<ArrowShape>({
213 213
     }
214 214
   },
215 215
 
216
-  rotateTo(shape, rotation) {
217
-    // const rot = rotation - shape.rotation
218
-    // const center = this.getCenter(shape)
219
-    // shape.points = shape.points.map((pt) => vec.rotWith(pt, shape.point, rot))
220
-    shape.rotation = rotation
221
-    return this
222
-  },
223
-
224
-  translateTo(shape, point) {
225
-    shape.point = vec.toPrecision(point)
226
-    return this
227
-  },
228
-
229 216
   transform(shape, bounds, { initialShape, scaleX, scaleY }) {
230 217
     const initialShapeBounds = this.getBounds(initialShape)
231 218
 

+ 0
- 10
lib/shape-utils/circle.tsx 파일 보기

@@ -96,16 +96,6 @@ const circle = registerShapeUtils<CircleShape>({
96 96
     )
97 97
   },
98 98
 
99
-  rotateTo(shape, rotation) {
100
-    shape.rotation = rotation
101
-    return this
102
-  },
103
-
104
-  translateTo(shape, point) {
105
-    shape.point = vec.toPrecision(point)
106
-    return this
107
-  },
108
-
109 99
   transform(shape, bounds, { initialShape, transformOrigin, scaleX, scaleY }) {
110 100
     shape.radius =
111 101
       initialShape.radius * Math.min(Math.abs(scaleX), Math.abs(scaleY))

+ 0
- 9
lib/shape-utils/dot.tsx 파일 보기

@@ -79,15 +79,6 @@ const dot = registerShapeUtils<DotShape>({
79 79
     )
80 80
   },
81 81
 
82
-  rotateTo(shape) {
83
-    return this
84
-  },
85
-
86
-  translateTo(shape, point) {
87
-    shape.point = vec.toPrecision(point)
88
-    return this
89
-  },
90
-
91 82
   transform(shape, bounds) {
92 83
     shape.point = [bounds.minX, bounds.minY]
93 84
 

+ 0
- 14
lib/shape-utils/draw.tsx 파일 보기

@@ -137,20 +137,6 @@ const draw = registerShapeUtils<DrawShape>({
137 137
     )
138 138
   },
139 139
 
140
-  rotateTo(shape, rotation) {
141
-    shape.rotation = rotation
142
-    // console.log(shape.points.map(([x, y]) => [x, y]))
143
-    // const bounds = this.getBounds(shape)
144
-    // const center = [bounds.width / 2, bounds.height / 2]
145
-    // shape.points = shape.points.map((pt) => vec.rotWith(pt, center, rotation))
146
-    return this
147
-  },
148
-
149
-  translateTo(shape, point) {
150
-    shape.point = vec.toPrecision(point)
151
-    return this
152
-  },
153
-
154 140
   transform(shape, bounds, { initialShape, scaleX, scaleY }) {
155 141
     const initialShapeBounds = this.boundsCache.get(initialShape)
156 142
     shape.points = initialShape.points.map(([x, y]) => {

+ 0
- 10
lib/shape-utils/ellipse.tsx 파일 보기

@@ -112,16 +112,6 @@ const ellipse = registerShapeUtils<EllipseShape>({
112 112
     )
113 113
   },
114 114
 
115
-  rotateTo(shape, rotation) {
116
-    shape.rotation = rotation
117
-    return this
118
-  },
119
-
120
-  translateTo(shape, point) {
121
-    shape.point = vec.toPrecision(point)
122
-    return this
123
-  },
124
-
125 115
   transform(shape, bounds, { scaleX, scaleY, initialShape }) {
126 116
     // TODO: Locked aspect ratio transform
127 117
 

+ 1
- 7
lib/shape-utils/index.tsx 파일 보기

@@ -29,7 +29,7 @@ Operations throughout the app will call these utility methods
29 29
 when performing tests (such as hit tests) or mutations, such as translations.
30 30
 */
31 31
 
32
-export interface ShapeUtility<K extends Readonly<Shape>> {
32
+export interface ShapeUtility<K extends Shape> {
33 33
   // A cache for the computed bounds of this kind of shape.
34 34
   boundsCache: WeakMap<K, Bounds>
35 35
 
@@ -51,12 +51,6 @@ export interface ShapeUtility<K extends Readonly<Shape>> {
51 51
     style: Partial<ShapeStyles>
52 52
   ): ShapeUtility<K>
53 53
 
54
-  // Set the shape's point.
55
-  translateTo(this: ShapeUtility<K>, shape: K, delta: number[]): ShapeUtility<K>
56
-
57
-  // Set the shape's rotation.
58
-  rotateTo(this: ShapeUtility<K>, shape: K, rotation: number): ShapeUtility<K>
59
-
60 54
   // Transform to fit a new bounding box when more than one shape is selected.
61 55
   transform(
62 56
     this: ShapeUtility<K>,

+ 0
- 9
lib/shape-utils/line.tsx 파일 보기

@@ -89,15 +89,6 @@ const line = registerShapeUtils<LineShape>({
89 89
     )
90 90
   },
91 91
 
92
-  rotateTo(shape) {
93
-    return this
94
-  },
95
-
96
-  translateTo(shape, point) {
97
-    shape.point = vec.toPrecision(point)
98
-    return this
99
-  },
100
-
101 92
   transform(shape, bounds) {
102 93
     shape.point = [bounds.minX, bounds.minY]
103 94
 

+ 0
- 10
lib/shape-utils/polyline.tsx 파일 보기

@@ -90,16 +90,6 @@ const polyline = registerShapeUtils<PolylineShape>({
90 90
     )
91 91
   },
92 92
 
93
-  rotateTo(shape, rotation) {
94
-    shape.rotation = rotation
95
-    return this
96
-  },
97
-
98
-  translateTo(shape, point) {
99
-    shape.point = vec.toPrecision(point)
100
-    return this
101
-  },
102
-
103 93
   transform(shape, bounds, { initialShape, scaleX, scaleY }) {
104 94
     const initialShapeBounds = this.getBounds(initialShape)
105 95
 

+ 0
- 9
lib/shape-utils/ray.tsx 파일 보기

@@ -87,15 +87,6 @@ const ray = registerShapeUtils<RayShape>({
87 87
     )
88 88
   },
89 89
 
90
-  rotateTo(shape) {
91
-    return this
92
-  },
93
-
94
-  translateTo(shape, point) {
95
-    shape.point = vec.toPrecision(point)
96
-    return this
97
-  },
98
-
99 90
   transform(shape, bounds) {
100 91
     shape.point = [bounds.minX, bounds.minY]
101 92
 

+ 0
- 10
lib/shape-utils/rectangle.tsx 파일 보기

@@ -98,16 +98,6 @@ const rectangle = registerShapeUtils<RectangleShape>({
98 98
     )
99 99
   },
100 100
 
101
-  rotateTo(shape, rotation) {
102
-    shape.rotation = rotation
103
-    return this
104
-  },
105
-
106
-  translateTo(shape, point) {
107
-    shape.point = vec.toPrecision(point)
108
-    return this
109
-  },
110
-
111 101
   transform(shape, bounds, { initialShape, transformOrigin, scaleX, scaleY }) {
112 102
     if (shape.rotation === 0 && !shape.isAspectRatioLocked) {
113 103
       shape.size = [bounds.width, bounds.height]

+ 131
- 0
lib/shapes/BaseShape.tsx 파일 보기

@@ -0,0 +1,131 @@
1
+import { defaultStyle } from 'lib/shape-styles'
2
+import {
3
+  Shape,
4
+  Bounds,
5
+  BaseShape,
6
+  ShapeSpecificProps,
7
+  ShapeType,
8
+  ShapeStyles,
9
+  MutableShape,
10
+  Edge,
11
+  Corner,
12
+  ShapeBinding,
13
+} from 'types'
14
+import { v4 as uuid } from 'uuid'
15
+import * as vec from 'utils/vec'
16
+import {
17
+  getBoundsCenter,
18
+  getRotatedCorners,
19
+  getBoundsFromPoints,
20
+} from 'utils/utils'
21
+
22
+class ShapeUtility<K extends MutableShape> {
23
+  boundsCache = new WeakMap<K, Bounds>([])
24
+  canTransform = true
25
+  canChangeAspectRatio = true
26
+  canStyleFill = true
27
+
28
+  // Create a new shape.
29
+  create(props: Partial<K> & ShapeSpecificProps<K>): K {
30
+    return {
31
+      id: uuid(),
32
+      isGenerated: false,
33
+      point: [0, 0],
34
+      name: 'Shape',
35
+      parentId: 'page0',
36
+      childIndex: 0,
37
+      rotation: 0,
38
+      isAspectRatioLocked: false,
39
+      isLocked: false,
40
+      isHidden: false,
41
+      ...props,
42
+    } as K
43
+  }
44
+
45
+  applyStyles = (shape: K, style: Partial<ShapeStyles>) => {
46
+    Object.assign(shape.style, style)
47
+    return this
48
+  }
49
+
50
+  transform = (
51
+    shape: K,
52
+    bounds: Bounds,
53
+    info: {
54
+      type: Edge | Corner
55
+      initialShape: K
56
+      scaleX: number
57
+      scaleY: number
58
+      transformOrigin: number[]
59
+    }
60
+  ) => {
61
+    shape.point = [bounds.minX, bounds.minY]
62
+
63
+    return this
64
+  }
65
+
66
+  transformSingle = (
67
+    shape: K,
68
+    bounds: Bounds,
69
+    info: {
70
+      type: Edge | Corner
71
+      initialShape: K
72
+      scaleX: number
73
+      scaleY: number
74
+      transformOrigin: number[]
75
+    }
76
+  ) => {
77
+    return this.transform(shape, bounds, info)
78
+  }
79
+
80
+  setProperty = <P extends keyof K>(shape: K, prop: P, value: K[P]) => {
81
+    shape[prop] = value
82
+    return this
83
+  }
84
+
85
+  onBindingMove? = (shape: K, bindings: Record<string, ShapeBinding>) => {
86
+    return this
87
+  }
88
+
89
+  onHandleMove? = (shape: K, handle: Partial<K['handles']>) => {
90
+    return this
91
+  }
92
+
93
+  render = (shape: K): JSX.Element => {
94
+    return <circle id={shape.id} />
95
+  }
96
+
97
+  // Get the bounds of the a shape.
98
+  getBounds = (shape: K): Bounds => {
99
+    const [x, y] = shape.point
100
+    return {
101
+      minX: x,
102
+      minY: y,
103
+      maxX: x + 1,
104
+      maxY: y + 1,
105
+      width: 1,
106
+      height: 1,
107
+    }
108
+  }
109
+
110
+  // Get the routated bounds of the a shape.
111
+  getRotatedBounds = (shape: K): Bounds => {
112
+    return getBoundsFromPoints(
113
+      getRotatedCorners(this.getBounds(shape), shape.rotation)
114
+    )
115
+  }
116
+
117
+  // Get the center of the shape
118
+  getCenter = (shape: K): number[] => {
119
+    return getBoundsCenter(this.getBounds(shape))
120
+  }
121
+
122
+  // Test whether a point lies within a shape.
123
+  hitTest = (shape: K, test: number[]): boolean => {
124
+    return true
125
+  }
126
+
127
+  // Test whether bounds collide with or contain a shape.
128
+  hitTestBounds = (shape: K, bounds: Bounds): boolean => {
129
+    return true
130
+  }
131
+}

+ 14
- 14
state/commands/align.ts 파일 보기

@@ -1,8 +1,8 @@
1
-import Command from "./command"
2
-import history from "../history"
3
-import { AlignType, Data } from "types"
4
-import { getCommonBounds, getPage, getSelectedShapes } from "utils/utils"
5
-import { getShapeUtils } from "lib/shape-utils"
1
+import Command from './command'
2
+import history from '../history'
3
+import { AlignType, Data } from 'types'
4
+import { getCommonBounds, getPage, getSelectedShapes } from 'utils/utils'
5
+import { getShapeUtils } from 'lib/shape-utils'
6 6
 
7 7
 export default function alignCommand(data: Data, type: AlignType) {
8 8
   const { currentPageId } = data
@@ -18,8 +18,8 @@ export default function alignCommand(data: Data, type: AlignType) {
18 18
   history.execute(
19 19
     data,
20 20
     new Command({
21
-      name: "aligned",
22
-      category: "canvas",
21
+      name: 'aligned',
22
+      category: 'canvas',
23 23
       do(data) {
24 24
         const { shapes } = getPage(data, currentPageId)
25 25
 
@@ -27,7 +27,7 @@ export default function alignCommand(data: Data, type: AlignType) {
27 27
           case AlignType.Top: {
28 28
             for (let id in boundsForShapes) {
29 29
               const shape = shapes[id]
30
-              getShapeUtils(shape).translateTo(shape, [
30
+              getShapeUtils(shape).setProperty(shape, 'point', [
31 31
                 shape.point[0],
32 32
                 commonBounds.minY,
33 33
               ])
@@ -37,7 +37,7 @@ export default function alignCommand(data: Data, type: AlignType) {
37 37
           case AlignType.CenterVertical: {
38 38
             for (let id in boundsForShapes) {
39 39
               const shape = shapes[id]
40
-              getShapeUtils(shape).translateTo(shape, [
40
+              getShapeUtils(shape).setProperty(shape, 'point', [
41 41
                 shape.point[0],
42 42
                 midY - boundsForShapes[id].height / 2,
43 43
               ])
@@ -47,7 +47,7 @@ export default function alignCommand(data: Data, type: AlignType) {
47 47
           case AlignType.Bottom: {
48 48
             for (let id in boundsForShapes) {
49 49
               const shape = shapes[id]
50
-              getShapeUtils(shape).translateTo(shape, [
50
+              getShapeUtils(shape).setProperty(shape, 'point', [
51 51
                 shape.point[0],
52 52
                 commonBounds.maxY - boundsForShapes[id].height,
53 53
               ])
@@ -57,7 +57,7 @@ export default function alignCommand(data: Data, type: AlignType) {
57 57
           case AlignType.Left: {
58 58
             for (let id in boundsForShapes) {
59 59
               const shape = shapes[id]
60
-              getShapeUtils(shape).translateTo(shape, [
60
+              getShapeUtils(shape).setProperty(shape, 'point', [
61 61
                 commonBounds.minX,
62 62
                 shape.point[1],
63 63
               ])
@@ -67,7 +67,7 @@ export default function alignCommand(data: Data, type: AlignType) {
67 67
           case AlignType.CenterHorizontal: {
68 68
             for (let id in boundsForShapes) {
69 69
               const shape = shapes[id]
70
-              getShapeUtils(shape).translateTo(shape, [
70
+              getShapeUtils(shape).setProperty(shape, 'point', [
71 71
                 midX - boundsForShapes[id].width / 2,
72 72
                 shape.point[1],
73 73
               ])
@@ -77,7 +77,7 @@ export default function alignCommand(data: Data, type: AlignType) {
77 77
           case AlignType.Right: {
78 78
             for (let id in boundsForShapes) {
79 79
               const shape = shapes[id]
80
-              getShapeUtils(shape).translateTo(shape, [
80
+              getShapeUtils(shape).setProperty(shape, 'point', [
81 81
                 commonBounds.maxX - boundsForShapes[id].width,
82 82
                 shape.point[1],
83 83
               ])
@@ -91,7 +91,7 @@ export default function alignCommand(data: Data, type: AlignType) {
91 91
         for (let id in boundsForShapes) {
92 92
           const shape = shapes[id]
93 93
           const initialBounds = boundsForShapes[id]
94
-          getShapeUtils(shape).translateTo(shape, [
94
+          getShapeUtils(shape).setProperty(shape, 'point', [
95 95
             initialBounds.minX,
96 96
             initialBounds.minY,
97 97
           ])

+ 18
- 12
state/commands/distribute.ts 파일 보기

@@ -1,13 +1,13 @@
1
-import Command from "./command"
2
-import history from "../history"
3
-import { Data, DistributeType } from "types"
1
+import Command from './command'
2
+import history from '../history'
3
+import { Data, DistributeType } from 'types'
4 4
 import {
5 5
   getBoundsCenter,
6 6
   getCommonBounds,
7 7
   getPage,
8 8
   getSelectedShapes,
9
-} from "utils/utils"
10
-import { getShapeUtils } from "lib/shape-utils"
9
+} from 'utils/utils'
10
+import { getShapeUtils } from 'lib/shape-utils'
11 11
 
12 12
 export default function distributeCommand(data: Data, type: DistributeType) {
13 13
   const { currentPageId } = data
@@ -32,8 +32,8 @@ export default function distributeCommand(data: Data, type: DistributeType) {
32 32
   history.execute(
33 33
     data,
34 34
     new Command({
35
-      name: "distributed",
36
-      category: "canvas",
35
+      name: 'distributed',
36
+      category: 'canvas',
37 37
       do(data) {
38 38
         const { shapes } = getPage(data, currentPageId)
39 39
         const len = entries.length
@@ -59,7 +59,7 @@ export default function distributeCommand(data: Data, type: DistributeType) {
59 59
               for (let i = 0; i < entriesToMove.length; i++) {
60 60
                 const [id, bounds] = entriesToMove[i]
61 61
                 const shape = shapes[id]
62
-                getShapeUtils(shape).translateTo(shape, [
62
+                getShapeUtils(shape).setProperty(shape, 'point', [
63 63
                   x + step * i - bounds.width / 2,
64 64
                   bounds.minY,
65 65
                 ])
@@ -75,7 +75,10 @@ export default function distributeCommand(data: Data, type: DistributeType) {
75 75
               for (let i = 0; i < entriesToMove.length - 1; i++) {
76 76
                 const [id, bounds] = entriesToMove[i]
77 77
                 const shape = shapes[id]
78
-                getShapeUtils(shape).translateTo(shape, [x, bounds.minY])
78
+                getShapeUtils(shape).setProperty(shape, 'point', [
79
+                  x,
80
+                  bounds.minY,
81
+                ])
79 82
                 x += bounds.width + step
80 83
               }
81 84
             }
@@ -101,7 +104,7 @@ export default function distributeCommand(data: Data, type: DistributeType) {
101 104
               for (let i = 0; i < entriesToMove.length; i++) {
102 105
                 const [id, bounds] = entriesToMove[i]
103 106
                 const shape = shapes[id]
104
-                getShapeUtils(shape).translateTo(shape, [
107
+                getShapeUtils(shape).setProperty(shape, 'point', [
105 108
                   bounds.minX,
106 109
                   y + step * i - bounds.height / 2,
107 110
                 ])
@@ -117,7 +120,10 @@ export default function distributeCommand(data: Data, type: DistributeType) {
117 120
               for (let i = 0; i < entriesToMove.length - 1; i++) {
118 121
                 const [id, bounds] = entriesToMove[i]
119 122
                 const shape = shapes[id]
120
-                getShapeUtils(shape).translateTo(shape, [bounds.minX, y])
123
+                getShapeUtils(shape).setProperty(shape, 'point', [
124
+                  bounds.minX,
125
+                  y,
126
+                ])
121 127
                 y += bounds.height + step
122 128
               }
123 129
             }
@@ -131,7 +137,7 @@ export default function distributeCommand(data: Data, type: DistributeType) {
131 137
         for (let id in boundsForShapes) {
132 138
           const shape = shapes[id]
133 139
           const initialBounds = boundsForShapes[id]
134
-          getShapeUtils(shape).translateTo(shape, [
140
+          getShapeUtils(shape).setProperty(shape, 'point', [
135 141
             initialBounds.minX,
136 142
             initialBounds.minY,
137 143
           ])

+ 10
- 2
state/commands/nudge.ts 파일 보기

@@ -24,7 +24,11 @@ export default function nudgeCommand(data: Data, delta: number[]) {
24 24
 
25 25
         for (let id in shapeBounds) {
26 26
           const shape = shapes[id]
27
-          getShapeUtils(shape).translateTo(shape, vec.add(shape.point, delta))
27
+          getShapeUtils(shape).setProperty(
28
+            shape,
29
+            'point',
30
+            vec.add(shape.point, delta)
31
+          )
28 32
         }
29 33
       },
30 34
       undo(data) {
@@ -32,7 +36,11 @@ export default function nudgeCommand(data: Data, delta: number[]) {
32 36
 
33 37
         for (let id in shapeBounds) {
34 38
           const shape = shapes[id]
35
-          getShapeUtils(shape).translateTo(shape, vec.sub(shape.point, delta))
39
+          getShapeUtils(shape).setProperty(
40
+            shape,
41
+            'point',
42
+            vec.sub(shape.point, delta)
43
+          )
36 44
         }
37 45
       },
38 46
     })

+ 8
- 4
state/commands/rotate-ccw.ts 파일 보기

@@ -47,7 +47,9 @@ export default function rotateCcwCommand(data: Data) {
47 47
 
48 48
       const rot = (PI2 + (shape.rotation - PI2 / 4)) % PI2
49 49
 
50
-      getShapeUtils(shape).rotateTo(shape, rot).translateTo(shape, nextPoint)
50
+      getShapeUtils(shape)
51
+        .setProperty(shape, 'rotation', rot)
52
+        .setProperty(shape, 'point', nextPoint)
51 53
 
52 54
       return [id, shape]
53 55
     })
@@ -67,8 +69,8 @@ export default function rotateCcwCommand(data: Data) {
67 69
           const shape = shapes[id]
68 70
 
69 71
           getShapeUtils(shape)
70
-            .rotateTo(shape, nextShapes[id].rotation)
71
-            .translateTo(shape, nextShapes[id].point)
72
+            .setProperty(shape, 'rotation', nextShapes[id].rotation)
73
+            .setProperty(shape, 'point', nextShapes[id].point)
72 74
         }
73 75
 
74 76
         data.boundsRotation = nextboundsRotation
@@ -81,7 +83,9 @@ export default function rotateCcwCommand(data: Data) {
81 83
 
82 84
           const shape = shapes[id]
83 85
           const utils = getShapeUtils(shape)
84
-          utils.rotateTo(shape, rotation).translateTo(shape, point)
86
+          utils
87
+            .setProperty(shape, 'rotation', rotation)
88
+            .setProperty(shape, 'point', point)
85 89
         }
86 90
 
87 91
         data.boundsRotation = boundsRotation

+ 6
- 2
state/commands/rotate.ts 파일 보기

@@ -21,7 +21,9 @@ export default function rotateCommand(
21 21
         for (let { id, point, rotation } of after.initialShapes) {
22 22
           const shape = shapes[id]
23 23
           const utils = getShapeUtils(shape)
24
-          utils.rotateTo(shape, rotation).translateTo(shape, point)
24
+          utils
25
+            .setProperty(shape, 'rotation', rotation)
26
+            .setProperty(shape, 'point', point)
25 27
         }
26 28
 
27 29
         data.boundsRotation = after.boundsRotation
@@ -32,7 +34,9 @@ export default function rotateCommand(
32 34
         for (let { id, point, rotation } of before.initialShapes) {
33 35
           const shape = shapes[id]
34 36
           const utils = getShapeUtils(shape)
35
-          utils.rotateTo(shape, rotation).translateTo(shape, point)
37
+          utils
38
+            .setProperty(shape, 'rotation', rotation)
39
+            .setProperty(shape, 'point', point)
36 40
         }
37 41
 
38 42
         data.boundsRotation = before.boundsRotation

+ 2
- 2
state/commands/translate.ts 파일 보기

@@ -34,7 +34,7 @@ export default function translateCommand(
34 34
 
35 35
         for (const { id, point } of initialShapes) {
36 36
           const shape = shapes[id]
37
-          getShapeUtils(shape).translateTo(shape, point)
37
+          getShapeUtils(shape).setProperty(shape, 'point', point)
38 38
           data.selectedIds.add(id)
39 39
         }
40 40
       },
@@ -52,7 +52,7 @@ export default function translateCommand(
52 52
 
53 53
         for (const { id, point } of initialShapes) {
54 54
           const shape = shapes[id]
55
-          getShapeUtils(shape).translateTo(shape, point)
55
+          getShapeUtils(shape).setProperty(shape, 'point', point)
56 56
           data.selectedIds.add(id)
57 57
         }
58 58
       },

+ 2
- 2
state/sessions/arrow-session.ts 파일 보기

@@ -66,7 +66,7 @@ export default class PointsSession extends BaseSession {
66 66
 
67 67
     getShapeUtils(shape)
68 68
       .onHandleMove(shape, { end: initialShape.handles.end })
69
-      .translateTo(shape, initialShape.point)
69
+      .setProperty(shape, 'point', initialShape.point)
70 70
   }
71 71
 
72 72
   complete(data: Data) {
@@ -95,7 +95,7 @@ export default class PointsSession extends BaseSession {
95 95
         nextHandles.end.point,
96 96
       ])
97 97
       .setProperty(shape, 'handles', nextHandles)
98
-      .translateTo(shape, newPoint)
98
+      .setProperty(shape, 'point', newPoint)
99 99
       .onHandleMove(shape, nextHandles)
100 100
 
101 101
     commands.arrow(

+ 2
- 2
state/sessions/draw-session.ts 파일 보기

@@ -25,7 +25,7 @@ export default class BrushSession extends BaseSession {
25 25
 
26 26
     const page = getPage(data)
27 27
     const shape = page.shapes[id]
28
-    getShapeUtils(shape).translateTo(shape, point)
28
+    getShapeUtils(shape).setProperty(shape, 'point', point)
29 29
   }
30 30
 
31 31
   update = (data: Data, point: number[], isLocked = false) => {
@@ -108,7 +108,7 @@ export default class BrushSession extends BaseSession {
108 108
 
109 109
       getShapeUtils(shape)
110 110
         .setProperty(shape, 'points', pts)
111
-        .translateTo(shape, vec.add(shape.point, [minX, minY]))
111
+        .setProperty(shape, 'point', vec.add(shape.point, [minX, minY]))
112 112
     }
113 113
 
114 114
     commands.draw(data, this.snapshot.id, this.points)

+ 5
- 3
state/sessions/rotate-session.ts 파일 보기

@@ -60,8 +60,8 @@ export default class RotateSession extends BaseSession {
60 60
       )
61 61
 
62 62
       getShapeUtils(shape)
63
-        .rotateTo(shape, (PI2 + nextRotation) % PI2)
64
-        .translateTo(shape, nextPoint)
63
+        .setProperty(shape, 'rotation', (PI2 + nextRotation) % PI2)
64
+        .setProperty(shape, 'point', nextPoint)
65 65
     }
66 66
   }
67 67
 
@@ -70,7 +70,9 @@ export default class RotateSession extends BaseSession {
70 70
 
71 71
     for (let { id, point, rotation } of this.snapshot.initialShapes) {
72 72
       const shape = page.shapes[id]
73
-      getShapeUtils(shape).rotateTo(shape, rotation).translateTo(shape, point)
73
+      getShapeUtils(shape)
74
+        .setProperty(shape, 'rotation', rotation)
75
+        .setProperty(shape, 'point', point)
74 76
     }
75 77
   }
76 78
 

+ 4
- 4
state/sessions/translate-session.ts 파일 보기

@@ -40,7 +40,7 @@ export default class TranslateSession extends BaseSession {
40 40
 
41 41
         for (const { id, point } of initialShapes) {
42 42
           const shape = shapes[id]
43
-          getShapeUtils(shape).translateTo(shape, point)
43
+          getShapeUtils(shape).setProperty(shape, 'point', point)
44 44
         }
45 45
 
46 46
         for (const clone of clones) {
@@ -51,7 +51,7 @@ export default class TranslateSession extends BaseSession {
51 51
 
52 52
       for (const { id, point } of clones) {
53 53
         const shape = shapes[id]
54
-        getShapeUtils(shape).translateTo(shape, vec.add(point, delta))
54
+        getShapeUtils(shape).setProperty(shape, 'point', vec.add(point, delta))
55 55
       }
56 56
     } else {
57 57
       if (this.isCloning) {
@@ -69,7 +69,7 @@ export default class TranslateSession extends BaseSession {
69 69
 
70 70
       for (const { id, point } of initialShapes) {
71 71
         const shape = shapes[id]
72
-        getShapeUtils(shape).translateTo(shape, vec.add(point, delta))
72
+        getShapeUtils(shape).setProperty(shape, 'point', vec.add(point, delta))
73 73
       }
74 74
     }
75 75
   }
@@ -80,7 +80,7 @@ export default class TranslateSession extends BaseSession {
80 80
 
81 81
     for (const { id, point } of initialShapes) {
82 82
       const shape = shapes[id]
83
-      getShapeUtils(shape).translateTo(shape, point)
83
+      getShapeUtils(shape).setProperty(shape, 'point', point)
84 84
     }
85 85
 
86 86
     for (const { id } of clones) {

Loading…
취소
저장