Skip to content

Commit

Permalink
Implement #isFirst() / #isLast() tests on Segment and Curve.
Browse files Browse the repository at this point in the history
  • Loading branch information
lehni committed Sep 23, 2015
1 parent db1ecdd commit 20f950a
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/path/Curve.js
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,26 @@ var Curve = Base.extend(/** @lends Curve# */{
|| this._path._closed && curves[curves.length - 1]) || null;
},

/**
* Checks if the this is the first curve in the {@link Path#curves} array.
*
* @return {Boolean} {@true if this is the first curve}
*/
isFirst: function() {
return this._segment1._index === 0;
},

/**
* Checks if the this is the last curve in the {@link Path#curves} array.
*
* @return {Boolean} {@true if this is the last curve}
*/
isLast: function() {
var path = this._path;
return path && this._segment1._index === path._curves.length - 1
|| false;
},

/**
* Specifies whether the points and handles of the curve are selected.
*
Expand Down Expand Up @@ -877,7 +897,7 @@ statics: {
* @return {Boolean} {@true if the curve is parametrically linear}
*/

/**
/**
* Checks if the the two curves describe straight lines that are
* collinear, meaning they run in parallel.
*
Expand All @@ -889,7 +909,7 @@ statics: {
&& this.getVector().isCollinear(curve.getVector());
},

/**
/**
* Checks if the curve is a straight horizontal line.
*
* @return {Boolean} {@true if the line is horizontal}
Expand All @@ -899,7 +919,7 @@ statics: {
< /*#=*/Numerical.GEOMETRIC_EPSILON;
},

/**
/**
* Checks if the curve is a straight vertical line.
*
* @return {Boolean} {@true if the line is vertical}
Expand Down
21 changes: 21 additions & 0 deletions src/path/Segment.js
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,27 @@ var Segment = Base.extend(/** @lends Segment# */{
|| this._path._closed && segments[segments.length - 1]) || null;
},

/**
* Checks if the this is the first segment in the {@link Path#segments}
* array.
*
* @return {Boolean} {@true if this is the first segment}
*/
isFirst: function() {
return this._index === 0;
},

/**
* Checks if the this is the last segment in the {@link Path#segments}
* array.
*
* @return {Boolean} {@true if this is the last segment}
*/
isLast: function() {
var path = this._path;
return path && this._index === path._segments.length - 1 || false;
},

/**
* Reverses the {@link #handleIn} and {@link #handleOut} vectors of this
* segment. Note: the actual segment is modified, no copy is created.
Expand Down

0 comments on commit 20f950a

Please sign in to comment.