MathUtils

public final class MathUtils


A class that contains utility methods related to numbers.

Summary

Constants

static final float
DEFAULT_EPSILON = 1.0E-4f

Default epsilon value for fuzzy float comparisons.

Public methods

static boolean
areAllElementsEqual(float[] array)

Returns whether the array contains all same elements.

static float
dist(float x1, float y1, float x2, float y2)

Returns the distance between two points.

static float
distanceToFurthestCorner(
    float pointX,
    float pointY,
    float rectLeft,
    float rectTop,
    float rectRight,
    float rectBottom
)

Returns the furthest distance from the point defined by pointX and pointY to the four corners of the rectangle defined by rectLeft, rectTop, rectRight, and rectBottom.

static float
floorMod(float x, int y)

This returns as similar as floorMod.

static int
floorMod(int x, int y)

This is same as floorMod.

static boolean
geq(float a, float b, float epsilon)

Fuzzy greater than or equal to for floats.

static float
lerp(float start, float stop, float amount)

Returns the linear interpolation of amount between start and stop.

Constants

DEFAULT_EPSILON

public static final float DEFAULT_EPSILON = 1.0E-4f

Default epsilon value for fuzzy float comparisons.

Public methods

areAllElementsEqual

public static boolean areAllElementsEqual(float[] array)

Returns whether the array contains all same elements.

Parameters
float[] array

Input array of floats.

dist

public static float dist(float x1, float y1, float x2, float y2)

Returns the distance between two points.

distanceToFurthestCorner

public static float distanceToFurthestCorner(
    float pointX,
    float pointY,
    float rectLeft,
    float rectTop,
    float rectRight,
    float rectBottom
)

Returns the furthest distance from the point defined by pointX and pointY to the four corners of the rectangle defined by rectLeft, rectTop, rectRight, and rectBottom.

The caller should ensure that the point and rectangle share the same coordinate space.

floorMod

public static float floorMod(float x, int y)

This returns as similar as floorMod. Instead it works for float type values. And the re-implementation makes it back compatible to API<24.

floorMod

public static int floorMod(int x, int y)

This is same as floorMod. Re-implementation makes it back compatible to API<24.

geq

public static boolean geq(float a, float b, float epsilon)

Fuzzy greater than or equal to for floats.

Returns true if a is greater than or equal to b, allowing for epsilon error due to limitations in floating point accuracy.

Does not handle overflow, underflow, infinity, or NaN.

lerp

public static float lerp(float start, float stop, float amount)

Returns the linear interpolation of amount between start and stop.