Skip to content

Commit

Permalink
Removed allocations during dragging, see phetsims/circuit-constructio…
Browse files Browse the repository at this point in the history
  • Loading branch information
samreid committed Jul 7, 2017
1 parent 43aa77e commit f7d9de8
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions js/Vector2.js
Original file line number Diff line number Diff line change
Expand Up @@ -907,8 +907,20 @@ define( function( require ) {
*/
getAngleBetweenVectors: function( startVector, endVector ) {
var dx = endVector.x - startVector.x;
var dy = endVector.x - startVector.y;
return Math.atan2( dy, dx )
var dy = endVector.y - startVector.y;
return Math.atan2( dy, dx );
},

/**
* Allocation-free way to get the distance between vectors.
* @param {Vector2} startVector
* @param {Vector2} endVector
* @returns {number} the angle between the vectors
*/
getDistanceBetweenVectors: function( startVector, endVector ) {
var dx = endVector.x - startVector.x;
var dy = endVector.y - startVector.y;
return Math.sqrt( dx * dx + dy * dy );
}
} );

Expand Down

0 comments on commit f7d9de8

Please sign in to comment.