diff --git a/src/geometry/Vector.js b/src/geometry/Vector.js index 0eaacdf..bfc512d 100644 --- a/src/geometry/Vector.js +++ b/src/geometry/Vector.js @@ -62,14 +62,16 @@ module.exports = Vector; * @method rotate * @param {vector} vector * @param {number} angle - * @return {vector} A new vector rotated about (0, 0) + * @param {vector} [output] + * @return {vector} The vector rotated about (0, 0) */ - Vector.rotate = function(vector, angle) { + Vector.rotate = function(vector, angle, output) { var cos = Math.cos(angle), sin = Math.sin(angle); - return { - x: vector.x * cos - vector.y * sin, - y: vector.x * sin + vector.y * cos - }; + if (!output) output = {}; + var x = vector.x * cos - vector.y * sin; + output.y = vector.x * sin + vector.y * cos; + output.x = x; + return output; }; /**