Skip to content

Commit dbde484

Browse files
jasondaviesFil
andcommitted
Add changes suggested by @Fil.
Skip unnecessary division for performance. Use `d` rather than `digits` to compute the power of 10. Co-authored-by: Philippe Rivière <fil@rezo.net>
1 parent 97f6a50 commit dbde484

1 file changed

Lines changed: 5 additions & 10 deletions

File tree

src/path.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,26 +23,21 @@ function appendRound(digits) {
2323
};
2424
}
2525

26-
function round(digits) {
27-
const k = 10 ** digits;
28-
return function(value) {
29-
return Math.round(value * k) / k;
30-
};
31-
}
32-
3326
function equal(x0, y0, x1, y1) {
3427
return x0 === x1 && y0 === y1;
3528
}
3629

3730
function equalRound(digits) {
38-
let d = Math.floor(digits);
31+
const d = Math.floor(digits);
3932
if (d > 15) return equal;
40-
const r = round(digits);
33+
const k = 10 ** d;
34+
const r = function(value) {
35+
return Math.round(value * k);
36+
};
4137
return function(x0, y0, x1, y1) {
4238
return r(x0) === r(x1) && r(y0) === r(y1);
4339
};
4440
}
45-
4641
export class Path {
4742
constructor(digits) {
4843
this._x0 = this._y0 = // start of current subpath

0 commit comments

Comments
 (0)