From e2bc83af5d1c79db5d0212ac93c0d6176bbd263f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=BCrg=20Lehni?= <juerg@scratchdisk.com>
Date: Fri, 12 Feb 2016 20:19:40 +0100
Subject: [PATCH] Add test for #960 and improve fix a bit.

Closes #960
---
 src/path/Curve.js   |  8 ++++++--
 test/tests/Curve.js | 10 ++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/path/Curve.js b/src/path/Curve.js
index 4895da53..32a550ac 100644
--- a/src/path/Curve.js
+++ b/src/path/Curve.js
@@ -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()
diff --git a/test/tests/Curve.js b/test/tests/Curve.js
index c03ccf35..7139e437 100644
--- a/test/tests/Curve.js
+++ b/test/tests/Curve.js
@@ -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() {