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

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