feat(bidirectional-tool): Reset rotation behaviour when long/short axes invert
This commit is contained in:
parent
822dc448c9
commit
b8d619390a
@ -0,0 +1,42 @@
|
|||||||
|
const swapAttribute = (a, b, attribute) => {
|
||||||
|
const originalA = a[attribute];
|
||||||
|
const originalB = b[attribute];
|
||||||
|
a[attribute] = originalB;
|
||||||
|
b[attribute] = originalA;
|
||||||
|
};
|
||||||
|
|
||||||
|
const swapHandles = (a, b) => {
|
||||||
|
swapAttribute(a, b, 'x');
|
||||||
|
swapAttribute(a, b, 'y');
|
||||||
|
swapAttribute(a, b, 'moving');
|
||||||
|
swapAttribute(a, b, 'hover');
|
||||||
|
swapAttribute(a, b, 'active');
|
||||||
|
swapAttribute(a, b, 'selected');
|
||||||
|
};
|
||||||
|
|
||||||
|
function invertHandles(eventData, measurementData, handle) {
|
||||||
|
const { rowPixelSpacing, columnPixelSpacing } = eventData.image;
|
||||||
|
const { handles } = measurementData;
|
||||||
|
const { start, end, perpendicularStart, perpendicularEnd } = handles;
|
||||||
|
|
||||||
|
// Calculate the long axis length
|
||||||
|
const dx = (start.x - end.x) * (columnPixelSpacing || 1);
|
||||||
|
const dy = (start.y - end.y) * (rowPixelSpacing || 1);
|
||||||
|
const length = Math.sqrt(dx * dx + dy * dy);
|
||||||
|
|
||||||
|
// Calculate the short axis length
|
||||||
|
const wx = (perpendicularStart.x - perpendicularEnd.x) * (columnPixelSpacing || 1);
|
||||||
|
const wy = (perpendicularStart.y - perpendicularEnd.y) * (rowPixelSpacing || 1);
|
||||||
|
const width = Math.sqrt(wx * wx + wy * wy) || 0;
|
||||||
|
|
||||||
|
if (width > length) {
|
||||||
|
swapHandles(start, end);
|
||||||
|
swapHandles(start, perpendicularStart);
|
||||||
|
swapHandles(end, perpendicularEnd);
|
||||||
|
return Object.values(handles).find(h => h.moving === true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default invertHandles;
|
||||||
@ -5,6 +5,7 @@ import { toolType, distanceThreshold } from './definitions';
|
|||||||
import mouseMoveCallback from './mouseMoveCallback';
|
import mouseMoveCallback from './mouseMoveCallback';
|
||||||
import pointNearTool from './pointNearTool';
|
import pointNearTool from './pointNearTool';
|
||||||
import moveHandle from './moveHandle';
|
import moveHandle from './moveHandle';
|
||||||
|
import invertHandles from './invertHandles';
|
||||||
|
|
||||||
// Clear the selected state for the given handles object
|
// Clear the selected state for the given handles object
|
||||||
const unselectAllHandles = handles => {
|
const unselectAllHandles = handles => {
|
||||||
@ -88,9 +89,14 @@ export default function(event) {
|
|||||||
for (let i = 0; i < toolData.data.length; i++) {
|
for (let i = 0; i < toolData.data.length; i++) {
|
||||||
data = toolData.data[i];
|
data = toolData.data[i];
|
||||||
const handleParams = [element, data.handles, coords, distanceThreshold];
|
const handleParams = [element, data.handles, coords, distanceThreshold];
|
||||||
const handle = cornerstoneTools.getHandleNearImagePoint(...handleParams);
|
let handle = cornerstoneTools.getHandleNearImagePoint(...handleParams);
|
||||||
|
|
||||||
if (handle) {
|
if (handle) {
|
||||||
|
handle.moving = true;
|
||||||
|
|
||||||
|
// Invert handles if needed
|
||||||
|
handle = invertHandles(eventData, data, handle);
|
||||||
|
|
||||||
// Hide the cursor to improve precision while resizing the line or set to move
|
// Hide the cursor to improve precision while resizing the line or set to move
|
||||||
// if dragging text box
|
// if dragging text box
|
||||||
$element.css('cursor', handle.hasBoundingBox ? 'move' : 'none');
|
$element.css('cursor', handle.hasBoundingBox ? 'move' : 'none');
|
||||||
@ -99,7 +105,6 @@ export default function(event) {
|
|||||||
data.active = true;
|
data.active = true;
|
||||||
|
|
||||||
unselectAllHandles(data.handles);
|
unselectAllHandles(data.handles);
|
||||||
handle.moving = true;
|
|
||||||
moveHandle(eventData, toolType, data, handle, () => handleDoneMove(handle));
|
moveHandle(eventData, toolType, data, handle, () => handleDoneMove(handle));
|
||||||
event.stopImmediatePropagation();
|
event.stopImmediatePropagation();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user