Skip to content

Commit

Permalink
perf(): clone => clonePoint, rm JSON.stringify
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaMan123 committed Jan 21, 2024
1 parent 4e76729 commit 3d2ec96
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/bezier.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ class Bezier {
// move all points by distance 'd' wrt the origin 'o',
// and move end points by fixed distance along normal.
[0, 1].forEach(function (t) {
const p = (np[t * order] = utils.copy(points[t * order]));
const p = (np[t * order] = utils.clonePoint(points[t * order]));
p.x += (t ? r2 : r1) * v[t].n.x;
p.y += (t ? r2 : r1) * v[t].n.y;
});
Expand Down
5 changes: 3 additions & 2 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ const utils = {
return "[" + points.map(utils.pointToString).join(", ") + "]";
},

copy: function (obj) {
return JSON.parse(JSON.stringify(obj));
clonePoint: function (point) {
return { x: point.x, y: point.y };
},

angle: function (o, v1, v2) {
Expand Down Expand Up @@ -528,6 +528,7 @@ const utils = {

const order = points.length - 1;
const aligned = utils.align(points, line);
console.log(aligned, line);
const reduce = function (t) {
return 0 <= t && t <= 1;
};
Expand Down

0 comments on commit 3d2ec96

Please sign in to comment.