A class containing a set of math-related functions.

@:value(0.0000001)staticinlineread onlyEPSILON:Float = 0.0000001

Used to account for floating-point inaccuracies.

@:value(1.79e+308)staticinlineread onlyMAX_VALUE_FLOAT:Float = 1.79e+308

Maximum value of a floating point number.

@:value(0x7FFFFFFF)staticinlineread onlyMAX_VALUE_INT:Int = 0x7FFFFFFF

Maximum value of an integer.

@:value(0.0000000000000001)staticinlineread onlyMIN_VALUE_FLOAT:Float = 0.0000000000000001

Minimum value of a floating point number.

@:value(-MAX_VALUE_INT)staticinlineread onlyMIN_VALUE_INT:Int = -MAX_VALUE_INT

Minimum value of an integer.

@:value(1.41421356237)staticinlineread onlySQUARE_ROOT_OF_TWO:Float = 1.41421356237

Approximation of Math.sqrt(2).

staticinlineabsInt(n:Int):Int

Returns the absolute integer value.

staticinlinebound(Value:Float, ?Min:Float, ?Max:Float):Float

Bound a number by a minimum and maximum. Ensures that this number is no smaller than the minimum, and no larger than the maximum. Leaving a bound null means that side is unbounded.

Parameters:

Value Any number. Any number. Any number.

Returns:

The bounded value of the number.

staticinlinedistanceBetween(SpriteA:FlxSprite, SpriteB:FlxSprite):Int

Find the distance (in pixels, rounded) between two FlxSprites, taking their origin into account

Parameters:

SpriteA The first FlxSprite The second FlxSprite

Returns:

Distance between the sprites in pixels

staticinlinedistanceToMouse(Sprite:FlxSprite):Int

Find the distance (in pixels, rounded) from the object x/y and the mouse x/y

Parameters:

Sprite The FlxSprite to test against

Returns:

The distance between the given sprite and the mouse coordinates

staticinlinedistanceToPoint(Sprite:FlxSprite, Target:FlxPoint):Int

Find the distance (in pixels, rounded) from an FlxSprite to the given FlxPoint, taking the source origin into account.

Parameters:

Sprite The FlxSprite The FlxPoint

Returns:

Distance in pixels

staticinlinedistanceToTouch(Sprite:FlxSprite, Touch:FlxTouch):Int

Find the distance (in pixels, rounded) from the object x/y and the FlxPoint screen x/y

Parameters:

Sprite The FlxSprite to test against The FlxTouch to test against

Returns:

The distance between the given sprite and the mouse coordinates

staticinlinedotProduct(ax:Float, ay:Float, bx:Float, by:Float):Float

Finds the dot product value of two vectors

Parameters:

ax Vector X Vector Y Vector X Vector Y

Returns:

Result of the dot product

staticinlinefastCos(n:Float):Float

A faster, but less accurate version of Math.cos(). About 2-6 times faster with < 0.05% average error.

Parameters:

n The angle in radians.

Returns:

An approximated cosine of n.

staticinlinefastSin(n:Float):Float

A faster but slightly less accurate version of Math.sin(). About 2-6 times faster with < 0.05% average error.

Parameters:

n The angle in radians.

Returns:

An approximated sine of n.

staticgetDecimals(n:Float):Int

Returns the amount of decimals a Float has.

staticinlineinBounds(Value:Float, Min:Null<Float>, Max:Null<Float>):Bool

Checks if number is in defined range. A null bound means that side is unbounded.

Parameters:

Value Number to check. Lower bound of range. Higher bound of range.

Returns:

Returns true if Value is in range.

@:value({ IncludeEqual : false })staticinlineisDistanceToMouseWithin(Sprite:FlxSprite, Distance:Float, IncludeEqual:Bool = false):Bool

Check if the distance from the object x/y and the mouse x/y is within a specified number. A faster algorithm than distanceToMouse because the Math.sqrt() is avoided.

Parameters:

Sprite The FlxSprite to test against The distance to check If set to true, the function will return true if the calculated distance is equal to the given Distance

Returns:

True if the distance between the sprites is less than the given Distance

@:value({ IncludeEqual : false })staticinlineisDistanceToPointWithin(Sprite:FlxSprite, Target:FlxPoint, Distance:Float, IncludeEqual:Bool = false):Bool

Check if the distance from an FlxSprite to the given FlxPoint is within a specified number. A faster algorithm than distanceToPoint because the Math.sqrt() is avoided.

Parameters:

Sprite The FlxSprite The FlxPoint The distance to check If set to true, the function will return true if the calculated distance is equal to the given Distance

Returns:

True if the distance between the sprites is less than the given Distance

@:value({ IncludeEqual : false })staticinlineisDistanceToTouchWithin(Sprite:FlxSprite, Touch:FlxTouch, Distance:Float, IncludeEqual:Bool = false):Bool

Check if the distance from the object x/y and the FlxPoint screen x/y is within a specified number. A faster algorithm than distanceToTouch because the Math.sqrt() is avoided.

Parameters:

Sprite The FlxSprite to test against The distance to check If set to true, the function will return true if the calculated distance is equal to the given Distance

Returns:

True if the distance between the sprites is less than the given Distance

@:value({ IncludeEqual : false })staticinlineisDistanceWithin(SpriteA:FlxSprite, SpriteB:FlxSprite, Distance:Float, IncludeEqual:Bool = false):Bool

Check if the distance between two FlxSprites is within a specified number. A faster algorithm than distanceBetween because the Math.sqrt() is avoided.

Parameters:

SpriteA The first FlxSprite The second FlxSprite The distance to check If set to true, the function will return true if the calculated distance is equal to the given Distance

Returns:

True if the distance between the sprites is less than the given Distance

staticinlineisEven(n:Float):Bool

Returns true if the given number is even.

staticinlineisOdd(n:Float):Bool

Returns true if the given number is odd.

staticinlinelerp(a:Float, b:Float, ratio:Float):Float

Returns the linear interpolation of two numbers if ratio is between 0 and 1, and the linear extrapolation otherwise.

Examples:

lerp(a, b, 0) = a
lerp(a, b, 1) = b
lerp(5, 15, 0.5) = 10
lerp(5, 15, -1) = -5

@:value({ min : 0 })staticmaxAdd(value:Int, amount:Int, max:Int, min:Int = 0):Int

Adds the given amount to the value, but never lets the value go over the specified maximum or under the specified minimum.

Parameters:

value The value to add the amount to The amount to add to the value The maximum the value is allowed to be The minimum the value is allowed to be

Returns:

The new value

staticinlinemaxInt(a:Int, b:Int):Int

Returns the bigger argument.

staticinlineminInt(a:Int, b:Int):Int

Returns the smaller argument.

staticmouseInFlxRect(useWorldCoords:Bool, rect:FlxRect):Bool

Returns true if the mouse world x/y coordinate are within the given rectangular block

Parameters:

useWorldCoords If true the world x/y coordinates of the mouse will be used, otherwise screen x/y The FlxRect to test within. If this is null for any reason this function always returns true.

Returns:

true if mouse is within the FlxRect, otherwise false

staticnumericComparison(a:Float, b:Float):Int

Returns -1 if a is smaller, 1 if b is bigger and 0 if both numbers are equal.

staticpointInCoordinates(pointX:Float, pointY:Float, rectX:Float, rectY:Float, rectWidth:Float, rectHeight:Float):Bool

Returns true if the given x/y coordinate is within the given rectangular block

Parameters:

pointX The X value to test The Y value to test The X value of the region to test within The Y value of the region to test within The width of the region to test within The height of the region to test within

Returns:

true if pointX/pointY is within the region, otherwise false

staticpointInFlxRect(pointX:Float, pointY:Float, rect:FlxRect):Bool

Returns true if the given x/y coordinate is within the given rectangular block

Parameters:

pointX The X value to test The Y value to test The FlxRect to test within

Returns:

true if pointX/pointY is within the FlxRect, otherwise false

staticpointInRectangle(pointX:Float, pointY:Float, rect:Rectangle):Bool

Returns true if the given x/y coordinate is within the Rectangle

Parameters:

pointX The X value to test The Y value to test The Rectangle to test within

Returns:

true if pointX/pointY is within the Rectangle, otherwise false

staticremapToRange(value:Float, start1:Float, stop1:Float, start2:Float, stop2:Float):Float

Remaps a number from one range to another.

Parameters:

value The incoming value to be converted Lower bound of the value's current range Upper bound of the value's current range Lower bound of the value's target range Upper bound of the value's target range

Returns:

The remapped value

staticroundDecimal(Value:Float, Precision:Int):Float

Round a decimal number to have reduced precision (less decimal numbers).

roundDecimal(1.2485, 2) = 1.25

Parameters:

Value Any number. Number of decimals the result should have.

Returns:

The rounded value of that number.

staticinlinesameSign(a:Float, b:Float):Bool

Checks if two numbers have the same sign (using FlxMath.signOf()).

staticinlinesignOf(n:Float):Int

Returns -1 if the number is smaller than 0 and 1 otherwise

Hyperbolic sine.

staticinlinevectorLength(dx:Float, dy:Float):Float

Returns the length of the given vector.

staticwrap(value:Int, min:Int, max:Int):Int

Makes sure that value always stays between 0 and max, by wrapping the value around.

Parameters:

value The value to wrap around The minimum the value is allowed to be The maximum the value is allowed to be

Returns:

The wrapped value