Some code optimizations and cleanup.

This commit is contained in:
Jürg Lehni 2017-02-11 21:25:42 +01:00
parent 1b50355585
commit 23202d0c80
2 changed files with 14 additions and 10 deletions

View file

@ -182,10 +182,6 @@ 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;
@ -195,6 +191,11 @@ var Line = Base.extend(/** @lends Line# */{
return vx === 0 ? vy > 0 ? x - px : px - x
: vy === 0 ? vx < 0 ? y - py : py - y
: ((x-px) * vy - (y-py) * vx) / Math.sqrt(vx * vx + vy * vy);
},
getDistance: function(px, py, vx, vy, x, y, asVector) {
return Math.abs(
Line.getSignedDistance(px, py, vx, vy, x, y, asVector));
}
}
});

View file

@ -2203,19 +2203,22 @@ new function() { // Scope for intersection using bezier fat-line clipping
var flip = getSquaredLineLength(v1) < getSquaredLineLength(v2),
l1 = flip ? v2 : v1,
l2 = flip ? v1 : v2,
// Get l1 start and end point values for faster referencing.
x1 = l1[0], y1 = l1[1],
x2 = l1[6], y2 = 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 (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 (getDistance(x1, y1, x2, y2, l2[0], l2[1]) < geomEpsilon &&
getDistance(x1, y1, x2, y2, 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 &&
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) {
getDistance(x1, y1, x2, y2, l1[2], l1[3]) < geomEpsilon &&
getDistance(x1, y1, x2, y2, l1[4], l1[5]) < geomEpsilon &&
getDistance(x1, y1, x2, y2, l2[2], l2[3]) < geomEpsilon &&
getDistance(x1, y1, x2, y2, l2[4], l2[5]) < geomEpsilon) {
straight1 = straight2 = straightBoth = true;
}
} else if (straightBoth) {