Renamed Curve#reverse() and Segment#reverse() to #reversed()

Since they don't modify the object. Also introduce new Segment#reverse(), which does.
This commit is contained in:
Jürg Lehni 2015-09-16 18:16:48 +02:00
parent 857e27e3a8
commit d0332f843f
3 changed files with 18 additions and 4 deletions

View file

@ -522,8 +522,8 @@ var Curve = Base.extend(/** @lends Curve# */{
* *
* @return {Curve} a reversed version of the curve * @return {Curve} a reversed version of the curve
*/ */
reverse: function() { reversed: function() {
return new Curve(this._segment2.reverse(), this._segment1.reverse()); return new Curve(this._segment2.reversed(), this._segment1.reversed());
}, },
/** /**

View file

@ -393,10 +393,24 @@ var Segment = Base.extend(/** @lends Segment# */{
}, },
/** /**
* Returns the reversed the segment, without modifying the segment itself. * Reverses the {@link #handleIn} and {@link #handleOut} vectors of this
* segment. Note: the actual segment is modified, no copy is created.
* @return {Segment} the reversed segment * @return {Segment} the reversed segment
*/ */
reverse: function() { reverse: function() {
var handleIn = this._handleIn,
handleOut = this._handleOut,
inX = handleIn._x,
inY = handleIn._y;
handleIn.set(handleOut._x, handleOut._y);
handleOut.set(inX, inY);
},
/**
* Returns the reversed the segment, without modifying the segment itself.
* @return {Segment} the reversed segment
*/
reversed: function() {
return new Segment(this._point, this._handleOut, this._handleIn); return new Segment(this._point, this._handleOut, this._handleIn);
}, },

View file

@ -43,7 +43,7 @@ test('new Segment(size)', function() {
test('segment.reverse()', function() { test('segment.reverse()', function() {
var segment = new Segment(new Point(10, 10), new Point(5, 5), new Point(15, 15)); var segment = new Segment(new Point(10, 10), new Point(5, 5), new Point(15, 15));
segment = segment.reverse(); segment.reverse();
equals(segment.toString(), '{ point: { x: 10, y: 10 }, handleIn: { x: 15, y: 15 }, handleOut: { x: 5, y: 5 } }'); equals(segment.toString(), '{ point: { x: 10, y: 10 }, handleIn: { x: 15, y: 15 }, handleOut: { x: 5, y: 5 } }');
}); });