Add test for #960 and improve fix a bit.

Closes #960
This commit is contained in:
Jürg Lehni 2016-02-12 20:19:40 +01:00
parent 7c24fc916f
commit e2bc83af5d
2 changed files with 16 additions and 2 deletions

View file

@ -1338,8 +1338,12 @@ new function() { // Scope for methods that require private functions
if (type === 0) {
// type === 0: getPoint()
// Calculate the curve point at parameter value t
x = t === 1 ? p2x : ((ax * t + bx) * t + cx) * t + p1x;
y = t === 1 ? p2y : ((ay * t + by) * t + cy) * t + p1y;
// Use special handling at t === 0 / 1, to avoid imprecisions.
// See #960
x = t === 0 ? p1x : t === 1 ? p2x
: ((ax * t + bx) * t + cx) * t + p1x;
y = t === 0 ? p1y : t === 1 ? p2y
: ((ay * t + by) * t + cy) * t + p1y;
} else {
// type === 1: getTangent()
// type === 2: getNormal()

View file

@ -37,6 +37,16 @@ test('Curve#getPointAtTime()', function() {
equals(curve.getPointAt(curve.length + 1), null,
'Should return null when offset is out of range.');
// #960:
var curve = new Curve({
segment1: [178.58559999999994, 333.41440000000006],
segment2: [178.58559999999994, 178.58560000000008]
});
equals(curve.getPointAtTime(0).y, curve.point1.y,
'Point at t=0 should not deviate from the actual coordinates.');
equals(curve.getPointAtTime(1).y, curve.point2.y,
'Point at t=1 should not deviate from the actual coordinates.');
});
test('Curve#getTangentAtTime()', function() {