From 9aafb46e6c4122ea20a6b67cfdca466b6bedf9c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Sat, 4 May 2013 02:50:18 -0700 Subject: [PATCH] Remove need for __segment property and further simplify computeBoolean() code. --- src/path/CurveLocation.js | 8 ++++---- src/path/PathItem.Boolean.js | 15 +++++---------- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/path/CurveLocation.js b/src/path/CurveLocation.js index 52022bc5..197ae76c 100644 --- a/src/path/CurveLocation.js +++ b/src/path/CurveLocation.js @@ -57,14 +57,14 @@ var CurveLocation = this.CurveLocation = Base.extend(/** @lends CurveLocation# * * @type Segment * @bean */ - getSegment: function() { + getSegment: function(/* preferFirst */) { if (!this._segment) { var curve = this.getCurve(), parameter = this.getParameter(); - if (parameter === 0) { - this._segment = curve._segment1; - } else if (parameter === 1) { + if (parameter === 1) { this._segment = curve._segment2; + } else if (parameter === 0 || arguments[0]) { + this._segment = curve._segment1; } else if (parameter == null) { return null; } else { diff --git a/src/path/PathItem.Boolean.js b/src/path/PathItem.Boolean.js index b6029f23..78450cef 100644 --- a/src/path/PathItem.Boolean.js +++ b/src/path/PathItem.Boolean.js @@ -57,7 +57,6 @@ PathItem.inject(new function() { segment = curve && curve.getSegment1() || loc.getSegment(); if (others) others.push(other); - other.__segment = segment; segment._ixPair = other; } return others; @@ -168,22 +167,18 @@ PathItem.inject(new function() { continue; var path = node.path, nuPath = new Path(), - firstNode = node, - intersectNode = null; + end = node._ixPair && node._ixPair.getSegment(true); if (node.getPrevious()._INVALID) { node.setHandleIn(node._ixPair - ? node._ixPair.getIntersection().__segment._handleIn + ? node._ixPair.getSegment(true)._handleIn : Point.create(0, 0)); } - while (node && !node._visited && node !== intersectNode) { + do { node._visited = true; - intersectNode = intersectNode || firstNode._ixPair - && firstNode._ixPair.getIntersection().__segment; // node._ixPair is this node's intersection CurveLocation object - // node._ixPair.getIntersection() is the other CurveLocation object this node intersects with if (node._ixPair) { var nextNode = node._INVALID - ? node._ixPair.getIntersection().__segment + ? node._ixPair.getSegment(true) : node; nuPath.add(new Segment(node._point, node._handleIn, nextNode._handleOut)); @@ -193,7 +188,7 @@ PathItem.inject(new function() { nuPath.add(node); } node = node.getNext(); - } + } while (node && !node._visited && node !== end); // Avoid stray segments and incomplete paths if (nuPath._segments.length > 2) { nuPath.setClosed(true);