Skip to content

Commit

Permalink
Fix: Cannot read properties of undefined (reading 'startPoints') (#8966)
Browse files Browse the repository at this point in the history
  • Loading branch information
klakhov authored Jan 21, 2025
1 parent 1140a92 commit 02719a2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 4 additions & 0 deletions changelog.d/20250120_142814_klakhov_fix_start_points.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- Error: Cannot read properties of undefined (reading 'startPoints') when dragging an object
(<https://github.com/cvat-ai/cvat/pull/8966>)
13 changes: 8 additions & 5 deletions cvat-canvas/src/typescript/canvasView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1129,9 +1129,12 @@ export class CanvasViewImpl implements CanvasView, Listener {
...(state.shapeType === 'mask' ? { snapToGrid: 1 } : {}),
});

let startPoint = null;

draggableInstance.on('dragstart', (): void => {
onDragStart();
this.draggableShape = shape;
startPoint = { x: shape.x(), y: shape.y() };
start = Date.now();
}).on('dragmove', (e: CustomEvent): void => {
onDragMove();
Expand Down Expand Up @@ -1159,18 +1162,18 @@ export class CanvasViewImpl implements CanvasView, Listener {
skeletonSVGTemplate = skeletonSVGTemplate ?? makeSVGFromTemplate(state.label.structure.svg);
setupSkeletonEdges(shape as SVG.G, skeletonSVGTemplate);
}
}).on('dragend', (e: CustomEvent): void => {
}).on('dragend', (): void => {
if (aborted) {
this.resetViewPosition(state.clientID);
return;
}

onDragEnd();
this.draggableShape = null;
const p1 = e.detail.handler.startPoints.point;
const p2 = e.detail.p;
const dx2 = (p1.x - p2.x) ** 2;
const dy2 = (p1.y - p2.y) ** 2;
const endPoint = { x: shape.x(), y: shape.y() };

const dx2 = (startPoint.x - endPoint.x) ** 2;
const dy2 = (startPoint.y - endPoint.y) ** 2;
if (Math.sqrt(dx2 + dy2) > 0) {
if (state.shapeType === 'mask') {
const { points } = state;
Expand Down

0 comments on commit 02719a2

Please sign in to comment.