Browse Source

Removes translateTo, rotateTo

main
Steve Ruiz 4 years ago
parent
commit
9ab86ba9ae

+ 9
- 8
lib/code/index.ts View File

1
-import { Shape } from "types"
1
+import { Shape } from 'types'
2
 import shapeUtilityMap, {
2
 import shapeUtilityMap, {
3
   createShape,
3
   createShape,
4
   getShapeUtils,
4
   getShapeUtils,
5
   ShapeUtility,
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
 export const codeShapes = new Set<CodeShape<Shape>>([])
11
 export const codeShapes = new Set<CodeShape<Shape>>([])
12
 
12
 
29
   }
29
   }
30
 
30
 
31
   moveTo(point: Vector) {
31
   moveTo(point: Vector) {
32
-    this.utils.translateTo(this._shape, vectorToPoint(point))
32
+    this.utils.setProperty(this._shape, 'point', vectorToPoint(point))
33
     return this
33
     return this
34
   }
34
   }
35
 
35
 
36
   translate(delta: Vector) {
36
   translate(delta: Vector) {
37
-    this.utils.translateTo(
37
+    this.utils.setProperty(
38
       this._shape,
38
       this._shape,
39
+      'point',
39
       vec.add(this._shape.point, vectorToPoint(delta))
40
       vec.add(this._shape.point, vectorToPoint(delta))
40
     )
41
     )
41
     return this
42
     return this
42
   }
43
   }
43
 
44
 
44
   rotate(rotation: number) {
45
   rotate(rotation: number) {
45
-    this.utils.rotateTo(this._shape, rotation)
46
+    this.utils.setProperty(this._shape, 'rotation', rotation)
46
     return this
47
     return this
47
   }
48
   }
48
 
49
 

+ 0
- 13
lib/shape-utils/arrow.tsx View File

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
   transform(shape, bounds, { initialShape, scaleX, scaleY }) {
216
   transform(shape, bounds, { initialShape, scaleX, scaleY }) {
230
     const initialShapeBounds = this.getBounds(initialShape)
217
     const initialShapeBounds = this.getBounds(initialShape)
231
 
218
 

+ 0
- 10
lib/shape-utils/circle.tsx View File

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
   transform(shape, bounds, { initialShape, transformOrigin, scaleX, scaleY }) {
99
   transform(shape, bounds, { initialShape, transformOrigin, scaleX, scaleY }) {
110
     shape.radius =
100
     shape.radius =
111
       initialShape.radius * Math.min(Math.abs(scaleX), Math.abs(scaleY))
101
       initialShape.radius * Math.min(Math.abs(scaleX), Math.abs(scaleY))

+ 0
- 9
lib/shape-utils/dot.tsx View File

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
   transform(shape, bounds) {
82
   transform(shape, bounds) {
92
     shape.point = [bounds.minX, bounds.minY]
83
     shape.point = [bounds.minX, bounds.minY]
93
 
84
 

+ 0
- 14
lib/shape-utils/draw.tsx View File

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
   transform(shape, bounds, { initialShape, scaleX, scaleY }) {
140
   transform(shape, bounds, { initialShape, scaleX, scaleY }) {
155
     const initialShapeBounds = this.boundsCache.get(initialShape)
141
     const initialShapeBounds = this.boundsCache.get(initialShape)
156
     shape.points = initialShape.points.map(([x, y]) => {
142
     shape.points = initialShape.points.map(([x, y]) => {

+ 0
- 10
lib/shape-utils/ellipse.tsx View File

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
   transform(shape, bounds, { scaleX, scaleY, initialShape }) {
115
   transform(shape, bounds, { scaleX, scaleY, initialShape }) {
126
     // TODO: Locked aspect ratio transform
116
     // TODO: Locked aspect ratio transform
127
 
117
 

+ 1
- 7
lib/shape-utils/index.tsx View File

29
 when performing tests (such as hit tests) or mutations, such as translations.
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
   // A cache for the computed bounds of this kind of shape.
33
   // A cache for the computed bounds of this kind of shape.
34
   boundsCache: WeakMap<K, Bounds>
34
   boundsCache: WeakMap<K, Bounds>
35
 
35
 
51
     style: Partial<ShapeStyles>
51
     style: Partial<ShapeStyles>
52
   ): ShapeUtility<K>
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
   // Transform to fit a new bounding box when more than one shape is selected.
54
   // Transform to fit a new bounding box when more than one shape is selected.
61
   transform(
55
   transform(
62
     this: ShapeUtility<K>,
56
     this: ShapeUtility<K>,

+ 0
- 9
lib/shape-utils/line.tsx View File

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
   transform(shape, bounds) {
92
   transform(shape, bounds) {
102
     shape.point = [bounds.minX, bounds.minY]
93
     shape.point = [bounds.minX, bounds.minY]
103
 
94
 

+ 0
- 10
lib/shape-utils/polyline.tsx View File

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
   transform(shape, bounds, { initialShape, scaleX, scaleY }) {
93
   transform(shape, bounds, { initialShape, scaleX, scaleY }) {
104
     const initialShapeBounds = this.getBounds(initialShape)
94
     const initialShapeBounds = this.getBounds(initialShape)
105
 
95
 

+ 0
- 9
lib/shape-utils/ray.tsx View File

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
   transform(shape, bounds) {
90
   transform(shape, bounds) {
100
     shape.point = [bounds.minX, bounds.minY]
91
     shape.point = [bounds.minX, bounds.minY]
101
 
92
 

+ 0
- 10
lib/shape-utils/rectangle.tsx View File

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
   transform(shape, bounds, { initialShape, transformOrigin, scaleX, scaleY }) {
101
   transform(shape, bounds, { initialShape, transformOrigin, scaleX, scaleY }) {
112
     if (shape.rotation === 0 && !shape.isAspectRatioLocked) {
102
     if (shape.rotation === 0 && !shape.isAspectRatioLocked) {
113
       shape.size = [bounds.width, bounds.height]
103
       shape.size = [bounds.width, bounds.height]

+ 131
- 0
lib/shapes/BaseShape.tsx View File

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 View File

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

+ 18
- 12
state/commands/distribute.ts View File

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

+ 10
- 2
state/commands/nudge.ts View File

24
 
24
 
25
         for (let id in shapeBounds) {
25
         for (let id in shapeBounds) {
26
           const shape = shapes[id]
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
       undo(data) {
34
       undo(data) {
32
 
36
 
33
         for (let id in shapeBounds) {
37
         for (let id in shapeBounds) {
34
           const shape = shapes[id]
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 View File

47
 
47
 
48
       const rot = (PI2 + (shape.rotation - PI2 / 4)) % PI2
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
       return [id, shape]
54
       return [id, shape]
53
     })
55
     })
67
           const shape = shapes[id]
69
           const shape = shapes[id]
68
 
70
 
69
           getShapeUtils(shape)
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
         data.boundsRotation = nextboundsRotation
76
         data.boundsRotation = nextboundsRotation
81
 
83
 
82
           const shape = shapes[id]
84
           const shape = shapes[id]
83
           const utils = getShapeUtils(shape)
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
         data.boundsRotation = boundsRotation
91
         data.boundsRotation = boundsRotation

+ 6
- 2
state/commands/rotate.ts View File

21
         for (let { id, point, rotation } of after.initialShapes) {
21
         for (let { id, point, rotation } of after.initialShapes) {
22
           const shape = shapes[id]
22
           const shape = shapes[id]
23
           const utils = getShapeUtils(shape)
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
         data.boundsRotation = after.boundsRotation
29
         data.boundsRotation = after.boundsRotation
32
         for (let { id, point, rotation } of before.initialShapes) {
34
         for (let { id, point, rotation } of before.initialShapes) {
33
           const shape = shapes[id]
35
           const shape = shapes[id]
34
           const utils = getShapeUtils(shape)
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
         data.boundsRotation = before.boundsRotation
42
         data.boundsRotation = before.boundsRotation

+ 2
- 2
state/commands/translate.ts View File

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

+ 2
- 2
state/sessions/arrow-session.ts View File

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

+ 2
- 2
state/sessions/draw-session.ts View File

25
 
25
 
26
     const page = getPage(data)
26
     const page = getPage(data)
27
     const shape = page.shapes[id]
27
     const shape = page.shapes[id]
28
-    getShapeUtils(shape).translateTo(shape, point)
28
+    getShapeUtils(shape).setProperty(shape, 'point', point)
29
   }
29
   }
30
 
30
 
31
   update = (data: Data, point: number[], isLocked = false) => {
31
   update = (data: Data, point: number[], isLocked = false) => {
108
 
108
 
109
       getShapeUtils(shape)
109
       getShapeUtils(shape)
110
         .setProperty(shape, 'points', pts)
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
     commands.draw(data, this.snapshot.id, this.points)
114
     commands.draw(data, this.snapshot.id, this.points)

+ 5
- 3
state/sessions/rotate-session.ts View File

60
       )
60
       )
61
 
61
 
62
       getShapeUtils(shape)
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
 
70
 
71
     for (let { id, point, rotation } of this.snapshot.initialShapes) {
71
     for (let { id, point, rotation } of this.snapshot.initialShapes) {
72
       const shape = page.shapes[id]
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 View File

40
 
40
 
41
         for (const { id, point } of initialShapes) {
41
         for (const { id, point } of initialShapes) {
42
           const shape = shapes[id]
42
           const shape = shapes[id]
43
-          getShapeUtils(shape).translateTo(shape, point)
43
+          getShapeUtils(shape).setProperty(shape, 'point', point)
44
         }
44
         }
45
 
45
 
46
         for (const clone of clones) {
46
         for (const clone of clones) {
51
 
51
 
52
       for (const { id, point } of clones) {
52
       for (const { id, point } of clones) {
53
         const shape = shapes[id]
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
     } else {
56
     } else {
57
       if (this.isCloning) {
57
       if (this.isCloning) {
69
 
69
 
70
       for (const { id, point } of initialShapes) {
70
       for (const { id, point } of initialShapes) {
71
         const shape = shapes[id]
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
 
80
 
81
     for (const { id, point } of initialShapes) {
81
     for (const { id, point } of initialShapes) {
82
       const shape = shapes[id]
82
       const shape = shapes[id]
83
-      getShapeUtils(shape).translateTo(shape, point)
83
+      getShapeUtils(shape).setProperty(shape, 'point', point)
84
     }
84
     }
85
 
85
 
86
     for (const { id } of clones) {
86
     for (const { id } of clones) {

Loading…
Cancel
Save