diff --git a/src/basic/Line.js b/src/basic/Line.js index af99855c..7ed66852 100644 --- a/src/basic/Line.js +++ b/src/basic/Line.js @@ -184,9 +184,9 @@ var Line = Base.extend(/** @lends Line# */{ } // Based on the error analysis by @iconexperience outlined in // https://github.com/paperjs/paper.js/issues/799 - return vx == 0 + return vx === 0 ? vy >= 0 ? px - x : x - px - : vy == 0 + : vy === 0 ? vx >= 0 ? y - py : py - y : (vx * (y - py) - vy * (x - px)) / Math.sqrt(vx * vx + vy * vy); } diff --git a/src/path/CurveLocation.js b/src/path/CurveLocation.js index d475cf3d..ab80b917 100644 --- a/src/path/CurveLocation.js +++ b/src/path/CurveLocation.js @@ -365,10 +365,16 @@ var CurveLocation = Base.extend(/** @lends CurveLocation# */{ * @see #isCrossing() */ isTouching: function() { - var t1 = this.getTangent(), - inter = this._intersection, - t2 = inter && inter.getTangent(); - return t1 && t2 ? t1.isCollinear(t2) : false; + var inter = this._intersection; + if (inter && this.getTangent().isCollinear(inter.getTangent())) { + // Only consider two straight curves as touching if their lines + // don't intersect. + var curve1 = this.getCurve(), + curve2 = inter.getCurve(); + return !(curve1.isStraight() && curve2.isStraight() + && curve1.getLine().intersect(curve2.getLine())); + } + return false; }, /** diff --git a/src/path/PathItem.Boolean.js b/src/path/PathItem.Boolean.js index 80a4b32e..c038298a 100644 --- a/src/path/PathItem.Boolean.js +++ b/src/path/PathItem.Boolean.js @@ -119,7 +119,7 @@ PathItem.inject(new function() { var intersections = CurveLocation.expand( _path1.getIntersections(_path2, function(inter) { // Only handle overlaps when not self-intersecting - return inter.isCrossing() || _path2 && inter.isOverlap(); + return _path2 && inter.isOverlap() || inter.isCrossing(); }) ); // console.timeEnd('intersection'); @@ -161,9 +161,9 @@ PathItem.inject(new function() { path1, path2, true); } - function logIntersection(title, inter) { + function logIntersection(inter) { var other = inter._intersection; - var log = [title, inter._id, 'id', inter.getPath()._id, + var log = ['Intersection', inter._id, 'id', inter.getPath()._id, 'i', inter.getIndex(), 't', inter.getParameter(), 'o', inter.isOverlap(), 'p', inter.getPoint(), 'Other', other._id, 'id', other.getPath()._id, @@ -216,7 +216,7 @@ PathItem.inject(new function() { locations.forEach(function(inter) { if (inter._other) return; - logIntersection('Intersection', inter); + logIntersection(inter); new Path.Circle({ center: inter.point, radius: 2 * scaleFactor, @@ -292,17 +292,11 @@ PathItem.inject(new function() { } if (window.reportIntersections) { - console.log('After', locations.length / 2); + console.log('Split Crossings'); locations.forEach(function(inter) { - if (inter._other) - return; - logIntersection('Intersection', inter); - new Path.Circle({ - center: inter.point, - radius: 2 * scaleFactor, - strokeColor: 'red', - strokeScaling: false - }); + if (!inter._other) { + logIntersection(inter); + } }); } }