Package org.oscim.utils.math
Class MathUtils
java.lang.Object
org.oscim.utils.math.MathUtils
Utility and fast math functions.
Thanks to Riven on JavaGaming.org for the basis of sin/cos/atan2/floor/ceil.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final floatstatic final floatstatic final floatstatic final floatstatic final floatstatic final floatstatic final floatstatic Random -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic final floatatan2(float y, float x) Returns atan2 in radians from a lookup table.static intceil(float x) Returns the smallest integer greater than or equal to the specified float.static intceilPositive(float x) Returns the smallest integer greater than or equal to the specified float.static floatclamp(float value, float min, float max) static intclamp(int value, int min, int max) static shortclamp(short value, short min, short max) static final floatcos(float radians) Returns the cosine in radians.static final floatcosDeg(float degrees) Returns the cosine in radians.static intfloor(float x) Returns the largest integer less than or equal to the specified float.static intfloorPositive(float x) Returns the largest integer less than or equal to the specified float.static booleanisPowerOfTwo(int value) static intnextPowerOfTwo(int value) Returns the next power of two.static final floatrandom()Returns random number between 0.0 (inclusive) and 1.0 (exclusive).static final floatrandom(float range) Returns a random number between 0 (inclusive) and the specified value (exclusive).static final floatrandom(float start, float end) Returns a random number between start (inclusive) and end (exclusive).static final intrandom(int range) Returns a random number between 0 (inclusive) and the specified value (inclusive).static final intrandom(int start, int end) Returns a random number between start (inclusive) and end (inclusive).static final booleanReturns a random boolean value.static intround(float x) Returns the closest integer to the specified float.static introundPositive(float x) Returns the closest integer to the specified float.static final floatsin(float radians) Returns the sine in radians.static final floatsinDeg(float degrees) Returns the sine in radians.
-
Field Details
-
nanoToSec
public static final float nanoToSec- See Also:
-
PI
public static final float PI- See Also:
-
PI2
public static final float PI2- See Also:
-
radiansToDegrees
public static final float radiansToDegrees- See Also:
-
radDeg
public static final float radDeg- See Also:
-
degreesToRadians
public static final float degreesToRadians- See Also:
-
degRad
public static final float degRad- See Also:
-
random
-
-
Constructor Details
-
MathUtils
public MathUtils()
-
-
Method Details
-
sin
public static final float sin(float radians) Returns the sine in radians. -
cos
public static final float cos(float radians) Returns the cosine in radians. -
sinDeg
public static final float sinDeg(float degrees) Returns the sine in radians. -
cosDeg
public static final float cosDeg(float degrees) Returns the cosine in radians. -
atan2
public static final float atan2(float y, float x) Returns atan2 in radians from a lookup table. -
random
public static final int random(int range) Returns a random number between 0 (inclusive) and the specified value (inclusive). -
random
public static final int random(int start, int end) Returns a random number between start (inclusive) and end (inclusive). -
randomBoolean
public static final boolean randomBoolean()Returns a random boolean value. -
random
public static final float random()Returns random number between 0.0 (inclusive) and 1.0 (exclusive). -
random
public static final float random(float range) Returns a random number between 0 (inclusive) and the specified value (exclusive). -
random
public static final float random(float start, float end) Returns a random number between start (inclusive) and end (exclusive). -
nextPowerOfTwo
public static int nextPowerOfTwo(int value) Returns the next power of two. Returns the specified value if the value is already a power of two. -
isPowerOfTwo
public static boolean isPowerOfTwo(int value) -
clamp
public static int clamp(int value, int min, int max) -
clamp
public static short clamp(short value, short min, short max) -
clamp
public static float clamp(float value, float min, float max) -
floor
public static int floor(float x) Returns the largest integer less than or equal to the specified float. This method will only properly floor floats from -(2^14) to (Float.MAX_VALUE - 2^14). -
floorPositive
public static int floorPositive(float x) Returns the largest integer less than or equal to the specified float. This method will only properly floor floats that are positive. Note this method simply casts the float to int. -
ceil
public static int ceil(float x) Returns the smallest integer greater than or equal to the specified float. This method will only properly ceil floats from -(2^14) to (Float.MAX_VALUE - 2^14). -
ceilPositive
public static int ceilPositive(float x) Returns the smallest integer greater than or equal to the specified float. This method will only properly ceil floats that are positive. -
round
public static int round(float x) Returns the closest integer to the specified float. This method will only properly round floats from -(2^14) to (Float.MAX_VALUE - 2^14). -
roundPositive
public static int roundPositive(float x) Returns the closest integer to the specified float. This method will only properly round floats that are positive.
-