-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartDraw.ts
More file actions
77 lines (73 loc) · 1.86 KB
/
startDraw.ts
File metadata and controls
77 lines (73 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import type { Roi } from '../../types/Roi.js';
import { assertUnreachable } from '../../utilities/assert.js';
import {
applyInverseX,
applyInverseY,
computeTotalPanZoom,
} from '../../utilities/panZoom.js';
import { createRoi } from '../../utilities/rois.js';
import type { ReactRoiState, StartDrawPayload } from '../roiReducer.js';
/**
* The draw action is executed when the user starts interacting with the container
*/
export function startDraw(draft: ReactRoiState, payload: StartDrawPayload) {
const { event, containerBoundingRect, noUnselection, lockPan } = payload;
const emptyRoi = createRoi(crypto.randomUUID());
if (payload.isPanZooming && !lockPan) {
draft.action = 'panning';
return;
}
const totalPanZoom = computeTotalPanZoom(draft);
const x = applyInverseX(
totalPanZoom,
event.clientX - containerBoundingRect.x,
);
const y = applyInverseY(
totalPanZoom,
event.clientY - containerBoundingRect.y,
);
switch (draft.mode) {
case 'hybrid':
case 'draw': {
const roi: Roi = {
...emptyRoi,
data: payload.data,
action: {
type: 'drawing',
xAxisCorner: 'left',
yAxisCorner: 'top',
previousSelectedRoi: draft.selectedRoi,
remainder: {
x: 0,
y: 0,
},
},
box: {
xRotationCenter: 'left',
yRotationCenter: 'top',
x,
y,
width: 0,
height: 0,
angle: 0,
},
};
draft.selectedRoi = roi.id;
draft.rois.push(roi);
draft.action = 'drawing';
break;
}
case 'select_rotate':
case 'select': {
if (!noUnselection) {
draft.selectedRoi = undefined;
}
if (!lockPan) {
draft.action = 'panning';
}
break;
}
default:
assertUnreachable(draft.mode);
}
}