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:
parent
26c1200387
commit
59d62be899
1 changed files with 8 additions and 6 deletions
|
@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue