LT-123: intersected attribute is removed in intersectLine method,
getIntersectionRect method returns topLeft and bottomRight points instead of left, right, top, bottom points
This commit is contained in:
parent
12a326c7fe
commit
f9d697dea0
@ -986,7 +986,7 @@ var cornerstoneMath = (function (cornerstoneMath) {
|
|||||||
var a1, a2, b1, b2, c1, c2; // Coefficients of line equations
|
var a1, a2, b1, b2, c1, c2; // Coefficients of line equations
|
||||||
var r1, r2, r3, r4; // Sign values
|
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"
|
// Compute a1, b1, c1, where line joining points 1 and 2 is "a1 x + b1 y + c1 = 0"
|
||||||
a1 = y2 - y1;
|
a1 = y2 - y1;
|
||||||
@ -1004,10 +1004,7 @@ var cornerstoneMath = (function (cornerstoneMath) {
|
|||||||
if (r3 !== 0 &&
|
if (r3 !== 0 &&
|
||||||
r4 !== 0 &&
|
r4 !== 0 &&
|
||||||
cornerstoneMath.sign(r3) === cornerstoneMath.sign(r4)) {
|
cornerstoneMath.sign(r3) === cornerstoneMath.sign(r4)) {
|
||||||
intersectionPoint.x = 0;
|
return;
|
||||||
intersectionPoint.y = 0;
|
|
||||||
intersectionPoint.intersected = false;
|
|
||||||
return intersectionPoint;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Compute a2, b2, c2 */
|
/* Compute a2, b2, c2 */
|
||||||
@ -1029,10 +1026,7 @@ var cornerstoneMath = (function (cornerstoneMath) {
|
|||||||
if (r1 !== 0 &&
|
if (r1 !== 0 &&
|
||||||
r2 !== 0 &&
|
r2 !== 0 &&
|
||||||
cornerstoneMath.sign(r1) === cornerstoneMath.sign(r2)) {
|
cornerstoneMath.sign(r1) === cornerstoneMath.sign(r2)) {
|
||||||
intersectionPoint.x = 0;
|
return
|
||||||
intersectionPoint.y = 0;
|
|
||||||
intersectionPoint.intersected = false;
|
|
||||||
return intersectionPoint;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Line segments intersect: compute intersection point.
|
/* Line segments intersect: compute intersection point.
|
||||||
@ -1040,8 +1034,6 @@ var cornerstoneMath = (function (cornerstoneMath) {
|
|||||||
|
|
||||||
denom = (a1 * b2) - (a2 * b1);
|
denom = (a1 * b2) - (a2 * b1);
|
||||||
|
|
||||||
offset = denom < 0 ? -denom / 2 : denom / 2;
|
|
||||||
|
|
||||||
/* The denom/2 is to get rounding instead of truncating. It
|
/* The denom/2 is to get rounding instead of truncating. It
|
||||||
* is added or subtracted to the numerator, depending upon the
|
* is added or subtracted to the numerator, depending upon the
|
||||||
* sign of the numerator.
|
* sign of the numerator.
|
||||||
@ -1055,7 +1047,6 @@ var cornerstoneMath = (function (cornerstoneMath) {
|
|||||||
|
|
||||||
intersectionPoint.x = x;
|
intersectionPoint.x = x;
|
||||||
intersectionPoint.y = y;
|
intersectionPoint.y = y;
|
||||||
intersectionPoint.intersected = true;
|
|
||||||
|
|
||||||
return intersectionPoint;
|
return intersectionPoint;
|
||||||
}
|
}
|
||||||
@ -1859,19 +1850,23 @@ var cornerstoneMath = (function (cornerstoneMath) {
|
|||||||
return minDistance;
|
return minDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns rectangle points
|
// Returns top-left and bottom-right of rectangle
|
||||||
function rectToPoints (rect) {
|
function rectToPoints (rect) {
|
||||||
var rectPoints = {
|
var rectPoints = {
|
||||||
top: rect.top,
|
topLeft: {
|
||||||
left: rect.left,
|
x: rect.left,
|
||||||
right: rect.left + rect.width,
|
y: rect.top
|
||||||
bottom: rect.top + rect.height
|
},
|
||||||
|
bottomRight: {
|
||||||
|
x: rect.left + rect.width,
|
||||||
|
y: rect.top + rect.height
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return rectPoints;
|
return rectPoints;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns whether two rectangles are intersected
|
// Returns whether two non-rotated rectangles are intersected
|
||||||
function doesIntersect (rect1, rect2) {
|
function doesIntersect (rect1, rect2) {
|
||||||
var intersectLeftRight;
|
var intersectLeftRight;
|
||||||
var intersectTopBottom;
|
var intersectTopBottom;
|
||||||
@ -1881,34 +1876,37 @@ var cornerstoneMath = (function (cornerstoneMath) {
|
|||||||
|
|
||||||
if (rect1.width >= 0) {
|
if (rect1.width >= 0) {
|
||||||
if (rect2.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
|
else
|
||||||
intersectLeftRight = !((rect1Points.right <= rect2Points.right) || (rect2Points.left <= rect1Points.left));
|
intersectLeftRight = !((rect1Points.bottomRight.x <= rect2Points.bottomRight.x) || (rect2Points.topLeft.x <= rect1Points.topLeft.x));
|
||||||
} else {
|
} else {
|
||||||
if (rect2.width >= 0)
|
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
|
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 (rect1.height >= 0) {
|
||||||
if (rect2.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
|
else
|
||||||
intersectTopBottom = !((rect1Points.bottom <= rect2Points.bottom) || (rect2Points.top <= rect1Points.top));
|
intersectTopBottom = !((rect1Points.bottomRight.y <= rect2Points.bottomRight.y ) || (rect2Points.topLeft.y <= rect1Points.topLeft.y));
|
||||||
} else {
|
} else {
|
||||||
if (rect2.height >= 0)
|
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
|
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;
|
return intersectLeftRight && intersectTopBottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns intersection points of two rectangles
|
// Returns intersection points of two non-rotated rectangles
|
||||||
function getIntersectionRect(rect1, rect2) {
|
function getIntersectionRect(rect1, rect2) {
|
||||||
var intersectPoints = {};
|
var intersectRect = {
|
||||||
|
topLeft: {},
|
||||||
|
bottomRight: {}
|
||||||
|
};
|
||||||
|
|
||||||
if (!doesIntersect(rect1, rect2)) {
|
if (!doesIntersect(rect1, rect2)) {
|
||||||
return;
|
return;
|
||||||
@ -1919,41 +1917,42 @@ var cornerstoneMath = (function (cornerstoneMath) {
|
|||||||
|
|
||||||
if (rect1.width >= 0) {
|
if (rect1.width >= 0) {
|
||||||
if (rect2.width >= 0) {
|
if (rect2.width >= 0) {
|
||||||
intersectPoints.left = Math.max(rect1Points.left, rect2Points.left);
|
intersectRect.topLeft.x = Math.max(rect1Points.topLeft.x, rect2Points.topLeft.x);
|
||||||
intersectPoints.right = Math.min(rect1Points.right, rect2Points.right);
|
intersectRect.bottomRight.x = Math.min(rect1Points.bottomRight.x, rect2Points.bottomRight.x);
|
||||||
} else {
|
} else {
|
||||||
intersectPoints.left = Math.max(rect1Points.left, rect2Points.right);
|
intersectRect.topLeft.x = Math.max(rect1Points.topLeft.x, rect2Points.bottomRight.x);
|
||||||
intersectPoints.right = Math.min(rect1Points.right, rect2Points.left);
|
intersectRect.bottomRight.x = Math.min(rect1Points.bottomRight.x, rect2Points.topLeft.x);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (rect2.width >= 0) {
|
if (rect2.width >= 0) {
|
||||||
intersectPoints.left = Math.min(rect1Points.left, rect2Points.right);
|
intersectRect.topLeft.x = Math.min(rect1Points.topLeft.x, rect2Points.bottomRight.x);
|
||||||
intersectPoints.right = Math.max(rect1Points.right, rect2Points.left);
|
intersectRect.bottomRight.x = Math.max(rect1Points.bottomRight.x, rect2Points.topLeft.x);
|
||||||
} else {
|
} else {
|
||||||
intersectPoints.left = Math.min(rect1Points.left, rect2Points.left);
|
intersectRect.topLeft.x = Math.min(rect1Points.topLeft.x, rect2Points.topLeft.x);
|
||||||
intersectPoints.right = Math.max(rect1Points.right, rect2Points.right);
|
intersectRect.bottomRight.x = Math.max(rect1Points.bottomRight.x, rect2Points.bottomRight.x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rect1.height >= 0) {
|
if (rect1.height >= 0) {
|
||||||
if (rect2.height >= 0) {
|
if (rect2.height >= 0) {
|
||||||
intersectPoints.top = Math.max(rect1Points.top, rect2Points.top);
|
intersectRect.topLeft.y = Math.max(rect1Points.topLeft.y, rect2Points.topLeft.y);
|
||||||
intersectPoints.bottom = Math.min(rect1Points.bottom, rect2Points.bottom);
|
intersectRect.bottomRight.y = Math.min(rect1Points.bottomRight.y, rect2Points.bottomRight.y);
|
||||||
} else {
|
} else {
|
||||||
intersectPoints.top = Math.max(rect1Points.top, rect2Points.bottom);
|
intersectRect.topLeft.y = Math.max(rect1Points.topLeft.y, rect2Points.bottomRight.y);
|
||||||
intersectPoints.bottom = Math.min(rect1Points.bottom, rect2Points.top);
|
intersectRect.bottomRight.y = Math.min(rect1Points.bottomRight.y, rect2Points.topLeft.y);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (rect2.height >= 0) {
|
if (rect2.height >= 0) {
|
||||||
intersectPoints.top = Math.min(rect1Points.top, rect2Points.bottom);
|
intersectRect.topLeft.y = Math.min(rect1Points.topLeft.y, rect2Points.bottomRight.y);
|
||||||
intersectPoints.bottom = Math.max(rect1Points.bottom, rect2Points.top);
|
intersectRect.bottomRight.y = Math.max(rect1Points.bottomRight.y, rect2Points.topLeft.y);
|
||||||
} else {
|
} else {
|
||||||
intersectPoints.top = Math.min(rect1Points.top, rect2Points.top);
|
intersectRect.topLeft.y = Math.min(rect1Points.topLeft.y, rect2Points.topLeft.y);
|
||||||
intersectPoints.bottom = Math.max(rect1Points.bottom, rect2Points.bottom);
|
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -408,7 +408,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
var intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
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)) {
|
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.x = adjustedLineP2.x + distanceFromMoved * dy;
|
||||||
data.handles.perpendicularStart.y = adjustedLineP2.y - distanceFromMoved * dx;
|
data.handles.perpendicularStart.y = adjustedLineP2.y - distanceFromMoved * dx;
|
||||||
@ -490,7 +490,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
var intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
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)) {
|
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.x = adjustedLineP2.x - distanceFromMoved * dy;
|
||||||
data.handles.perpendicularEnd.y = adjustedLineP2.y + distanceFromMoved * dx;
|
data.handles.perpendicularEnd.y = adjustedLineP2.y + distanceFromMoved * dx;
|
||||||
@ -558,7 +558,7 @@
|
|||||||
perpendicularLine.end = {x: eventData.currentPoints.image.x, y: eventData.currentPoints.image.y};
|
perpendicularLine.end = {x: eventData.currentPoints.image.x, y: eventData.currentPoints.image.y};
|
||||||
|
|
||||||
intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
||||||
if (!intersection.intersected) {
|
if (!intersection) {
|
||||||
perpendicularLine.end = {x: data.handles.perpendicularStart.x, y: data.handles.perpendicularStart.y};
|
perpendicularLine.end = {x: data.handles.perpendicularStart.x, y: data.handles.perpendicularStart.y};
|
||||||
|
|
||||||
intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
||||||
@ -566,7 +566,7 @@
|
|||||||
d1 = cornerstoneMath.point.distance(intersection, data.handles.start);
|
d1 = cornerstoneMath.point.distance(intersection, data.handles.start);
|
||||||
d2 = cornerstoneMath.point.distance(intersection, data.handles.end);
|
d2 = cornerstoneMath.point.distance(intersection, data.handles.end);
|
||||||
|
|
||||||
if (!intersection.intersected || d1 < 3 || d2 < 3) {
|
if (!intersection || d1 < 3 || d2 < 3) {
|
||||||
outOfBounds = true;
|
outOfBounds = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -593,7 +593,7 @@
|
|||||||
perpendicularLine.end = {x: eventData.currentPoints.image.x, y: eventData.currentPoints.image.y};
|
perpendicularLine.end = {x: eventData.currentPoints.image.x, y: eventData.currentPoints.image.y};
|
||||||
|
|
||||||
intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
||||||
if (!intersection.intersected) {
|
if (!intersection) {
|
||||||
perpendicularLine.end = {x: data.handles.perpendicularEnd.x, y: data.handles.perpendicularEnd.y};
|
perpendicularLine.end = {x: data.handles.perpendicularEnd.x, y: data.handles.perpendicularEnd.y};
|
||||||
|
|
||||||
intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
intersection = cornerstoneMath.lineSegment.intersectLine(longLine, perpendicularLine);
|
||||||
@ -601,7 +601,7 @@
|
|||||||
d1 = cornerstoneMath.point.distance(intersection, data.handles.start);
|
d1 = cornerstoneMath.point.distance(intersection, data.handles.start);
|
||||||
d2 = cornerstoneMath.point.distance(intersection, data.handles.end);
|
d2 = cornerstoneMath.point.distance(intersection, data.handles.end);
|
||||||
|
|
||||||
if (!intersection.intersected || d1 < 3 || d2 < 3) {
|
if (!intersection || d1 < 3 || d2 < 3) {
|
||||||
outOfBounds = true;
|
outOfBounds = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
var i = 0;
|
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 = {
|
var startPoint = {
|
||||||
x: config.verticalLine.start.x,
|
x: config.verticalLine.start.x,
|
||||||
@ -39,7 +39,7 @@
|
|||||||
|
|
||||||
i = 0;
|
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 = {
|
startPoint = {
|
||||||
x: config.horizontalLine.start.x + i * config.horizontalMinorTick,
|
x: config.horizontalLine.start.x + i * config.horizontalMinorTick,
|
||||||
@ -207,22 +207,22 @@
|
|||||||
majorTickLength: 25,
|
majorTickLength: 25,
|
||||||
verticalLine: {
|
verticalLine: {
|
||||||
start: {
|
start: {
|
||||||
x: vscaleBounds.right ,
|
x: vscaleBounds.bottomRight.x,
|
||||||
y: vscaleBounds.top
|
y: vscaleBounds.topLeft.y
|
||||||
},
|
},
|
||||||
end: {
|
end: {
|
||||||
x: vscaleBounds.right,
|
x: vscaleBounds.bottomRight.x,
|
||||||
y: vscaleBounds.bottom
|
y: vscaleBounds.bottomRight.y
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
horizontalLine: {
|
horizontalLine: {
|
||||||
start: {
|
start: {
|
||||||
x: hscaleBounds.left,
|
x: hscaleBounds.topLeft.x,
|
||||||
y: hscaleBounds.bottom
|
y: hscaleBounds.bottomRight.y
|
||||||
},
|
},
|
||||||
end: {
|
end: {
|
||||||
x: hscaleBounds.right,
|
x: hscaleBounds.bottomRight.x,
|
||||||
y: hscaleBounds.bottom
|
y: hscaleBounds.bottomRight.y
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
color: cornerstoneTools.toolColors.getToolColor(),
|
color: cornerstoneTools.toolColors.getToolColor(),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user