Skip to content

Commit

Permalink
optimised Vertices.translate
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Apr 29, 2021
1 parent e909b04 commit 792ae2e
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/geometry/Vertices.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,16 @@ var Common = require('../core/Common');
* @param {number} scalar
*/
Vertices.translate = function(vertices, vector, scalar) {
var i;
if (scalar) {
for (i = 0; i < vertices.length; i++) {
vertices[i].x += vector.x * scalar;
vertices[i].y += vector.y * scalar;
}
} else {
for (i = 0; i < vertices.length; i++) {
vertices[i].x += vector.x;
vertices[i].y += vector.y;
}
scalar = typeof scalar !== 'undefined' ? scalar : 1;

var verticesLength = vertices.length,
translateX = vector.x * scalar,
translateY = vector.y * scalar,
i;

for (i = 0; i < verticesLength; i++) {
vertices[i].x += translateX;
vertices[i].y += translateY;
}

return vertices;
Expand Down

0 comments on commit 792ae2e

Please sign in to comment.