Skip to content

Commit a6d2da2

Browse files
committed
Math/Utils - various cleanup and deprecations/moves
There are no known breaking changes. - Timer - Uses standard Math.min/Math.max (it's better 2, 3 items). - Math - Updated documentation - Marked various Math functions as deprecated, proxying as appropriate - Array-based functions -> ArrayUtils - RNG-based functions -> Utils - Updated core-usage - floor/ceil should not be used (alternatives provided) - Altered for some equivalencies - Also fixes some assorted issues - Marked a few internal functions as private - Utils - Moved polyfills to their own file for better visibility - Moved array functions to ArrayUtils and marked proxies as deprecated - Created Phaser.ArrayUtils for array-related functions - polyfills moved to their own file - Functions given function names - Added Math.trunc
1 parent 0fc70db commit a6d2da2

9 files changed

Lines changed: 608 additions & 518 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)