From f9d697dea01b2604716a0e9ba4a0719ed1459b77 Mon Sep 17 00:00:00 2001 From: Aysel Afsar Date: Thu, 14 Jan 2016 13:16:41 -0500 Subject: [PATCH] LT-123: intersected attribute is removed in intersectLine method, getIntersectionRect method returns topLeft and bottomRight points instead of left, right, top, bottom points --- .../cornerstone/client/cornerstoneMath.js | 89 +++++++++---------- .../client/compatibility/lesionTool.js | 12 +-- .../client/compatibility/scaleOverlayTool.js | 20 ++--- 3 files changed, 60 insertions(+), 61 deletions(-) diff --git a/Packages/cornerstone/client/cornerstoneMath.js b/Packages/cornerstone/client/cornerstoneMath.js index 464bcbd30..292fa5fd2 100644 --- a/Packages/cornerstone/client/cornerstoneMath.js +++ b/Packages/cornerstone/client/cornerstoneMath.js @@ -986,7 +986,7 @@ var cornerstoneMath = (function (cornerstoneMath) { var a1, a2, b1, b2, c1, c2; // Coefficients of line equations var r1, r2, r3, r4; // Sign values - var denom, offset, num; //Intermediate values + var denom, num; //Intermediate values // Compute a1, b1, c1, where line joining points 1 and 2 is "a1 x + b1 y + c1 = 0" a1 = y2 - y1; @@ -1004,10 +1004,7 @@ var cornerstoneMath = (function (cornerstoneMath) { if (r3 !== 0 && r4 !== 0 && cornerstoneMath.sign(r3) === cornerstoneMath.sign(r4)) { - intersectionPoint.x = 0; - intersectionPoint.y = 0; - intersectionPoint.intersected = false; - return intersectionPoint; + return; } /* Compute a2, b2, c2 */ @@ -1029,10 +1026,7 @@ var cornerstoneMath = (function (cornerstoneMath) { if (r1 !== 0 && r2 !== 0 && cornerstoneMath.sign(r1) === cornerstoneMath.sign(r2)) { - intersectionPoint.x = 0; - intersectionPoint.y = 0; - intersectionPoint.intersected = false; - return intersectionPoint; + return } /* Line segments intersect: compute intersection point. @@ -1040,8 +1034,6 @@ var cornerstoneMath = (function (cornerstoneMath) { denom = (a1 * b2) - (a2 * b1); - offset = denom < 0 ? -denom / 2 : denom / 2; - /* The denom/2 is to get rounding instead of truncating. It * is added or subtracted to the numerator, depending upon the * sign of the numerator. @@ -1055,7 +1047,6 @@ var cornerstoneMath = (function (cornerstoneMath) { intersectionPoint.x = x; intersectionPoint.y = y; - intersectionPoint.intersected = true; return intersectionPoint; } @@ -1859,19 +1850,23 @@ var cornerstoneMath = (function (cornerstoneMath) { return minDistance; } - // Returns rectangle points + // Returns top-left and bottom-right of rectangle function rectToPoints (rect) { var rectPoints = { - top: rect.top, - left: rect.left, - right: rect.left + rect.width, - bottom: rect.top + rect.height + topLeft: { + x: rect.left, + y: rect.top + }, + bottomRight: { + x: rect.left + rect.width, + y: rect.top + rect.height + } }; return rectPoints; } - // Returns whether two rectangles are intersected + // Returns whether two non-rotated rectangles are intersected function doesIntersect (rect1, rect2) { var intersectLeftRight; var intersectTopBottom; @@ -1881,34 +1876,37 @@ var cornerstoneMath = (function (cornerstoneMath) { if (rect1.width >= 0) { if (rect2.width >= 0) - intersectLeftRight = !((rect1Points.right <= rect2Points.left) || (rect2Points.right <= rect1Points.left)); + intersectLeftRight = !((rect1Points.bottomRight.x <= rect2Points.topLeft.x) || (rect2Points.bottomRight.x <= rect1Points.topLeft.x)); else - intersectLeftRight = !((rect1Points.right <= rect2Points.right) || (rect2Points.left <= rect1Points.left)); + intersectLeftRight = !((rect1Points.bottomRight.x <= rect2Points.bottomRight.x) || (rect2Points.topLeft.x <= rect1Points.topLeft.x)); } else { if (rect2.width >= 0) - intersectLeftRight = !((rect1Points.left <= rect2Points.left) || (rect2Points.right <= rect1Points.right)); + intersectLeftRight = !((rect1Points.topLeft.x <= rect2Points.topLeft.x) || (rect2Points.bottomRight.x <= rect1Points.bottomRight.x)); else - intersectLeftRight = !((rect1Points.left <= rect2Points.right) || (rect2Points.left <= rect1Points.right)); + intersectLeftRight = !((rect1Points.topLeft.x <= rect2Points.bottomRight.x) || (rect2Points.topLeft.x <= rect1Points.bottomRight.x)); } if (rect1.height >= 0) { if (rect2.height >= 0) - intersectTopBottom = !((rect1Points.bottom <= rect2Points.top) || (rect2Points.bottom <= rect1Points.top)); + intersectTopBottom = !((rect1Points.bottomRight.y <= rect2Points.topLeft.y) || (rect2Points.bottomRight.y <= rect1Points.topLeft.y)); else - intersectTopBottom = !((rect1Points.bottom <= rect2Points.bottom) || (rect2Points.top <= rect1Points.top)); + intersectTopBottom = !((rect1Points.bottomRight.y <= rect2Points.bottomRight.y ) || (rect2Points.topLeft.y <= rect1Points.topLeft.y)); } else { if (rect2.height >= 0) - intersectTopBottom = !((rect1Points.top <= rect2Points.top) || (rect2Points.bottom <= rect1Points.bottom)); + intersectTopBottom = !((rect1Points.topLeft.y <= rect2Points.topLeft.y) || (rect2Points.bottomRight.y <= rect1Points.bottomRight.y )); else - intersectTopBottom = !((rect1Points.top <= rect2Points.bottom) || (rect2Points.top <= rect1Points.bottom)); + intersectTopBottom = !((rect1Points.topLeft.y <= rect2Points.bottomRight.y ) || (rect2Points.top <= rect1Points.bottomRight.y )); } return intersectLeftRight && intersectTopBottom; } - // Returns intersection points of two rectangles + // Returns intersection points of two non-rotated rectangles function getIntersectionRect(rect1, rect2) { - var intersectPoints = {}; + var intersectRect = { + topLeft: {}, + bottomRight: {} + }; if (!doesIntersect(rect1, rect2)) { return; @@ -1919,41 +1917,42 @@ var cornerstoneMath = (function (cornerstoneMath) { if (rect1.width >= 0) { if (rect2.width >= 0) { - intersectPoints.left = Math.max(rect1Points.left, rect2Points.left); - intersectPoints.right = Math.min(rect1Points.right, rect2Points.right); + intersectRect.topLeft.x = Math.max(rect1Points.topLeft.x, rect2Points.topLeft.x); + intersectRect.bottomRight.x = Math.min(rect1Points.bottomRight.x, rect2Points.bottomRight.x); } else { - intersectPoints.left = Math.max(rect1Points.left, rect2Points.right); - intersectPoints.right = Math.min(rect1Points.right, rect2Points.left); + intersectRect.topLeft.x = Math.max(rect1Points.topLeft.x, rect2Points.bottomRight.x); + intersectRect.bottomRight.x = Math.min(rect1Points.bottomRight.x, rect2Points.topLeft.x); } } else { if (rect2.width >= 0) { - intersectPoints.left = Math.min(rect1Points.left, rect2Points.right); - intersectPoints.right = Math.max(rect1Points.right, rect2Points.left); + intersectRect.topLeft.x = Math.min(rect1Points.topLeft.x, rect2Points.bottomRight.x); + intersectRect.bottomRight.x = Math.max(rect1Points.bottomRight.x, rect2Points.topLeft.x); } else { - intersectPoints.left = Math.min(rect1Points.left, rect2Points.left); - intersectPoints.right = Math.max(rect1Points.right, rect2Points.right); + intersectRect.topLeft.x = Math.min(rect1Points.topLeft.x, rect2Points.topLeft.x); + intersectRect.bottomRight.x = Math.max(rect1Points.bottomRight.x, rect2Points.bottomRight.x); } } if (rect1.height >= 0) { if (rect2.height >= 0) { - intersectPoints.top = Math.max(rect1Points.top, rect2Points.top); - intersectPoints.bottom = Math.min(rect1Points.bottom, rect2Points.bottom); + intersectRect.topLeft.y = Math.max(rect1Points.topLeft.y, rect2Points.topLeft.y); + intersectRect.bottomRight.y = Math.min(rect1Points.bottomRight.y, rect2Points.bottomRight.y); } else { - intersectPoints.top = Math.max(rect1Points.top, rect2Points.bottom); - intersectPoints.bottom = Math.min(rect1Points.bottom, rect2Points.top); + intersectRect.topLeft.y = Math.max(rect1Points.topLeft.y, rect2Points.bottomRight.y); + intersectRect.bottomRight.y = Math.min(rect1Points.bottomRight.y, rect2Points.topLeft.y); } } else { if (rect2.height >= 0) { - intersectPoints.top = Math.min(rect1Points.top, rect2Points.bottom); - intersectPoints.bottom = Math.max(rect1Points.bottom, rect2Points.top); + intersectRect.topLeft.y = Math.min(rect1Points.topLeft.y, rect2Points.bottomRight.y); + intersectRect.bottomRight.y = Math.max(rect1Points.bottomRight.y, rect2Points.topLeft.y); } else { - intersectPoints.top = Math.min(rect1Points.top, rect2Points.top); - intersectPoints.bottom = Math.max(rect1Points.bottom, rect2Points.bottom); + intersectRect.topLeft.y = Math.min(rect1Points.topLeft.y, rect2Points.topLeft.y); + intersectRect.bottomRight.y = Math.max(rect1Points.bottomRight.y, rect2Points.bottomRight.y); } } - return intersectPoints; + // Returns top-left and bottom-right points of intersected rectangle + return intersectRect; } diff --git a/Packages/lesiontracker/client/compatibility/lesionTool.js b/Packages/lesiontracker/client/compatibility/lesionTool.js index 6b44585c3..8799e645c 100644 --- a/Packages/lesiontracker/client/compatibility/lesionTool.js +++ b/Packages/lesiontracker/client/compatibility/lesionTool.js @@ -408,7 +408,7 @@ }; var intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine); - if (!intersection.intersected) { + if (!intersection) { if (cornerstoneMath.point.distance(movedPoint, data.handles.start) > cornerstoneMath.point.distance(movedPoint, data.handles.end)) { data.handles.perpendicularStart.x = adjustedLineP2.x + distanceFromMoved * dy; data.handles.perpendicularStart.y = adjustedLineP2.y - distanceFromMoved * dx; @@ -490,7 +490,7 @@ }; var intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine); - if (!intersection.intersected) { + if (!intersection) { if (cornerstoneMath.point.distance(movedPoint, data.handles.start) > cornerstoneMath.point.distance(movedPoint, data.handles.end)) { data.handles.perpendicularEnd.x = adjustedLineP2.x - distanceFromMoved * dy; data.handles.perpendicularEnd.y = adjustedLineP2.y + distanceFromMoved * dx; @@ -558,7 +558,7 @@ perpendicularLine.end = {x: eventData.currentPoints.image.x, y: eventData.currentPoints.image.y}; intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine); - if (!intersection.intersected) { + if (!intersection) { perpendicularLine.end = {x: data.handles.perpendicularStart.x, y: data.handles.perpendicularStart.y}; intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine); @@ -566,7 +566,7 @@ d1 = cornerstoneMath.point.distance(intersection, data.handles.start); d2 = cornerstoneMath.point.distance(intersection, data.handles.end); - if (!intersection.intersected || d1 < 3 || d2 < 3) { + if (!intersection || d1 < 3 || d2 < 3) { outOfBounds = true; } } @@ -593,7 +593,7 @@ perpendicularLine.end = {x: eventData.currentPoints.image.x, y: eventData.currentPoints.image.y}; intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine); - if (!intersection.intersected) { + if (!intersection) { perpendicularLine.end = {x: data.handles.perpendicularEnd.x, y: data.handles.perpendicularEnd.y}; intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine); @@ -601,7 +601,7 @@ d1 = cornerstoneMath.point.distance(intersection, data.handles.start); d2 = cornerstoneMath.point.distance(intersection, data.handles.end); - if (!intersection.intersected || d1 < 3 || d2 < 3) { + if (!intersection || d1 < 3 || d2 < 3) { outOfBounds = true; } } diff --git a/Packages/lesiontracker/client/compatibility/scaleOverlayTool.js b/Packages/lesiontracker/client/compatibility/scaleOverlayTool.js index 7b9811d0d..fbedca2aa 100644 --- a/Packages/lesiontracker/client/compatibility/scaleOverlayTool.js +++ b/Packages/lesiontracker/client/compatibility/scaleOverlayTool.js @@ -8,7 +8,7 @@ var i = 0; - while (config.verticalLine.start.y + i * config.verticalMinorTick <= config.vscaleBounds.bottom) { + while (config.verticalLine.start.y + i * config.verticalMinorTick <= config.vscaleBounds.bottomRight.y) { var startPoint = { x: config.verticalLine.start.x, @@ -39,7 +39,7 @@ i = 0; - while (config.horizontalLine.start.x + i * config.horizontalMinorTick <= config.hscaleBounds.right) { + while (config.horizontalLine.start.x + i * config.horizontalMinorTick <= config.hscaleBounds.bottomRight.x) { startPoint = { x: config.horizontalLine.start.x + i * config.horizontalMinorTick, @@ -207,22 +207,22 @@ majorTickLength: 25, verticalLine: { start: { - x: vscaleBounds.right , - y: vscaleBounds.top + x: vscaleBounds.bottomRight.x, + y: vscaleBounds.topLeft.y }, end: { - x: vscaleBounds.right, - y: vscaleBounds.bottom + x: vscaleBounds.bottomRight.x, + y: vscaleBounds.bottomRight.y } }, horizontalLine: { start: { - x: hscaleBounds.left, - y: hscaleBounds.bottom + x: hscaleBounds.topLeft.x, + y: hscaleBounds.bottomRight.y }, end: { - x: hscaleBounds.right, - y: hscaleBounds.bottom + x: hscaleBounds.bottomRight.x, + y: hscaleBounds.bottomRight.y } }, color: cornerstoneTools.toolColors.getToolColor(),