diff --git a/src/path/Curve.js b/src/path/Curve.js index 8e5e07a1..5a05ed46 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -471,36 +471,32 @@ var Curve = Base.extend(/** @lends Curve# */{ // Only divide if not at the beginning or end. if (parameter >= tMin && parameter <= tMax) { var parts = Curve.subdivide(this.getValues(), parameter), - setHandles = _setHandles || this.hasHandles(), left = parts[0], - right = parts[1]; - - // Write back the results: + right = parts[1], + setHandles = _setHandles || this.hasHandles(), + segment1 = this._segment1, + segment2 = this._segment2, + path = this._path; if (setHandles) { - this._segment1._handleOut.set(left[2] - left[0], - left[3] - left[1]); - // segment2 is the end segment. By inserting newSegment - // between segment1 and 2, 2 becomes the end segment. + // Adjust the handles on the existing segments. The new segment + // will be inserted between the existing segment1 and segment2: // Convert absolute -> relative - this._segment2._handleIn.set(right[4] - right[6], + segment1._handleOut.set(left[2] - left[0], + left[3] - left[1]); + segment2._handleIn.set(right[4] - right[6], right[5] - right[7]); } - - // Create the new segment, convert absolute -> relative: + // Create the new segment: var x = left[6], y = left[7], segment = new Segment(new Point(x, y), setHandles && new Point(left[4] - x, left[5] - y), setHandles && new Point(right[2] - x, right[3] - y)); - // Insert it in the segments list, if needed: - if (this._path) { - // Insert at the end if this curve is a closing curve of a - // closed path, since otherwise it would be inserted at 0. - if (this._segment1._index > 0 && this._segment2._index === 0) { - this._path.add(segment); - } else { - this._path.insert(this._segment2._index, segment); - } + if (path) { + // By inserting at segment1.index + 1, we make sure to insert at + // the end if this curve is a closing curve of a closed path, + // as with segment2.index it would be inserted at 0. + path.insert(segment1._index + 1, segment); // The way Path#_add handles curves, this curve will always // become the owner of the newly inserted segment. // TODO: I expect this.getNext() to produce the correct result, @@ -509,8 +505,8 @@ var Curve = Base.extend(/** @lends Curve# */{ res = this; // this.getNext(); } else { // otherwise create it from the result of split - var end = this._segment2; - this._segment2 = segment; + var end = segment2; + segment2 = segment; res = new Curve(segment, end); } } diff --git a/src/path/Path.js b/src/path/Path.js index fdc601a2..b8a07e1c 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -374,10 +374,10 @@ var Path = PathItem.extend(/** @lends Path# */{ }, /** - * Private method that adds a segment to the segment list. It assumes that - * the passed object is a segment already and does not perform any checks. - * If a curves list was requested, it will kept in sync with the segments - * list automatically. + * Private method that adds segments to the segment list. It assumes that + * the passed object is an array of segments already and does not perform + * any checks. If a curves list was requested, it will be kept in sync with + * the segments list automatically. */ _add: function(segs, index) { // Local short-cuts: diff --git a/src/path/PathItem.Boolean.js b/src/path/PathItem.Boolean.js index 49a55298..91355696 100644 --- a/src/path/PathItem.Boolean.js +++ b/src/path/PathItem.Boolean.js @@ -471,6 +471,13 @@ PathItem.inject(new function() { text.pivot = text.globalToLocal(text.point); text.scale(scaleFactor); text.rotate(textAngle); + new Path.Line({ + from: text.point, + to: seg.point, + strokeColor: color, + strokeScaling: false + }); + return text; } function drawSegment(seg, other, text, index, color) {