From b339f8a48955c01a30247e71752b4ff4a408f52b Mon Sep 17 00:00:00 2001 From: Jason Davies Date: Wed, 16 Oct 2024 10:04:57 +0100 Subject: [PATCH] Add changes suggested by @Fils. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Skip unnecessary division for performance. Use `d` rather than `digits` to compute the power of 10. Co-authored-by: Philippe Rivière --- src/path.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/path.js b/src/path.js index 4cd9266..98015c9 100644 --- a/src/path.js +++ b/src/path.js @@ -23,26 +23,21 @@ function appendRound(digits) { }; } -function round(digits) { - const k = 10 ** digits; - return function(value) { - return Math.round(value * k) / k; - }; -} - function equal(x0, y0, x1, y1) { return x0 === x1 && y0 === y1; } function equalRound(digits) { - let d = Math.floor(digits); + const d = Math.floor(digits); if (d > 15) return equal; - const r = round(digits); + const k = 10 ** d; + const r = function(value) { + return Math.round(value * k); + }; return function(x0, y0, x1, y1) { return r(x0) === r(x1) && r(y0) === r(y1); }; } - export class Path { constructor(digits) { this._x0 = this._y0 = // start of current subpath