Add Line.getDistance() and use it in Curve.getOverlaps()

This commit is contained in:
iconexperience 2017-02-07 16:15:41 +01:00
parent 13f4773985
commit af7b22a708
2 changed files with 11 additions and 7 deletions

View file

@ -182,6 +182,10 @@ var Line = Base.extend(/** @lends Line# */{
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) {
if (!asVector) {
vx -= px;

View file

@ -2203,19 +2203,19 @@ new function() { // Scope for intersection using bezier fat-line clipping
var flip = getSquaredLineLength(v1) < getSquaredLineLength(v2),
l1 = flip ? v2 : v1,
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
// picked line. Note that the curve for the picked line might not
// actually be a line, so we have to perform more checks after.
if (line.getDistance(new Point(l2[0], l2[1])) < geomEpsilon &&
line.getDistance(new Point(l2[6], l2[7])) < geomEpsilon) {
if (getDistance(l1[0], l1[1], l1[6], l1[7], l2[0], l2[1]) < 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
// handles, and treat them as straight if they are very close.
if (!straightBoth &&
line.getDistance(new Point(l1[2], l1[3])) < geomEpsilon &&
line.getDistance(new Point(l1[4], l1[5])) < geomEpsilon &&
line.getDistance(new Point(l2[2], l2[3])) < geomEpsilon &&
line.getDistance(new Point(l2[4], l2[5])) < geomEpsilon) {
getDistance(l1[0], l1[1], l1[6], l1[7], l1[2], l1[3]) < geomEpsilon &&
getDistance(l1[0], l1[1], l1[6], l1[7], l1[4], l1[5]) < geomEpsilon &&
getDistance(l1[0], l1[1], l1[6], l1[7], l2[2], l2[3]) < geomEpsilon &&
getDistance(l1[0], l1[1], l1[6], l1[7], l2[4], l2[5]) < geomEpsilon) {
straight1 = straight2 = straightBoth = true;
}
} else if (straightBoth) {