mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Check for valid parameter range in Curve#getLocationAt() and delegate to it in #getLocationOf()
This commit is contained in:
parent
c94fb3038f
commit
ee27fe820f
1 changed files with 5 additions and 7 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue