Skip to content

Commit a1bd35f

Browse files
committed
Tidied up formatting and improved jsdocs.
1 parent b4a72b8 commit a1bd35f

2 files changed

Lines changed: 40 additions & 21 deletions

File tree

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,9 @@ If you are an exceptional JavaScript developer and would like to join the Phaser
260260

261261
### Updates
262262

263-
* TypeScript definitions fixes and updates (thanks @clark-stevenson)
264-
* JSDoc typo fixes (thanks )
263+
* TypeScript definitions fixes and updates (thanks @clark-stevenson @milkey-mouse)
264+
* JSDoc typo fixes (thanks @rwrountree)
265+
* Math.average has been optimized (thanks @rwrountree #2025)
265266

266267
### Bug Fixes
267268

src/math/Math.js

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,66 +27,83 @@ Phaser.Math = {
2727
* Two number are fuzzyEqual if their difference is less than epsilon.
2828
*
2929
* @method Phaser.Math#fuzzyEqual
30-
* @param {number} a
31-
* @param {number} b
32-
* @param {number} [epsilon=(small value)]
30+
* @param {number} a - The first number to compare.
31+
* @param {number} b - The second number to compare.
32+
* @param {number} [epsilon=0.0001] - The epsilon (a small value used in the calculation)
3333
* @return {boolean} True if |a-b|<epsilon
3434
*/
3535
fuzzyEqual: function (a, b, epsilon) {
36+
3637
if (epsilon === undefined) { epsilon = 0.0001; }
38+
3739
return Math.abs(a - b) < epsilon;
40+
3841
},
3942

4043
/**
4144
* `a` is fuzzyLessThan `b` if it is less than b + epsilon.
4245
*
4346
* @method Phaser.Math#fuzzyLessThan
44-
* @param {number} a
45-
* @param {number} b
46-
* @param {number} [epsilon=(small value)]
47+
* @param {number} a - The first number to compare.
48+
* @param {number} b - The second number to compare.
49+
* @param {number} [epsilon=0.0001] - The epsilon (a small value used in the calculation)
4750
* @return {boolean} True if a<b+epsilon
4851
*/
4952
fuzzyLessThan: function (a, b, epsilon) {
53+
5054
if (epsilon === undefined) { epsilon = 0.0001; }
55+
5156
return a < b + epsilon;
57+
5258
},
5359

5460
/**
5561
* `a` is fuzzyGreaterThan `b` if it is more than b - epsilon.
5662
*
5763
* @method Phaser.Math#fuzzyGreaterThan
58-
* @param {number} a
59-
* @param {number} b
60-
* @param {number} [epsilon=(small value)]
64+
* @param {number} a - The first number to compare.
65+
* @param {number} b - The second number to compare.
66+
* @param {number} [epsilon=0.0001] - The epsilon (a small value used in the calculation)
6167
* @return {boolean} True if a>b+epsilon
6268
*/
6369
fuzzyGreaterThan: function (a, b, epsilon) {
70+
6471
if (epsilon === undefined) { epsilon = 0.0001; }
72+
6573
return a > b - epsilon;
74+
6675
},
6776

6877
/**
78+
* Applies a fuzzy ceil to the given value.
79+
*
6980
* @method Phaser.Math#fuzzyCeil
70-
*
71-
* @param {number} val
72-
* @param {number} [epsilon=(small value)]
81+
* @param {number} val - The value to ceil.
82+
* @param {number} [epsilon=0.0001] - The epsilon (a small value used in the calculation)
7383
* @return {number} ceiling(val-epsilon)
7484
*/
7585
fuzzyCeil: function (val, epsilon) {
86+
7687
if (epsilon === undefined) { epsilon = 0.0001; }
88+
7789
return Math.ceil(val - epsilon);
90+
7891
},
7992

8093
/**
94+
* Applies a fuzzy floor to the given value.
95+
*
8196
* @method Phaser.Math#fuzzyFloor
82-
*
83-
* @param {number} val
84-
* @param {number} [epsilon=(small value)]
97+
* @param {number} val - The value to floor.
98+
* @param {number} [epsilon=0.0001] - The epsilon (a small value used in the calculation)
8599
* @return {number} floor(val+epsilon)
86100
*/
87101
fuzzyFloor: function (val, epsilon) {
102+
88103
if (epsilon === undefined) { epsilon = 0.0001; }
104+
89105
return Math.floor(val + epsilon);
106+
90107
},
91108

92109
/**
@@ -98,14 +115,15 @@ Phaser.Math = {
98115
*/
99116
average: function () {
100117

101-
var sum = 0,
102-
argumentsLength = arguments.length;
118+
var sum = 0;
119+
var len = arguments.length;
103120

104-
for (var i = 0; i < argumentsLength; i++) {
121+
for (var i = 0; i < len; i++)
122+
{
105123
sum += (+arguments[i]);
106124
}
107125

108-
return sum / argumentsLength;
126+
return sum / len;
109127

110128
},
111129

0 commit comments

Comments
 (0)