mirror of
https://github.com/photonstorm/phaser
synced 2024-11-28 07:31:11 +00:00
Fix for #1761: [Feature Request] Add Math.distanceSq(). Also, first attempt at a pull request for Phaser.
This commit is contained in:
parent
8290e8c371
commit
61f24f1719
1 changed files with 33 additions and 13 deletions
|
@ -1095,6 +1095,26 @@ Phaser.Math = {
|
|||
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the euclidian distance squared between the two given set of
|
||||
* coordinates (cuts out a square root operation before returning).
|
||||
*
|
||||
* @method Phaser.Math#distanceSq
|
||||
* @param {number} x1
|
||||
* @param {number} y1
|
||||
* @param {number} x2
|
||||
* @param {number} y2
|
||||
* @return {number} The distance squared between the two sets of coordinates.
|
||||
*/
|
||||
distanceSq: function (x1, y1, x2, y2) {
|
||||
|
||||
var dx = x1 - x2;
|
||||
var dy = y1 - y2;
|
||||
|
||||
return dx * dx + dy * dy;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Returns the distance between the two given set of coordinates at the power given.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue