diff --git a/src/path/CurveLocation.js b/src/path/CurveLocation.js index 3ddce0ca..2f3920af 100644 --- a/src/path/CurveLocation.js +++ b/src/path/CurveLocation.js @@ -72,22 +72,18 @@ CurveLocation = Base.extend({ * The length of the path from its beginning up to the location described * by this object. */ - getLength: function() { + getOffset: function() { var path = this._curve && this._curve.getPath(); - return path && path.getLength(this); + return path && path._getOffset(this); }, /** * The length of the curve from its beginning up to the location described * by this object. */ - getCurveLength: function() { - if (this.curve) { - var parameter = this.getParameter(); - return parameter != null - ? curve.getLength(0, parameter) - : null; - } + getCurveOffset: function() { + var parameter = this._curve && this.getParameter(); + return parameter != null ? this._curve.getLength(0, parameter) : null; }, /** diff --git a/src/path/Path.js b/src/path/Path.js index 78c021f8..62d56577 100644 --- a/src/path/Path.js +++ b/src/path/Path.js @@ -233,30 +233,26 @@ var Path = this.Path = PathItem.extend({ } return null; }, - - getLength: function(/* location */) { - var location; - if (arguments.length) - location = arguments[0]; - var curves = this.getCurves(), - index = location - ? location.getIndex() - : curves.length; + + getLength: function() { + var curves = this.getCurves(); + var length = 0; + for (var i = 0, l = curves.length; i < l; i++) + length += curves[i].getLength(); + return length; + }, + + _getOffset: function(location) { + var index = location && location.getIndex(); if (index != null) { - var length = 0; + var curves = this.getCurves(), + offset = 0; for (var i = 0; i < index; i++) - length += curves[i].getLength(); - var curve; - if (location) { - // Clone the curve as we're going to divide it to get the - // length. Without cloning it, this would modify the path. - curve = curves[index].clone(); - curve.divide(location.getParameter()); - length += curve.getLength(); - } - return length; + offset += curves[i].getLength(); + var curve = curves[index]; + return offset + curve.getLength(0, location.getParameter()); } - return -1; + return null; }, /**