mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -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) {
|
getPart: function(v, from, to) {
|
||||||
if (from > 0)
|
if (from > 0)
|
||||||
v = Curve.subdivide(v, from)[1]; // [1] right
|
v = Curve.subdivide(v, from)[1]; // [1] right
|
||||||
// Interpolate the parameter at 'to' in the new curve and
|
// Interpolate the parameter at 'to' in the new curve and cut there.
|
||||||
// cut there.
|
|
||||||
if (to < 1)
|
if (to < 1)
|
||||||
v = Curve.subdivide(v, (to - from) / (1 - from))[0]; // [0] left
|
v = Curve.subdivide(v, (to - from) / (1 - from))[0]; // [0] left
|
||||||
return v;
|
return v;
|
||||||
|
@ -838,7 +837,7 @@ statics: {
|
||||||
getLocationAt: function(offset, isParameter) {
|
getLocationAt: function(offset, isParameter) {
|
||||||
if (!isParameter)
|
if (!isParameter)
|
||||||
offset = this.getParameterAt(offset);
|
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.
|
* @return {CurveLocation} the curve location of the specified point.
|
||||||
*/
|
*/
|
||||||
getLocationOf: function(/* point */) {
|
getLocationOf: function(/* point */) {
|
||||||
var point = Point.read(arguments),
|
return this.getLocationAt(this.getParameterOf(Point.read(arguments)),
|
||||||
t = this.getParameterOf(point);
|
true);
|
||||||
return t != null ? new CurveLocation(this, t) : null;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1014,13 +1012,13 @@ new function() { // Scope for methods that require numerical integration
|
||||||
var forward = offset > 0,
|
var forward = offset > 0,
|
||||||
a = forward ? start : 0,
|
a = forward ? start : 0,
|
||||||
b = forward ? 1 : start,
|
b = forward ? 1 : start,
|
||||||
offset = Math.abs(offset),
|
|
||||||
// Use integrand to calculate both range length and part
|
// Use integrand to calculate both range length and part
|
||||||
// lengths in f(t) below.
|
// lengths in f(t) below.
|
||||||
ds = getLengthIntegrand(v),
|
ds = getLengthIntegrand(v),
|
||||||
// Get length of total range
|
// Get length of total range
|
||||||
rangeLength = Numerical.integrate(ds, a, b,
|
rangeLength = Numerical.integrate(ds, a, b,
|
||||||
getIterations(a, b));
|
getIterations(a, b));
|
||||||
|
offset = Math.abs(offset);
|
||||||
if (offset >= rangeLength)
|
if (offset >= rangeLength)
|
||||||
return forward ? b : a;
|
return forward ? b : a;
|
||||||
// Use offset / rangeLength for an initial guess for t, to
|
// Use offset / rangeLength for an initial guess for t, to
|
||||||
|
|
Loading…
Reference in a new issue