Check for valid parameter range in Curve#getLocationAt() and delegate to it in #getLocationOf()

This commit is contained in:
Jürg Lehni 2014-09-20 11:09:09 +02:00
parent c94fb3038f
commit ee27fe820f

View file

@ -629,8 +629,7 @@ statics: {
getPart: function(v, from, to) {
if (from > 0)
v = Curve.subdivide(v, from)[1]; // [1] right
// Interpolate the parameter at 'to' in the new curve and
// cut there.
// Interpolate the parameter at 'to' in the new curve and cut there.
if (to < 1)
v = Curve.subdivide(v, (to - from) / (1 - from))[0]; // [0] left
return v;
@ -838,7 +837,7 @@ statics: {
getLocationAt: function(offset, isParameter) {
if (!isParameter)
offset = this.getParameterAt(offset);
return new CurveLocation(this, offset);
return offset >= 0 && offset <= 1 && new CurveLocation(this, offset);
},
/**
@ -848,9 +847,8 @@ statics: {
* @return {CurveLocation} the curve location of the specified point.
*/
getLocationOf: function(/* point */) {
var point = Point.read(arguments),
t = this.getParameterOf(point);
return t != null ? new CurveLocation(this, t) : null;
return this.getLocationAt(this.getParameterOf(Point.read(arguments)),
true);
},
/**
@ -1014,13 +1012,13 @@ new function() { // Scope for methods that require numerical integration
var forward = offset > 0,
a = forward ? start : 0,
b = forward ? 1 : start,
offset = Math.abs(offset),
// Use integrand to calculate both range length and part
// lengths in f(t) below.
ds = getLengthIntegrand(v),
// Get length of total range
rangeLength = Numerical.integrate(ds, a, b,
getIterations(a, b));
offset = Math.abs(offset);
if (offset >= rangeLength)
return forward ? b : a;
// Use offset / rangeLength for an initial guess for t, to