From 792ae2ead45eb38ea4813179bc96febac1364e6c Mon Sep 17 00:00:00 2001 From: liabru Date: Mon, 26 Apr 2021 23:36:09 +0100 Subject: [PATCH] optimised Vertices.translate --- src/geometry/Vertices.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/geometry/Vertices.js b/src/geometry/Vertices.js index 8e487de8..285eb070 100644 --- a/src/geometry/Vertices.js +++ b/src/geometry/Vertices.js @@ -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;