Improve handling of _changed() events in Segment.

This commit is contained in:
Jürg Lehni 2014-03-12 22:58:00 +01:00
parent dc76ef144e
commit 847060e146

View file

@ -150,25 +150,27 @@ var Segment = Base.extend(/** @lends Segment# */{
}, },
_changed: function(point) { _changed: function(point) {
if (!this._path) var path = this._path;
if (!path)
return; return;
// Delegate changes to affected curves if they exist. Check _curves // Delegate changes to affected curves if they exist.
// first to make sure we're not creating it by calling this.getCurve(). var curves = path._curves,
var curve = this._path._curves && this.getCurve(), index = this._index,
other; curveIn, curveOut;
if (curve) { if (curves) {
curve._changed(); // Updated the neighboring affected curves, depending on which point
// Get the other affected curve, which is the previous one for // is changing.
// _point or _handleIn changing when this segment is _segment1 of // TODO: Consider exposing these curves too, through #curveIn,
// the curve, for all other cases it's the next (e.g. _handleOut // and #curveOut, next to #curve?
// when this segment is _segment2) if ((!point || point === this._point || point === this._handleIn)
if (other = (curve[point == this._point && (curveIn = curves[index - 1]
|| point == this._handleIn && curve._segment1 == this || path._closed && curves[curves.length - 1]))
? 'getPrevious' : 'getNext']())) { curveIn._changed();
other._changed(); if ((!point || point === this._point || point === this._handleOut)
} && (curveOut = curves[index]))
curveOut._changed();
} }
this._path._changed(/*#=*/ Change.GEOMETRY); path._changed(/*#=*/ Change.GEOMETRY);
}, },
/** /**
@ -373,7 +375,8 @@ var Segment = Base.extend(/** @lends Segment# */{
}, },
/** /**
* The curve that the segment belongs to. * The curve that the segment belongs to. For the last segment of an open
* path, the previous segment is returned.
* *
* @type Curve * @type Curve
* @bean * @bean