libgdx API

com.badlogic.gdx.math
Class MathUtils

java.lang.Object
  extended by com.badlogic.gdx.math.MathUtils

public class MathUtils
extends java.lang.Object

Utility and fast math functions.

Thanks to Riven on JavaGaming.org for sin/cos/atan2/floor/ceil.


Field Summary
static float[] cos
           
static float degreesToRadians
           
static float PI
           
static float radiansToDegrees
           
static java.util.Random random
           
static float[] sin
           
 
Constructor Summary
MathUtils()
           
 
Method Summary
static float atan2(float y, float x)
           
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 rad)
           
static float cosDeg(float deg)
           
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 isPowerOfTwo(int value)
           
static int nextPowerOfTwo(int value)
           
static float random()
           
static float random(float range)
          Returns a random number between 0 (inclusive) and the specified value (inclusive).
static float random(float start, float end)
          Returns a random number between start (inclusive) and end (inclusive).
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()
           
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 rad)
           
static float sinDeg(float deg)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PI

public static final float PI
See Also:
Constant Field Values

radiansToDegrees

public static final float radiansToDegrees
See Also:
Constant Field Values

degreesToRadians

public static final float degreesToRadians
See Also:
Constant Field Values

sin

public static final float[] sin

cos

public static final float[] cos

random

public static java.util.Random random
Constructor Detail

MathUtils

public MathUtils()
Method Detail

sin

public static final float sin(float rad)

cos

public static final float cos(float rad)

sinDeg

public static final float sinDeg(float deg)

cosDeg

public static final float cosDeg(float deg)

atan2

public static final float atan2(float y,
                                float x)

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()

random

public static final float random()

random

public static final float random(float range)
Returns a random number between 0 (inclusive) and the specified value (inclusive).


random

public static final float random(float start,
                                 float end)
Returns a random number between start (inclusive) and end (inclusive).


nextPowerOfTwo

public static int nextPowerOfTwo(int value)

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.


libgdx API

Copyright 2010 Mario Zechner (contact@badlogicgames.com), Nathan Sweet (admin@esotericsoftware.com)