From 5bc5aa65b769e551177545fda77b31ea6c66467e Mon Sep 17 00:00:00 2001 From: Joe Wreschnig Date: Mon, 19 May 2014 10:12:44 +0200 Subject: [PATCH] Lerp precision. --- string-lerp.js | 5 +++-- tests/string-lerp.js | 5 ++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/string-lerp.js b/string-lerp.js index 46a55bf..6c240e4 100644 --- a/string-lerp.js +++ b/string-lerp.js @@ -193,9 +193,10 @@ 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(""); diff --git a/tests/string-lerp.js b/tests/string-lerp.js index 2eccba6..f2fb88d 100644 --- a/tests/string-lerp.js +++ b/tests/string-lerp.js @@ -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)); }}); -- 2.30.2