-
Notifications
You must be signed in to change notification settings - Fork 457
/
Copy pathupdatePerpendicularLineHandles.js
65 lines (56 loc) · 2.1 KB
/
updatePerpendicularLineHandles.js
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
import getLineVector from './getLineVector';
/**
* Update the perpendicular line handles when the measurement is being created.
* This method will make the perpendicular line intersect in the middle of the
* long line and assume half the size of the long line.
*
* @param {*} eventData Data object associated with the event
* @param {*} measurementData Data from current bidirectional tool measurement
*
* @returns {boolean} False in case the handle is not locked or true when moved
*/
export default function updatePerpendicularLineHandles(
eventData,
measurementData
) {
if (!measurementData.handles.perpendicularStart.locked) {
return false;
}
let startX, startY, endX, endY;
const { start, end } = measurementData.handles;
const { columnPixelSpacing = 1, rowPixelSpacing = 1 } = eventData.image;
const { scaledmageFactor = 1 } = eventData.image.imageFrame;
if (start.x === end.x && start.y === end.y) {
startX = start.originalX;
startY = start.originalY;
endX = end.originalX;
endY = end.originalY;
} else {
// Mid point of long-axis line
const mid = {
x: (start.originalX + end.originalX) / 2,
y: (start.originalY + end.originalY) / 2,
};
// Inclination of the perpendicular line
const vector = getLineVector(
columnPixelSpacing * scaledmageFactor,
rowPixelSpacing * scaledmageFactor,
start,
end
);
const perpendicularLineLength = vector.length / 2;
const rowMultiplier =
perpendicularLineLength / (2 * rowPixelSpacing * scaledmageFactor);
const columnMultiplier =
perpendicularLineLength / (2 * columnPixelSpacing * scaledmageFactor);
startX = mid.x + columnMultiplier * vector.y;
startY = mid.y - rowMultiplier * vector.x;
endX = mid.x - columnMultiplier * vector.y;
endY = mid.y + rowMultiplier * vector.x;
}
measurementData.handles.perpendicularStart.originalX = startX;
measurementData.handles.perpendicularStart.originalY = startY;
measurementData.handles.perpendicularEnd.originalX = endX;
measurementData.handles.perpendicularEnd.originalY = endY;
return true;
}