Implement #isFirst() / #isLast() tests on Segment and Curve.

This commit is contained in:
Jürg Lehni 2015-09-23 12:26:44 -04:00
parent db1ecdddd5
commit 20f950ac65
2 changed files with 44 additions and 3 deletions

View file

@ -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.
*
@ -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.
*
@ -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}
@ -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}

View file

@ -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.