Allow negative offsets in all Curve#get*At() methods.

To search from the end of the curve instead of the beginning.
This commit is contained in:
Jürg Lehni 2016-06-12 18:21:37 +02:00
parent 7404485f96
commit b0d0e41ddc
2 changed files with 6 additions and 2 deletions

View file

@ -1261,7 +1261,7 @@ new function() { // Injection scope for various curve evaluation methods
this[name + 'At'] = function(location, _isTime) {
var values = this.getValues();
return Curve[name](values, _isTime ? location
: Curve.getTimeAt(values, location, 0));
: Curve.getTimeAt(values, location));
};
this[name + 'AtTime'] = function(time) {

View file

@ -163,12 +163,16 @@ test('Curve#getTimeAt()', function() {
var o1 = curve.length * f;
var o2 = -curve.length * (1 - f);
var message = 'Curve-time parameter at offset ' + o1
+ ' should be the same value as at offset' + o2;
+ ' should be the same value as at offset ' + o2;
equals(curve.getTimeAt(o1), curve.getTimeAt(o2), message,
Numerical.CURVETIME_EPSILON);
// Legacy version:
equals(curve.getParameterAt(o1), curve.getParameterAt(o2),
'Legacy: ' + message, Numerical.CURVETIME_EPSILON);
equals(curve.getTangentAt(o1), curve.getTangentAt(o2),
'Tangent at offset ' + o1
+ ' should be the same value as at offset ' + o2,
Numerical.CURVETIME_EPSILON);
}
equals(curve.getTimeAt(curve.length + 1), null,