Skip to content

Commit 7366854

Browse files
committed
Merge pull request phaserjs#1307 from pnstickne/wip-math-util-cleanup
Math/Utils - various cleanup and deprecations/moves
2 parents 824c0e2 + ae6cba5 commit 7366854

9 files changed

Lines changed: 774 additions & 659 deletions

File tree

src/core/Group.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ Phaser.Group.prototype.getRandom = function (startIndex, length) {
15951595
startIndex = startIndex || 0;
15961596
length = length || this.children.length;
15971597

1598-
return this.game.math.getRandom(this.children, startIndex, length);
1598+
return Phaser.ArrayUtils.getRandomItem(this.children, startIndex, length);
15991599

16001600
};
16011601

src/geom/Circle.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,13 @@ Phaser.Circle.prototype = {
125125
* (can be Circle, Point or anything with x/y properties)
126126
* @method Phaser.Circle#distance
127127
* @param {object} dest - The target object. Must have visible x and y properties that represent the center of the object.
128-
* @param {boolean} [round] - Round the distance to the nearest integer (default false).
128+
* @param {boolean} [round=false] - Round the distance to the nearest integer.
129129
* @return {number} The distance between this Point object and the destination Point object.
130130
*/
131131
distance: function (dest, round) {
132132

133-
if (typeof round === "undefined") { round = false; }
134-
135-
if (round)
136-
{
137-
return Phaser.Math.distanceRounded(this.x, this.y, dest.x, dest.y);
138-
}
139-
else
140-
{
141-
return Phaser.Math.distance(this.x, this.y, dest.x, dest.y);
142-
}
133+
var distance = Phaser.Math.distance(this.x, this.y, dest.x, dest.y);
134+
return round ? Math.round(distance) : distance;
143135

144136
},
145137

src/geom/Point.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -708,21 +708,13 @@ Phaser.Point.rperp = function (a, out) {
708708
* @method Phaser.Point.distance
709709
* @param {object} a - The target object. Must have visible x and y properties that represent the center of the object.
710710
* @param {object} b - The target object. Must have visible x and y properties that represent the center of the object.
711-
* @param {boolean} [round] - Round the distance to the nearest integer (default false).
711+
* @param {boolean} [round=false] - Round the distance to the nearest integer.
712712
* @return {number} The distance between this Point object and the destination Point object.
713713
*/
714714
Phaser.Point.distance = function (a, b, round) {
715715

716-
if (typeof round === "undefined") { round = false; }
717-
718-
if (round)
719-
{
720-
return Phaser.Math.distanceRounded(a.x, a.y, b.x, b.y);
721-
}
722-
else
723-
{
724-
return Phaser.Math.distance(a.x, a.y, b.x, b.y);
725-
}
716+
var distance = Phaser.Math.distance(a.x, a.y, b.x, b.y);
717+
return round ? Math.round(distance) : distance;
726718

727719
};
728720

0 commit comments

Comments
 (0)