public final class MathUtils extends Object
Thanks to Riven on JavaGaming.org for the basis of sin/cos/atan2/floor/ceil.
Modifier and Type | Field and Description |
---|---|
static float |
degRad |
static float |
degreesToRadians
multiply by this to convert from degrees to radians
|
static float |
E |
static float |
FLOAT_ROUNDING_ERROR |
static float |
nanoToSec |
static float |
PI |
static float |
PI2 |
static float |
radDeg |
static float |
radiansToDegrees
multiply by this to convert from radians to degrees
|
static Random |
random |
Constructor and Description |
---|
MathUtils() |
Modifier and Type | Method and Description |
---|---|
static float |
atan2(float y,
float x)
Returns atan2 in radians from a lookup table.
|
static int |
ceil(float x)
Returns the smallest integer greater than or equal to the specified float.
|
static int |
ceilPositive(float x)
Returns the smallest integer greater than or equal to the specified float.
|
static float |
clamp(float value,
float min,
float max) |
static int |
clamp(int value,
int min,
int max) |
static short |
clamp(short value,
short min,
short max) |
static float |
cos(float radians)
Returns the cosine in radians from a lookup table.
|
static float |
cosDeg(float degrees)
Returns the cosine in radians from a lookup table.
|
static int |
floor(float x)
Returns the largest integer less than or equal to the specified float.
|
static int |
floorPositive(float x)
Returns the largest integer less than or equal to the specified float.
|
static boolean |
isEqual(float a,
float b)
Returns true if a is nearly equal to b.
|
static boolean |
isEqual(float a,
float b,
float tolerance)
Returns true if a is nearly equal to b.
|
static boolean |
isPowerOfTwo(int value) |
static boolean |
isZero(float value)
Returns true if the value is zero (using the default tolerance as upper bound)
|
static boolean |
isZero(float value,
float tolerance)
Returns true if the value is zero.
|
static float |
lerp(float fromValue,
float toValue,
float progress)
Linearly interpolates between fromValue to toValue on progress position.
|
static int |
nextPowerOfTwo(int value)
Returns the next power of two.
|
static float |
random()
Returns random number between 0.0 (inclusive) and 1.0 (exclusive).
|
static float |
random(float range)
Returns a random number between 0 (inclusive) and the specified value (exclusive).
|
static float |
random(float start,
float end)
Returns a random number between start (inclusive) and end (exclusive).
|
static int |
random(int range)
Returns a random number between 0 (inclusive) and the specified value (inclusive).
|
static int |
random(int start,
int end)
Returns a random number between start (inclusive) and end (inclusive).
|
static boolean |
randomBoolean()
Returns a random boolean value.
|
static boolean |
randomBoolean(float chance)
Returns true if a random value between 0 and 1 is less than the specified value.
|
static int |
round(float x)
Returns the closest integer to the specified float.
|
static int |
roundPositive(float x)
Returns the closest integer to the specified float.
|
static float |
sin(float radians)
Returns the sine in radians from a lookup table.
|
static float |
sinDeg(float degrees)
Returns the sine in radians from a lookup table.
|
public static final float nanoToSec
public static final float FLOAT_ROUNDING_ERROR
public static final float PI
public static final float PI2
public static final float E
public static final float radiansToDegrees
public static final float radDeg
public static final float degreesToRadians
public static final float degRad
public static Random random
public static float sin(float radians)
public static float cos(float radians)
public static float sinDeg(float degrees)
public static float cosDeg(float degrees)
public static float atan2(float y, float x)
public static int random(int range)
public static int random(int start, int end)
public static boolean randomBoolean()
public static boolean randomBoolean(float chance)
public static float random()
public static float random(float range)
public static float random(float start, float end)
public static int nextPowerOfTwo(int value)
public static boolean isPowerOfTwo(int value)
public static int clamp(int value, int min, int max)
public static short clamp(short value, short min, short max)
public static float clamp(float value, float min, float max)
public static float lerp(float fromValue, float toValue, float progress)
public static int floor(float x)
public static int floorPositive(float x)
public static int ceil(float x)
public static int ceilPositive(float x)
public static int round(float x)
public static int roundPositive(float x)
public static boolean isZero(float value)
public static boolean isZero(float value, float tolerance)
tolerance
- represent an upper bound below which the value is considered zero.public static boolean isEqual(float a, float b)
a
- the first value.b
- the second value.public static boolean isEqual(float a, float b, float tolerance)
a
- the first value.b
- the second value.tolerance
- represent an upper bound below which the two values are considered equal.Copyright © 2014. All Rights Reserved.