Skip to content

Commit

Permalink
added optional output argument to Vector.rotate
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed Apr 25, 2017
1 parent 26c1200 commit 59d62be
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/geometry/Vector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand Down

0 comments on commit 59d62be

Please sign in to comment.