diff --git a/src/path/Segment.js b/src/path/Segment.js index 1b821a8e..1a183a51 100644 --- a/src/path/Segment.js +++ b/src/path/Segment.js @@ -125,9 +125,7 @@ var Segment = Base.extend(/** @lends Segment# */{ } else { point = arg0; } - } else if ((count === 2 || count === 3) && typeof arg0 === 'number') { - // We check for 3 and 2 because there is an optional boolean - // argument for segment points to mark them as selected. + } else if (count === 2 && typeof arg0 === 'number') { point = arguments; } else if (count <= 3) { point = arg0; @@ -140,9 +138,9 @@ var Segment = Base.extend(/** @lends Segment# */{ handleIn = arg2 !== undefined ? [ arg2, arg3 ] : null; handleOut = arg4 !== undefined ? [ arg4, arg5 ] : null; } - this._point = new SegmentPoint(point, this); - this._handleIn = new SegmentPoint(handleIn, this); - this._handleOut = new SegmentPoint(handleOut, this); + new SegmentPoint(point, this, '_point'); + new SegmentPoint(handleIn, this, '_handleIn'); + new SegmentPoint(handleOut, this, '_handleOut'); }, _serialize: function(options) { @@ -316,7 +314,7 @@ var Segment = Base.extend(/** @lends Segment# */{ !!(state & /*#=*/ SelectionState.HANDLE_IN), !!(state & /*#=*/ SelectionState.HANDLE_OUT) ]; - if (point == this._point) { + if (point === this._point) { if (selected) { // We're selecting point, deselect the handles selection[1] = selection[2] = false; @@ -332,7 +330,7 @@ var Segment = Base.extend(/** @lends Segment# */{ } selection[0] = selected; } else { - var index = point == this._handleIn ? 1 : 2; + var index = point === this._handleIn ? 1 : 2; if (selection[index] != selected) { // When selecting handles, the point get deselected. if (selected) diff --git a/src/path/SegmentPoint.js b/src/path/SegmentPoint.js index c8ae6b01..6498f8a9 100644 --- a/src/path/SegmentPoint.js +++ b/src/path/SegmentPoint.js @@ -18,13 +18,12 @@ * @private */ var SegmentPoint = Point.extend({ - initialize: function SegmentPoint(point, owner) { + initialize: function SegmentPoint(point, owner, key) { var x, y, selected; if (!point) { x = y = 0; } else if ((x = point[0]) !== undefined) { // Array-like y = point[1]; - selected = point[2]; // See #_serialize() } else { // If not Point-like already, read Point from arguments if ((x = point.x) === undefined) { @@ -37,6 +36,9 @@ var SegmentPoint = Point.extend({ this._x = x; this._y = y; this._owner = owner; + // We have to set the owner's property that points to this point already + // now, so #setSelected(true) can work. + owner[key] = this; if (selected) this.setSelected(true); }, @@ -50,11 +52,11 @@ var SegmentPoint = Point.extend({ _serialize: function(options) { var f = options.formatter, - values = [f.number(this._x), f.number(this._y)]; - // Included the selected state of the segment point - if (this.isSelected()) - values.push(true); - return values; + x = f.number(this._x), + y = f.number(this._y); + return this.isSelected() + ? { x: x, y: y, selected: true } + : [x, y]; }, getX: function() {