|
|
@@ -145,14 +145,7 @@ const arrow = registerShapeUtils<ArrowShape>({
|
|
145
|
145
|
|
|
146
|
146
|
getBounds(shape) {
|
|
147
|
147
|
if (!this.boundsCache.has(shape)) {
|
|
148
|
|
- this.boundsCache.set(
|
|
149
|
|
- shape,
|
|
150
|
|
- getBoundsFromPoints([
|
|
151
|
|
- ...shape.points,
|
|
152
|
|
- shape.handles['bend'].point,
|
|
153
|
|
- // vec.sub(shape.handles['bend'].point, shape.point),
|
|
154
|
|
- ])
|
|
155
|
|
- )
|
|
|
148
|
+ this.boundsCache.set(shape, getBoundsFromPoints(shape.points))
|
|
156
|
149
|
}
|
|
157
|
150
|
|
|
158
|
151
|
return translateBounds(this.boundsCache.get(shape), shape.point)
|
|
|
@@ -215,6 +208,8 @@ const arrow = registerShapeUtils<ArrowShape>({
|
|
215
|
208
|
transform(shape, bounds, { initialShape, scaleX, scaleY }) {
|
|
216
|
209
|
const initialShapeBounds = this.getBounds(initialShape)
|
|
217
|
210
|
|
|
|
211
|
+ // console.log([...shape.point], [bounds.minX, bounds.minY])
|
|
|
212
|
+
|
|
218
|
213
|
shape.point = [bounds.minX, bounds.minY]
|
|
219
|
214
|
|
|
220
|
215
|
shape.points = shape.points.map((_, i) => {
|
|
|
@@ -234,6 +229,28 @@ const arrow = registerShapeUtils<ArrowShape>({
|
|
234
|
229
|
]
|
|
235
|
230
|
})
|
|
236
|
231
|
|
|
|
232
|
+ const { start, end, bend } = shape.handles
|
|
|
233
|
+
|
|
|
234
|
+ start.point = shape.points[0]
|
|
|
235
|
+ end.point = shape.points[1]
|
|
|
236
|
+
|
|
|
237
|
+ // start.point[0] = initialShape.handles.start.point[0] * scaleX
|
|
|
238
|
+ // end.point[0] = initialShape.handles.end.point[0] * scaleX
|
|
|
239
|
+
|
|
|
240
|
+ // start.point[1] = initialShape.handles.start.point[1] * scaleY
|
|
|
241
|
+ // end.point[1] = initialShape.handles.end.point[1] * scaleY
|
|
|
242
|
+
|
|
|
243
|
+ const bendDist = (vec.dist(start.point, end.point) / 2) * shape.bend
|
|
|
244
|
+ const midPoint = vec.med(start.point, end.point)
|
|
|
245
|
+ const u = vec.uni(vec.vec(start.point, end.point))
|
|
|
246
|
+
|
|
|
247
|
+ bend.point =
|
|
|
248
|
+ Math.abs(bendDist) > 10
|
|
|
249
|
+ ? vec.add(midPoint, vec.mul(vec.per(u), bendDist))
|
|
|
250
|
+ : midPoint
|
|
|
251
|
+
|
|
|
252
|
+ shape.points = [shape.handles.start.point, shape.handles.end.point]
|
|
|
253
|
+
|
|
237
|
254
|
return this
|
|
238
|
255
|
},
|
|
239
|
256
|
|
|
|
@@ -248,6 +265,8 @@ const arrow = registerShapeUtils<ArrowShape>({
|
|
248
|
265
|
},
|
|
249
|
266
|
|
|
250
|
267
|
onHandleMove(shape, handles) {
|
|
|
268
|
+ const { start, end, bend } = shape.handles
|
|
|
269
|
+
|
|
251
|
270
|
for (let id in handles) {
|
|
252
|
271
|
const handle = handles[id]
|
|
253
|
272
|
|
|
|
@@ -257,9 +276,6 @@ const arrow = registerShapeUtils<ArrowShape>({
|
|
257
|
276
|
shape.points[handle.index] = handle.point
|
|
258
|
277
|
}
|
|
259
|
278
|
|
|
260
|
|
- const { start, end, bend } = shape.handles
|
|
261
|
|
-
|
|
262
|
|
- const midPoint = vec.med(start.point, end.point)
|
|
263
|
279
|
const dist = vec.dist(start.point, end.point)
|
|
264
|
280
|
|
|
265
|
281
|
if (handle.id === 'bend') {
|
|
|
@@ -272,15 +288,17 @@ const arrow = registerShapeUtils<ArrowShape>({
|
|
272
|
288
|
shape.bend = clamp(distance / (dist / 2), -1, 1)
|
|
273
|
289
|
if (!vec.clockwise(start.point, bend.point, end.point)) shape.bend *= -1
|
|
274
|
290
|
}
|
|
|
291
|
+ }
|
|
275
|
292
|
|
|
276
|
|
- const bendDist = (dist / 2) * shape.bend
|
|
277
|
|
- const u = vec.uni(vec.vec(start.point, end.point))
|
|
|
293
|
+ const dist = vec.dist(start.point, end.point)
|
|
|
294
|
+ const midPoint = vec.med(start.point, end.point)
|
|
|
295
|
+ const bendDist = (dist / 2) * shape.bend
|
|
|
296
|
+ const u = vec.uni(vec.vec(start.point, end.point))
|
|
278
|
297
|
|
|
279
|
|
- bend.point =
|
|
280
|
|
- Math.abs(bendDist) > 10
|
|
281
|
|
- ? vec.add(midPoint, vec.mul(vec.per(u), bendDist))
|
|
282
|
|
- : midPoint
|
|
283
|
|
- }
|
|
|
298
|
+ bend.point =
|
|
|
299
|
+ Math.abs(bendDist) > 10
|
|
|
300
|
+ ? vec.add(midPoint, vec.mul(vec.per(u), bendDist))
|
|
|
301
|
+ : midPoint
|
|
284
|
302
|
|
|
285
|
303
|
return this
|
|
286
|
304
|
},
|