0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2025-01-12 16:08:50 -05:00

added optional output argument to Vector.rotate

This commit is contained in:
liabru 2017-04-25 23:43:29 +01:00
parent 26c1200387
commit 59d62be899

View file

@ -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;
};
/**