Skip to content

Commit

Permalink
Add changes suggested by @fils.
Browse files Browse the repository at this point in the history
Skip unnecessary division for performance. Use `d` rather than `digits` to compute the power of 10.

Co-authored-by: Philippe Rivière <[email protected]>
  • Loading branch information
jasondavies and Fil authored Oct 16, 2024
1 parent 97f6a50 commit b339f8a
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b339f8a

Please sign in to comment.