Browse Source

cleans up shape utils

main
Steve Ruiz 4 years ago
parent
commit
bef35b9207

+ 6
- 27
lib/shape-utils/arrow.tsx View File

@@ -153,12 +153,6 @@ const arrow = registerShapeUtils<ArrowShape>({
153 153
     )
154 154
   },
155 155
 
156
-  applyStyles(shape, style) {
157
-    Object.assign(shape.style, style)
158
-    shape.style.isFilled = false
159
-    return this
160
-  },
161
-
162 156
   getBounds(shape) {
163 157
     if (!this.boundsCache.has(shape)) {
164 158
       this.boundsCache.set(shape, getBoundsFromPoints(shape.points))
@@ -167,15 +161,6 @@ const arrow = registerShapeUtils<ArrowShape>({
167 161
     return translateBounds(this.boundsCache.get(shape), shape.point)
168 162
   },
169 163
 
170
-  getRotatedBounds(shape) {
171
-    return this.getBounds(shape)
172
-  },
173
-
174
-  getCenter(shape) {
175
-    const bounds = this.getBounds(shape)
176
-    return [bounds.minX + bounds.width / 2, bounds.minY + bounds.height / 2]
177
-  },
178
-
179 164
   hitTest(shape, point) {
180 165
     const { start, end, bend } = shape.handles
181 166
     if (shape.bend === 0) {
@@ -247,16 +232,6 @@ const arrow = registerShapeUtils<ArrowShape>({
247 232
     return this
248 233
   },
249 234
 
250
-  transformSingle(shape, bounds, info) {
251
-    this.transform(shape, bounds, info)
252
-    return this
253
-  },
254
-
255
-  setProperty(shape, prop, value) {
256
-    shape[prop] = value
257
-    return this
258
-  },
259
-
260 235
   onHandleMove(shape, handles) {
261 236
     for (let id in handles) {
262 237
       const handle = handles[id]
@@ -293,8 +268,12 @@ const arrow = registerShapeUtils<ArrowShape>({
293 268
     return this
294 269
   },
295 270
 
296
-  canTransform: true,
297
-  canChangeAspectRatio: true,
271
+  applyStyles(shape, style) {
272
+    Object.assign(shape.style, style)
273
+    shape.style.isFilled = false
274
+    return this
275
+  },
276
+
298 277
   canStyleFill: false,
299 278
 })
300 279
 

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

@@ -43,11 +43,6 @@ const circle = registerShapeUtils<CircleShape>({
43 43
     )
44 44
   },
45 45
 
46
-  applyStyles(shape, style) {
47
-    Object.assign(shape.style, style)
48
-    return this
49
-  },
50
-
51 46
   getBounds(shape) {
52 47
     if (!this.boundsCache.has(shape)) {
53 48
       const { radius } = shape
@@ -118,14 +113,7 @@ const circle = registerShapeUtils<CircleShape>({
118 113
     return this
119 114
   },
120 115
 
121
-  setProperty(shape, prop, value) {
122
-    shape[prop] = value
123
-    return this
124
-  },
125
-
126
-  canTransform: true,
127 116
   canChangeAspectRatio: false,
128
-  canStyleFill: true,
129 117
 })
130 118
 
131 119
 export default circle

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

@@ -37,11 +37,6 @@ const dot = registerShapeUtils<DotShape>({
37 37
     return <DotCircle id={id} cx={0} cy={0} r={3} />
38 38
   },
39 39
 
40
-  applyStyles(shape, style) {
41
-    Object.assign(shape.style, style)
42
-    return this
43
-  },
44
-
45 40
   getBounds(shape) {
46 41
     if (!this.boundsCache.has(shape)) {
47 42
       const bounds = {
@@ -85,19 +80,8 @@ const dot = registerShapeUtils<DotShape>({
85 80
     return this
86 81
   },
87 82
 
88
-  transformSingle(shape, bounds, info) {
89
-    this.transform(shape, bounds, info)
90
-    return this
91
-  },
92
-
93
-  setProperty(shape, prop, value) {
94
-    shape[prop] = value
95
-    return this
96
-  },
97
-
98 83
   canTransform: false,
99 84
   canChangeAspectRatio: false,
100
-  canStyleFill: true,
101 85
 })
102 86
 
103 87
 export default dot

+ 4
- 16
lib/shape-utils/draw.tsx View File

@@ -70,13 +70,6 @@ const draw = registerShapeUtils<DrawShape>({
70 70
     return <path id={id} d={pathCache.get(points)} fill={styles.stroke} />
71 71
   },
72 72
 
73
-  applyStyles(shape, style) {
74
-    Object.assign(shape.style, style)
75
-    shape.style.isFilled = false
76
-    shape.style.dash = DashStyle.Solid
77
-    return this
78
-  },
79
-
80 73
   getBounds(shape) {
81 74
     if (!this.boundsCache.has(shape)) {
82 75
       const bounds = getBoundsFromPoints(shape.points)
@@ -161,18 +154,13 @@ const draw = registerShapeUtils<DrawShape>({
161 154
     return this
162 155
   },
163 156
 
164
-  transformSingle(shape, bounds, info) {
165
-    this.transform(shape, bounds, info)
166
-    return this
167
-  },
168
-
169
-  setProperty(shape, prop, value) {
170
-    shape[prop] = value
157
+  applyStyles(shape, style) {
158
+    Object.assign(shape.style, style)
159
+    shape.style.isFilled = false
160
+    shape.style.dash = DashStyle.Solid
171 161
     return this
172 162
   },
173 163
 
174
-  canTransform: true,
175
-  canChangeAspectRatio: true,
176 164
   canStyleFill: false,
177 165
 })
178 166
 

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

@@ -49,11 +49,6 @@ const ellipse = registerShapeUtils<EllipseShape>({
49 49
     )
50 50
   },
51 51
 
52
-  applyStyles(shape, style) {
53
-    Object.assign(shape.style, style)
54
-    return this
55
-  },
56
-
57 52
   getBounds(shape) {
58 53
     if (!this.boundsCache.has(shape)) {
59 54
       const { radiusX, radiusY } = shape
@@ -130,15 +125,6 @@ const ellipse = registerShapeUtils<EllipseShape>({
130 125
   transformSingle(shape, bounds, info) {
131 126
     return this.transform(shape, bounds, info)
132 127
   },
133
-
134
-  setProperty(shape, prop, value) {
135
-    shape[prop] = value
136
-    return this
137
-  },
138
-
139
-  canTransform: true,
140
-  canChangeAspectRatio: true,
141
-  canStyleFill: true,
142 128
 })
143 129
 
144 130
 export default ellipse

+ 120
- 10
lib/shape-utils/index.tsx View File

@@ -7,7 +7,11 @@ import {
7 7
   ShapeStyles,
8 8
   ShapeHandle,
9 9
   ShapeBinding,
10
+  BaseShape,
11
+  ShapeSpecificProps,
12
+  Mutable,
10 13
 } from 'types'
14
+import { v4 as uuid } from 'uuid'
11 15
 import circle from './circle'
12 16
 import dot from './dot'
13 17
 import polyline from './polyline'
@@ -17,6 +21,18 @@ import line from './line'
17 21
 import ray from './ray'
18 22
 import draw from './draw'
19 23
 import arrow from './arrow'
24
+import rectangleUtils from '../shapes/Rectangle'
25
+import {
26
+  getBoundsCenter,
27
+  getBoundsFromPoints,
28
+  getRotatedCorners,
29
+} from 'utils/utils'
30
+import shape from 'components/canvas/shape'
31
+import {
32
+  boundsCollidePolygon,
33
+  boundsContainPolygon,
34
+  pointInBounds,
35
+} from 'utils/bounds'
20 36
 
21 37
 /*
22 38
 Shape Utiliies
@@ -47,14 +63,14 @@ export interface ShapeUtility<K extends Shape> {
47 63
 
48 64
   applyStyles(
49 65
     this: ShapeUtility<K>,
50
-    shape: K,
66
+    shape: Mutable<K>,
51 67
     style: Partial<ShapeStyles>
52 68
   ): ShapeUtility<K>
53 69
 
54 70
   // Transform to fit a new bounding box when more than one shape is selected.
55 71
   transform(
56 72
     this: ShapeUtility<K>,
57
-    shape: K,
73
+    shape: Mutable<K>,
58 74
     bounds: Bounds,
59 75
     info: {
60 76
       type: Edge | Corner
@@ -68,7 +84,7 @@ export interface ShapeUtility<K extends Shape> {
68 84
   // Transform a single shape to fit a new bounding box.
69 85
   transformSingle(
70 86
     this: ShapeUtility<K>,
71
-    shape: K,
87
+    shape: Mutable<K>,
72 88
     bounds: Bounds,
73 89
     info: {
74 90
       type: Edge | Corner
@@ -81,7 +97,7 @@ export interface ShapeUtility<K extends Shape> {
81 97
 
82 98
   setProperty<P extends keyof K>(
83 99
     this: ShapeUtility<K>,
84
-    shape: K,
100
+    shape: Mutable<K>,
85 101
     prop: P,
86 102
     value: K[P]
87 103
   ): ShapeUtility<K>
@@ -89,14 +105,14 @@ export interface ShapeUtility<K extends Shape> {
89 105
   // Respond when a user moves one of the shape's bound elements.
90 106
   onBindingMove?(
91 107
     this: ShapeUtility<K>,
92
-    shape: K,
108
+    shape: Mutable<K>,
93 109
     bindings: Record<string, ShapeBinding>
94 110
   ): ShapeUtility<K>
95 111
 
96 112
   // Respond when a user moves one of the shape's handles.
97 113
   onHandleMove?(
98 114
     this: ShapeUtility<K>,
99
-    shape: K,
115
+    shape: Mutable<K>,
100 116
     handle: Partial<K['handles']>
101 117
   ): ShapeUtility<K>
102 118
 
@@ -141,15 +157,109 @@ export function getShapeUtils<T extends Shape>(shape: T): ShapeUtility<T> {
141 157
   return shapeUtilityMap[shape.type] as ShapeUtility<T>
142 158
 }
143 159
 
160
+function getDefaultShapeUtil<T extends Shape>(): ShapeUtility<T> {
161
+  return {
162
+    boundsCache: new WeakMap(),
163
+    canTransform: true,
164
+    canChangeAspectRatio: true,
165
+    canStyleFill: true,
166
+
167
+    create(props) {
168
+      return {
169
+        id: uuid(),
170
+        isGenerated: false,
171
+        point: [0, 0],
172
+        name: 'Shape',
173
+        parentId: 'page0',
174
+        childIndex: 0,
175
+        rotation: 0,
176
+        isAspectRatioLocked: false,
177
+        isLocked: false,
178
+        isHidden: false,
179
+        ...props,
180
+      } as T
181
+    },
182
+
183
+    render(shape) {
184
+      return <circle id={shape.id} />
185
+    },
186
+
187
+    transform(shape, bounds) {
188
+      shape.point = [bounds.minX, bounds.minY]
189
+      return this
190
+    },
191
+
192
+    transformSingle(shape, bounds, info) {
193
+      return this.transform(shape, bounds, info)
194
+    },
195
+
196
+    onBindingMove() {
197
+      return this
198
+    },
199
+
200
+    onHandleMove() {
201
+      return this
202
+    },
203
+
204
+    getBounds(shape) {
205
+      const [x, y] = shape.point
206
+      return {
207
+        minX: x,
208
+        minY: y,
209
+        maxX: x + 1,
210
+        maxY: y + 1,
211
+        width: 1,
212
+        height: 1,
213
+      }
214
+    },
215
+
216
+    getRotatedBounds(shape) {
217
+      return getBoundsFromPoints(
218
+        getRotatedCorners(this.getBounds(shape), shape.rotation)
219
+      )
220
+    },
221
+
222
+    getCenter(shape) {
223
+      return getBoundsCenter(this.getBounds(shape))
224
+    },
225
+
226
+    hitTest(shape, point) {
227
+      return pointInBounds(point, this.getBounds(shape))
228
+    },
229
+
230
+    hitTestBounds(shape, brushBounds) {
231
+      const rotatedCorners = getRotatedCorners(
232
+        this.getBounds(shape),
233
+        shape.rotation
234
+      )
235
+
236
+      return (
237
+        boundsContainPolygon(brushBounds, rotatedCorners) ||
238
+        boundsCollidePolygon(brushBounds, rotatedCorners)
239
+      )
240
+    },
241
+
242
+    setProperty(shape, prop, value) {
243
+      shape[prop] = value
244
+      return this
245
+    },
246
+
247
+    applyStyles(shape, style) {
248
+      Object.assign(shape.style, style)
249
+      return this
250
+    },
251
+  }
252
+}
253
+
144 254
 /**
145 255
  *  A factory of shape utilities, with typing enforced.
146 256
  * @param shape
147 257
  * @returns
148 258
  */
149
-export function registerShapeUtils<T extends Shape>(
150
-  shape: ShapeUtility<T>
151
-): ShapeUtility<T> {
152
-  return Object.freeze(shape)
259
+export function registerShapeUtils<K extends Shape>(
260
+  shapeUtil: Partial<ShapeUtility<K>>
261
+): ShapeUtility<K> {
262
+  return Object.freeze({ ...getDefaultShapeUtil<K>(), ...shapeUtil })
153 263
 }
154 264
 
155 265
 export function createShape<T extends Shape>(

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

@@ -47,11 +47,6 @@ const line = registerShapeUtils<LineShape>({
47 47
     )
48 48
   },
49 49
 
50
-  applyStyles(shape, style) {
51
-    Object.assign(shape.style, style)
52
-    return this
53
-  },
54
-
55 50
   getBounds(shape) {
56 51
     if (!this.boundsCache.has(shape)) {
57 52
       const bounds = {
@@ -99,11 +94,6 @@ const line = registerShapeUtils<LineShape>({
99 94
     return this.transform(shape, bounds, info)
100 95
   },
101 96
 
102
-  setProperty(shape, prop, value) {
103
-    shape[prop] = value
104
-    return this
105
-  },
106
-
107 97
   canTransform: false,
108 98
   canChangeAspectRatio: false,
109 99
   canStyleFill: false,

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

@@ -33,11 +33,6 @@ const polyline = registerShapeUtils<PolylineShape>({
33 33
     return <polyline id={id} points={points.toString()} />
34 34
   },
35 35
 
36
-  applyStyles(shape, style) {
37
-    Object.assign(shape.style, style)
38
-    return this
39
-  },
40
-
41 36
   getBounds(shape) {
42 37
     if (!this.boundsCache.has(shape)) {
43 38
       this.boundsCache.set(shape, getBoundsFromPoints(shape.points))
@@ -117,11 +112,6 @@ const polyline = registerShapeUtils<PolylineShape>({
117 112
     return this
118 113
   },
119 114
 
120
-  setProperty(shape, prop, value) {
121
-    shape[prop] = value
122
-    return this
123
-  },
124
-
125 115
   canTransform: true,
126 116
   canChangeAspectRatio: true,
127 117
   canStyleFill: false,

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

@@ -45,11 +45,6 @@ const ray = registerShapeUtils<RayShape>({
45 45
     )
46 46
   },
47 47
 
48
-  applyStyles(shape, style) {
49
-    Object.assign(shape.style, style)
50
-    return this
51
-  },
52
-
53 48
   getRotatedBounds(shape) {
54 49
     return this.getBounds(shape)
55 50
   },
@@ -97,11 +92,6 @@ const ray = registerShapeUtils<RayShape>({
97 92
     return this.transform(shape, bounds, info)
98 93
   },
99 94
 
100
-  setProperty(shape, prop, value) {
101
-    shape[prop] = value
102
-    return this
103
-  },
104
-
105 95
   canTransform: false,
106 96
   canChangeAspectRatio: false,
107 97
   canStyleFill: false,

+ 2
- 44
lib/shape-utils/rectangle.tsx View File

@@ -2,12 +2,7 @@ import { v4 as uuid } from 'uuid'
2 2
 import * as vec from 'utils/vec'
3 3
 import { RectangleShape, ShapeType } from 'types'
4 4
 import { registerShapeUtils } from './index'
5
-import { boundsCollidePolygon, boundsContainPolygon } from 'utils/bounds'
6
-import {
7
-  getBoundsFromPoints,
8
-  getRotatedCorners,
9
-  translateBounds,
10
-} from 'utils/utils'
5
+import { translateBounds } from 'utils/utils'
11 6
 import { defaultStyle, getShapeStyle } from 'lib/shape-styles'
12 7
 
13 8
 const rectangle = registerShapeUtils<RectangleShape>({
@@ -48,11 +43,6 @@ const rectangle = registerShapeUtils<RectangleShape>({
48 43
     )
49 44
   },
50 45
 
51
-  applyStyles(shape, style) {
52
-    Object.assign(shape.style, style)
53
-    return this
54
-  },
55
-
56 46
   getBounds(shape) {
57 47
     if (!this.boundsCache.has(shape)) {
58 48
       const [width, height] = shape.size
@@ -71,33 +61,10 @@ const rectangle = registerShapeUtils<RectangleShape>({
71 61
     return translateBounds(this.boundsCache.get(shape), shape.point)
72 62
   },
73 63
 
74
-  getRotatedBounds(shape) {
75
-    return getBoundsFromPoints(
76
-      getRotatedCorners(this.getBounds(shape), shape.rotation)
77
-    )
78
-  },
79
-
80
-  getCenter(shape) {
81
-    const bounds = this.getRotatedBounds(shape)
82
-    return [bounds.minX + bounds.width / 2, bounds.minY + bounds.height / 2]
83
-  },
84
-
85
-  hitTest(shape) {
64
+  hitTest() {
86 65
     return true
87 66
   },
88 67
 
89
-  hitTestBounds(shape, brushBounds) {
90
-    const rotatedCorners = getRotatedCorners(
91
-      this.getBounds(shape),
92
-      shape.rotation
93
-    )
94
-
95
-    return (
96
-      boundsContainPolygon(brushBounds, rotatedCorners) ||
97
-      boundsCollidePolygon(brushBounds, rotatedCorners)
98
-    )
99
-  },
100
-
101 68
   transform(shape, bounds, { initialShape, transformOrigin, scaleX, scaleY }) {
102 69
     if (shape.rotation === 0 && !shape.isAspectRatioLocked) {
103 70
       shape.size = [bounds.width, bounds.height]
@@ -131,15 +98,6 @@ const rectangle = registerShapeUtils<RectangleShape>({
131 98
     shape.point = [bounds.minX, bounds.minY]
132 99
     return this
133 100
   },
134
-
135
-  setProperty(shape, prop, value) {
136
-    shape[prop] = value
137
-    return this
138
-  },
139
-
140
-  canTransform: true,
141
-  canChangeAspectRatio: true,
142
-  canStyleFill: true,
143 101
 })
144 102
 
145 103
 export default rectangle

+ 0
- 115
lib/shape-utils/utils-next.tsx View File

@@ -1,115 +0,0 @@
1
-interface Props {
2
-  name: string
3
-}
4
-
5
-interface Core {
6
-  id: string
7
-}
8
-
9
-interface Instance extends Props, Core {}
10
-
11
-const defaults: Props = {
12
-  name: 'Spot',
13
-}
14
-
15
-const core: Core = {
16
-  id: '0',
17
-}
18
-
19
-class ClassInstance<T extends object = {}> implements Instance {
20
-  id = '0'
21
-  name = 'Spot'
22
-
23
-  constructor(
24
-    props: Partial<Props> &
25
-      { [K in keyof T]: K extends keyof Core ? never : T[K] }
26
-  ) {
27
-    Object.assign(this, props)
28
-  }
29
-}
30
-
31
-interface InstanceConstructor {
32
-  new <T extends object = {}>(
33
-    props: Partial<Props> &
34
-      { [K in keyof T]: K extends keyof Core ? never : T[K] }
35
-  ): Instance
36
-}
37
-
38
-function makeInstance<T extends object = {}>(
39
-  props: Partial<Props> &
40
-    { [K in keyof T]: K extends keyof Core ? never : T[K] } &
41
-    ThisType<ClassInstance>
42
-) {
43
-  return new ClassInstance<T>({ ...defaults, ...props, ...core })
44
-}
45
-
46
-function getInstance<T extends object = {}>(
47
-  props: Partial<Props> &
48
-    { [K in keyof T]: K extends keyof Core ? never : T[K] }
49
-) {
50
-  return { ...defaults, ...props, ...core }
51
-}
52
-
53
-const instance = getInstance({
54
-  name: 'Steve',
55
-  age: 93,
56
-  wag(this: Instance) {
57
-    return this.name
58
-  },
59
-})
60
-
61
-interface AnimalProps {
62
-  name: string
63
-  greet(this: Animal, name: string): string
64
-}
65
-
66
-interface AnimalCore {
67
-  id: string
68
-  sleep(this: Animal): void
69
-}
70
-
71
-interface Animal extends AnimalProps, AnimalCore {}
72
-
73
-const getAnimal = <T extends object>(
74
-  props: Partial<AnimalProps> &
75
-    { [K in keyof T]: K extends keyof AnimalCore ? never : T[K] }
76
-): Animal & T => {
77
-  return {
78
-    // Defaults
79
-    name: 'Animal',
80
-    greet(name) {
81
-      return 'Hey ' + name
82
-    },
83
-    // Overrides
84
-    ...props,
85
-    // Core
86
-    id: 'hi',
87
-    sleep() {},
88
-  }
89
-}
90
-
91
-const dog = getAnimal({
92
-  name: 'doggo',
93
-  greet(name) {
94
-    return 'Woof ' + this.name
95
-  },
96
-  wag() {
97
-    return 'wagging...'
98
-  },
99
-})
100
-
101
-dog.greet('steve')
102
-dog.wag()
103
-dog.sleep()
104
-
105
-class ShapeTest {}
106
-
107
-const shapeTest = new ShapeTest()
108
-
109
-export default shapeTest
110
-
111
-type Greet = (name: string) => string
112
-
113
-const greet: Greet = (name: string | number) => {
114
-  return 'hello ' + name
115
-}

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

@@ -1,131 +0,0 @@
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
-}

+ 2
- 0
types.ts View File

@@ -395,3 +395,5 @@ export type CodeControl =
395 395
 export type PropsOfType<T extends object, K> = {
396 396
   [K in keyof T]: T[K] extends boolean ? K : never
397 397
 }[keyof T]
398
+
399
+export type Mutable<T extends Shape> = { -readonly [K in keyof T]: T[K] }

Loading…
Cancel
Save