Utilities for performing mathematical operations.

Static variables

@:value(2.71828182845904523536)staticfinalread onlyE:Float = 2.71828182845904523536

Euler's constant and the base of the natural logarithm. Math.E is not a constant in Haxe, so we'll just define it ourselves.

Static methods

staticcameraLerp(lerp:Float):Float

Deprecated: "Use smoothLerpPrecision instead"

Perform linear interpolation based on the current framerate.

Parameters:

lerp

Value used to interpolate between base and target.

Returns:

The interpolated value.

staticcoolLerp(base:Float, target:Float, ratio:Float):Float

Deprecated: "Use smoothLerpPrecision instead"

Perform linear interpolation between the base and the target, based on the current framerate.

Parameters:

base

The starting value, when progress <= 0.

target

The ending value, when progress >= 1.

ratio

Value used to interpolate between base and target.

Returns:

The interpolated value.

@:value({ c : 1.70158 })staticeaseInBack(x:Float, c:Float = 1.70158):Float

@:value({ c : 1.70158 })staticeaseInOutBack(x:Float, c:Float = 1.70158):Float

staticeaseInOutCirc(x:Float):Float

@:value({ c : 1.70158 })staticeaseOutBack(x:Float, c:Float = 1.70158):Float

staticexp2(x:Float):Float

Get the base-2 exponent of a value.

Parameters:

x

value

Returns:

2^x

staticfract(x:Float):Float

Helper function to get the fractional part of a value.

Parameters:

x

value

Returns:

x mod 1.

staticgcd(m:Int, n:Int):Int

GCD stands for Greatest Common Divisor It's used in FullScreenScaleMode to prevent weird window resolutions from being counted as wide screen since those were causing issues positioning the game It returns the greatest common divisor between m and n

think it's from hxp..?

Parameters:

m
n

Returns:

Int the common divisor between m and n

staticlerp(base:Float, target:Float, alpha:Float):Float

Linear interpolation.

Parameters:

base

The starting value, when alpha = 0.

target

The ending value, when alpha = 1.

alpha

The percentage of the interpolation from base to target. Forms a "line" intersecting the two.

Returns:

The interpolated value.

staticlogBase(base:Float, value:Float):Float

Get the logarithm of a value with a given base.

Parameters:

base

The base of the logarithm.

value

The value to get the logarithm of.

Returns:

log_base(value)

staticmod(a:Float, b:Float):Float

Performs a modulo operation to calculate the remainder of a divided by b.

The definition of "remainder" varies by implementation; this one is similar to GLSL or Python in that it uses Euclidean division, which always returns positive, while Haxe's % operator uses signed truncated division.

For example, -5 % 3 returns -2 while FlxMath.mod(-5, 3) returns 1.

Parameters:

a

The dividend.

b

The divisor.

Returns:

a mod b.

@:value({ precision : 1 / 100 })staticsmoothLerp(current:Float, target:Float, elapsed:Float, duration:Float, precision:Float = 1 / 100):Float

Deprecated: "Use smoothLerpPrecision instead"

Backwards compatibility for smoothLerpPrecision.

Perform a framerate-independent linear interpolation between the base value and the target.

Parameters:

current

The current value.

target

The target value.

elapsed

The time elapsed since the last frame.

duration

The total duration of the interpolation. Nominal duration until remaining distance is less than precision.

precision

The target precision of the interpolation. Defaults to 1% of distance remaining.

Returns:

A value between the current value and the target value.

See also:

staticsmoothLerpDecay(base:Float, target:Float, deltaTime:Float, halfLife:Float):Float

Exponential decay interpolation.

Framerate-independent because the rate-of-change is proportional to the difference, so you can use the time elapsed since the last frame as deltaTime and the function will be consistent.

Equivalent to smoothLerpPrecision(base, target, deltaTime, halfLife, 0.5).

Parameters:

base

The starting or current value.

target

The value this function approaches.

deltaTime

The change in time along the function in seconds.

halfLife

Time in seconds to reach halfway to target.

Returns:

The interpolated value.

See also:

@:value({ precision : 1 / 100 })staticsmoothLerpPrecision(base:Float, target:Float, deltaTime:Float, duration:Float, precision:Float = 1 / 100):Float

Exponential decay interpolation.

Framerate-independent because the rate-of-change is proportional to the difference, so you can use the time elapsed since the last frame as deltaTime and the function will be consistent.

Equivalent to smoothLerpDecay(base, target, deltaTime, -duration / logBase(2, precision)).

Parameters:

base

The starting or current value.

target

The value this function approaches.

deltaTime

The change in time along the function in seconds.

duration

Time in seconds to reach target within precision, relative to the original distance.

precision

Relative target precision of the interpolation. Defaults to 1% distance remaining.

Returns:

The interpolated value.

See also:

staticsnap(base:Float, target:Float, threshold:Float):Float

Snap a value to another if it's within a certain distance (inclusive).

Helpful when using functions like smoothLerpPrecision to ensure the value actually reaches the target.

Parameters:

base

The base value to conditionally snap.

target

The target value to snap to.

threshold

Maximum distance between the two for snapping to occur.

Returns:

target if base is within threshold of it, otherwise base.