This commit is contained in:
Richard Davey 2021-03-26 10:05:54 +00:00
commit f060fec275
4 changed files with 49 additions and 13 deletions

View file

@ -122,7 +122,7 @@ var GameObjectFactory = new Class({
* @method Phaser.GameObjects.GameObjectFactory#existing
* @since 3.0.0
*
* @generic {Phaser.GameObjects.GameObject} G - [child,$return]
* @generic {(Phaser.GameObjects.GameObject|Phaser.GameObjects.Group)} G - [child,$return]
*
* @param {(Phaser.GameObjects.GameObject|Phaser.GameObjects.Group)} child - The child to be added to this Scene.
*

35
src/math/Median.js Normal file
View file

@ -0,0 +1,35 @@
/**
* @author Vladislav Forsh <vlad@robowhale.com>
* @copyright 2021 RoboWhale
* @license {@link https://opensource.org/licenses/MIT|MIT License}
*/
/**
* Calculate the median of the given values. The values are sorted and the middle value is returned.
* In case of an even number of values, the average of the two middle values is returned.
*
* @function Phaser.Math.Median
* @since 3.54.0
*
* @param {number[]} values - The values to average.
*
* @return {number} The median value.
*/
var Median = function (values)
{
var valuesNum = values.length;
if (valuesNum === 0)
{
return 0;
}
values.sort(function (a, b) { return a - b; });
var halfIndex = Math.floor(valuesNum / 2);
return valuesNum % 2 === 0
? (values[halfIndex] + values[halfIndex - 1]) / 2
: values[halfIndex];
};
module.exports = Median;

View file

@ -83,7 +83,7 @@ var Vector2 = new Class({
* @method Phaser.Math.Vector2#copy
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector to copy the components from.
* @param {Phaser.Types.Math.Vector2Like} src - The Vector to copy the components from.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
@ -179,7 +179,7 @@ var Vector2 = new Class({
* @method Phaser.Math.Vector2#equals
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} v - The vector to compare with this Vector.
* @param {Phaser.Types.Math.Vector2Like} v - The vector to compare with this Vector.
*
* @return {boolean} Whether the given Vector is equal to this Vector.
*/
@ -194,7 +194,7 @@ var Vector2 = new Class({
* @method Phaser.Math.Vector2#fuzzyEquals
* @since 3.23.0
*
* @param {Phaser.Math.Vector2} v - The vector to compare with this Vector.
* @param {Phaser.Types.Math.Vector2Like} v - The vector to compare with this Vector.
* @param {number} [epsilon=0.0001] - The tolerance value.
*
* @return {boolean} Whether both absolute differences of the x and y components are smaller than `epsilon`.
@ -247,7 +247,7 @@ var Vector2 = new Class({
* @method Phaser.Math.Vector2#add
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector to add to this Vector.
* @param {Phaser.Types.Math.Vector2Like} src - The Vector to add to this Vector.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
@ -265,7 +265,7 @@ var Vector2 = new Class({
* @method Phaser.Math.Vector2#subtract
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector to subtract from this Vector.
* @param {Phaser.Types.Math.Vector2Like} src - The Vector to subtract from this Vector.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
@ -285,7 +285,7 @@ var Vector2 = new Class({
* @method Phaser.Math.Vector2#multiply
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector to multiply this Vector by.
* @param {Phaser.Types.Math.Vector2Like} src - The Vector to multiply this Vector by.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
@ -331,7 +331,7 @@ var Vector2 = new Class({
* @method Phaser.Math.Vector2#divide
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector to divide this Vector by.
* @param {Phaser.Types.Math.Vector2Like} src - The Vector to divide this Vector by.
*
* @return {Phaser.Math.Vector2} This Vector2.
*/
@ -365,7 +365,7 @@ var Vector2 = new Class({
* @method Phaser.Math.Vector2#distance
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector to calculate the distance to.
* @param {Phaser.Types.Math.Vector2Like} src - The Vector to calculate the distance to.
*
* @return {number} The distance from this Vector to the given Vector.
*/
@ -383,7 +383,7 @@ var Vector2 = new Class({
* @method Phaser.Math.Vector2#distanceSq
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector to calculate the distance to.
* @param {Phaser.Types.Math.Vector2Like} src - The Vector to calculate the distance to.
*
* @return {number} The distance from this Vector to the given Vector, squared.
*/
@ -511,7 +511,7 @@ var Vector2 = new Class({
* @method Phaser.Math.Vector2#dot
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector2 to dot product with this Vector2.
* @param {Phaser.Types.Math.Vector2Like} src - The Vector2 to dot product with this Vector2.
*
* @return {number} The dot product of this Vector and the given Vector.
*/
@ -526,7 +526,7 @@ var Vector2 = new Class({
* @method Phaser.Math.Vector2#cross
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector2 to cross with this Vector2.
* @param {Phaser.Types.Math.Vector2Like} src - The Vector2 to cross with this Vector2.
*
* @return {number} The cross product of this Vector and the given Vector.
*/
@ -543,7 +543,7 @@ var Vector2 = new Class({
* @method Phaser.Math.Vector2#lerp
* @since 3.0.0
*
* @param {Phaser.Math.Vector2} src - The Vector2 to interpolate towards.
* @param {Phaser.Types.Math.Vector2Like} src - The Vector2 to interpolate towards.
* @param {number} [t=0] - The interpolation percentage, between 0 and 1.
*
* @return {Phaser.Math.Vector2} This Vector2.

View file

@ -44,6 +44,7 @@ var PhaserMath = {
IsEvenStrict: require('./IsEvenStrict'),
Linear: require('./Linear'),
MaxAdd: require('./MaxAdd'),
Median: require('./Median'),
MinSub: require('./MinSub'),
Percent: require('./Percent'),
RadToDeg: require('./RadToDeg'),