Lerp precision.
authorJoe Wreschnig <joe.wreschnig@gmail.com>
Mon, 19 May 2014 08:12:44 +0000 (10:12 +0200)
committerJoe Wreschnig <joe.wreschnig@gmail.com>
Mon, 19 May 2014 08:12:44 +0000 (10:12 +0200)
string-lerp.js
tests/string-lerp.js

index 46a55bf152769f14c15af203a3cc972ce64791e8..6c240e44b61f9df46911224e1d51b6fd0aadca12 100644 (file)
             var part = nlerp(+sourcePart, +targetPart, amount);
             var sourcePoint = sourcePart.indexOf(".");
             var targetPoint = targetPart.indexOf(".");
-            var point = Math.max(
+            var point = Math.round(nlerp(
                 sourcePoint >= 0 ? (sourcePart.length - 1) - sourcePoint : 0,
-                targetPoint >= 0 ? (targetPart.length - 1) - targetPoint : 0);
+                targetPoint >= 0 ? (targetPart.length - 1) - targetPoint : 0,
+                amount));
             targetParts[i] = part.toFixed(point);
         }
         return targetParts.join("");
index 2eccba65491a1a1878fcd66fe55f04452be413a5..f2fb88dc5a46af696d10f8605cea3cd7ca7e6eb1 100644 (file)
@@ -152,14 +152,13 @@ JS.Test.describe('numeric lerp', function () { with (this) {
 
     it("rounds integers", function () { with (this) {
         assertEqual("12", lerp("0", "100", 0.123));
-        assertEqual("12.3", lerp("0", "100.0", 0.123));
+        assertEqual("12.3", lerp("0.0", "100.0", 0.123));
         assertEqual("12.3", lerp("0.0", "100", 0.123));
         assertEqual("12.3", lerp("0.0", "100.0", 0.123));
     }});
 
     it("thinks about precision", function () { with (this) {
-        assertEqual("12.30", lerp("0", "100.00", 0.123));
-        assertEqual("12.30", lerp("0.00", "100", 0.123));
+        assertEqual("12.30", lerp("0.00", "100.00", 0.123));
         assertEqual("12.300", lerp("0.000", "100.000", 0.123));
     }});