Skip to content

Commit 59d62be

Browse files
committed
added optional output argument to Vector.rotate
1 parent 26c1200 commit 59d62be

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/geometry/Vector.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,16 @@ module.exports = Vector;
6262
* @method rotate
6363
* @param {vector} vector
6464
* @param {number} angle
65-
* @return {vector} A new vector rotated about (0, 0)
65+
* @param {vector} [output]
66+
* @return {vector} The vector rotated about (0, 0)
6667
*/
67-
Vector.rotate = function(vector, angle) {
68+
Vector.rotate = function(vector, angle, output) {
6869
var cos = Math.cos(angle), sin = Math.sin(angle);
69-
return {
70-
x: vector.x * cos - vector.y * sin,
71-
y: vector.x * sin + vector.y * cos
72-
};
70+
if (!output) output = {};
71+
var x = vector.x * cos - vector.y * sin;
72+
output.y = vector.x * sin + vector.y * cos;
73+
output.x = x;
74+
return output;
7375
};
7476

7577
/**

0 commit comments

Comments
 (0)