From 20f950ac65dfb0f28bdc467bf31742e240fefa1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 23 Sep 2015 12:26:44 -0400 Subject: [PATCH] Implement #isFirst() / #isLast() tests on Segment and Curve. --- src/path/Curve.js | 26 +++++++++++++++++++++++--- src/path/Segment.js | 21 +++++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/src/path/Curve.js b/src/path/Curve.js index 9923e2df34..1a9f2616fb 100644 --- a/src/path/Curve.js +++ b/src/path/Curve.js @@ -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} diff --git a/src/path/Segment.js b/src/path/Segment.js index 61b7d610fa..c42bbb7683 100644 --- a/src/path/Segment.js +++ b/src/path/Segment.js @@ -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.