Rename CurveLocation#getLength() and #getCurveLength() to #getOffset() and #getCurveOffset(), and seperate Path#getLength([location]) into #getLength() and #_getOffset().

This commit is contained in:
Jürg Lehni 2011-04-27 20:08:57 +01:00
parent b0a1f4b1a9
commit 016f4c15aa
2 changed files with 22 additions and 30 deletions

View file

@ -72,22 +72,18 @@ CurveLocation = Base.extend({
* The length of the path from its beginning up to the location described * The length of the path from its beginning up to the location described
* by this object. * by this object.
*/ */
getLength: function() { getOffset: function() {
var path = this._curve && this._curve.getPath(); 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 * The length of the curve from its beginning up to the location described
* by this object. * by this object.
*/ */
getCurveLength: function() { getCurveOffset: function() {
if (this.curve) { var parameter = this._curve && this.getParameter();
var parameter = this.getParameter(); return parameter != null ? this._curve.getLength(0, parameter) : null;
return parameter != null
? curve.getLength(0, parameter)
: null;
}
}, },
/** /**

View file

@ -233,30 +233,26 @@ var Path = this.Path = PathItem.extend({
} }
return null; return null;
}, },
getLength: function(/* location */) { getLength: function() {
var location; var curves = this.getCurves();
if (arguments.length) var length = 0;
location = arguments[0]; for (var i = 0, l = curves.length; i < l; i++)
var curves = this.getCurves(), length += curves[i].getLength();
index = location return length;
? location.getIndex() },
: curves.length;
_getOffset: function(location) {
var index = location && location.getIndex();
if (index != null) { if (index != null) {
var length = 0; var curves = this.getCurves(),
offset = 0;
for (var i = 0; i < index; i++) for (var i = 0; i < index; i++)
length += curves[i].getLength(); offset += curves[i].getLength();
var curve; var curve = curves[index];
if (location) { return offset + curve.getLength(0, location.getParameter());
// 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;
} }
return -1; return null;
}, },
/** /**