mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
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:
parent
857e27e3a8
commit
d0332f843f
3 changed files with 18 additions and 4 deletions
|
@ -522,8 +522,8 @@ var Curve = Base.extend(/** @lends Curve# */{
|
|||
*
|
||||
* @return {Curve} a reversed version of the curve
|
||||
*/
|
||||
reverse: function() {
|
||||
return new Curve(this._segment2.reverse(), this._segment1.reverse());
|
||||
reversed: function() {
|
||||
return new Curve(this._segment2.reversed(), this._segment1.reversed());
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
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);
|
||||
},
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ test('new Segment(size)', function() {
|
|||
|
||||
test('segment.reverse()', function() {
|
||||
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 } }');
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue