Restructuring bidirectionalTool to improve maintainability

This commit is contained in:
Bruno Alves de Faria committed 2017-12-28 08:59:25 -02:00
1 parent 4aa0204119
commit 0acdff0bc5
22 files changed
+1290 -1

No files matched your search

@@ -0,0 +1,33 @@
import { cornerstone, cornerstoneMath, cornerstoneTools } from 'meteor/ohif:cornerstone';
import { distanceThreshold } from './definitions';
const pointNearPerpendicular = (element, handles, coords) => {
const lineSegment = {
start: cornerstone.pixelToCanvas(element, handles.perpendicularStart),
end: cornerstone.pixelToCanvas(element, handles.perpendicularEnd)
};
const distanceToPoint = cornerstoneMath.lineSegment.distanceToPoint(lineSegment, coords);
return (distanceToPoint < distanceThreshold);
};
export default function(element, data, coords) {
const { handles } = data;
const lineSegment = {
start: cornerstone.pixelToCanvas(element, handles.start),
end: cornerstone.pixelToCanvas(element, handles.end)
};
const distanceToPoint = cornerstoneMath.lineSegment.distanceToPoint(lineSegment, coords);
if (cornerstoneTools.pointInsideBoundingBox(handles.textBox, coords)) {
return true;
}
if (pointNearPerpendicular(element, handles, coords)) {
return true;
}
return (distanceToPoint < distanceThreshold);
}