mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Merge pull request #1253 from iconexperience/LineGetDistance
Add Line.getDistance() and use it in Curve.getOverlaps()
This commit is contained in:
commit
5736ebaa19
2 changed files with 11 additions and 7 deletions
|
@ -182,6 +182,10 @@ var Line = Base.extend(/** @lends Line# */{
|
||||||
return ccw < 0 ? -1 : ccw > 0 ? 1 : 0;
|
return ccw < 0 ? -1 : ccw > 0 ? 1 : 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getDistance: function(px, py, vx, vy, x, y, asVector) {
|
||||||
|
return Math.abs(Line.getSignedDistance(px, py, vx, vy, x, y, asVector));
|
||||||
|
},
|
||||||
|
|
||||||
getSignedDistance: function(px, py, vx, vy, x, y, asVector) {
|
getSignedDistance: function(px, py, vx, vy, x, y, asVector) {
|
||||||
if (!asVector) {
|
if (!asVector) {
|
||||||
vx -= px;
|
vx -= px;
|
||||||
|
|
|
@ -2203,19 +2203,19 @@ new function() { // Scope for intersection using bezier fat-line clipping
|
||||||
var flip = getSquaredLineLength(v1) < getSquaredLineLength(v2),
|
var flip = getSquaredLineLength(v1) < getSquaredLineLength(v2),
|
||||||
l1 = flip ? v2 : v1,
|
l1 = flip ? v2 : v1,
|
||||||
l2 = flip ? v1 : v2,
|
l2 = flip ? v1 : v2,
|
||||||
line = new Line(l1[0], l1[1], l1[6], l1[7]);
|
getDistance = Line.getDistance;
|
||||||
// See if the starting and end point of curve two are very close to the
|
// See if the starting and end point of curve two are very close to the
|
||||||
// picked line. Note that the curve for the picked line might not
|
// picked line. Note that the curve for the picked line might not
|
||||||
// actually be a line, so we have to perform more checks after.
|
// actually be a line, so we have to perform more checks after.
|
||||||
if (line.getDistance(new Point(l2[0], l2[1])) < geomEpsilon &&
|
if (getDistance(l1[0], l1[1], l1[6], l1[7], l2[0], l2[1]) < geomEpsilon &&
|
||||||
line.getDistance(new Point(l2[6], l2[7])) < geomEpsilon) {
|
getDistance(l1[0], l1[1], l1[6], l1[7], l2[6], l2[7]) < geomEpsilon) {
|
||||||
// If not both curves are straight, check against both of their
|
// If not both curves are straight, check against both of their
|
||||||
// handles, and treat them as straight if they are very close.
|
// handles, and treat them as straight if they are very close.
|
||||||
if (!straightBoth &&
|
if (!straightBoth &&
|
||||||
line.getDistance(new Point(l1[2], l1[3])) < geomEpsilon &&
|
getDistance(l1[0], l1[1], l1[6], l1[7], l1[2], l1[3]) < geomEpsilon &&
|
||||||
line.getDistance(new Point(l1[4], l1[5])) < geomEpsilon &&
|
getDistance(l1[0], l1[1], l1[6], l1[7], l1[4], l1[5]) < geomEpsilon &&
|
||||||
line.getDistance(new Point(l2[2], l2[3])) < geomEpsilon &&
|
getDistance(l1[0], l1[1], l1[6], l1[7], l2[2], l2[3]) < geomEpsilon &&
|
||||||
line.getDistance(new Point(l2[4], l2[5])) < geomEpsilon) {
|
getDistance(l1[0], l1[1], l1[6], l1[7], l2[4], l2[5]) < geomEpsilon) {
|
||||||
straight1 = straight2 = straightBoth = true;
|
straight1 = straight2 = straightBoth = true;
|
||||||
}
|
}
|
||||||
} else if (straightBoth) {
|
} else if (straightBoth) {
|
||||||
|
|
Loading…
Reference in a new issue