MathUtil { static public short clamp(short value, short min, short max) { if (value < min) { return min; } if (value > max) { return max; } return value; }  static float sin(float radians); static float cos(float radians); static float roundFloat(float value); static float sinDeg(float degrees); static float cosDeg(float degrees); static float atan2(float y, float x); static int random(int range); static int floatToRawIntBits(float value); static int floatToIntBits(float value); static int random(int start, int end); static long random(long range); static long random(long start, long end); static Vector3 random(Vector3 start, Vector3 end); static boolean randomBoolean(); static boolean randomBoolean(float chance); static boolean randomBoolean(int probability, int bound); static boolean randomBoolean(int probability); static T random(Collection<T> collection); static List<T> randomList(Collection<T> collection, int num); static void randomIndex(List<T> list); static T randomRemove(Collection<T> collection); static float random(); static float random(float range); static float random(float start, float end); static int randomSign(); static float randomTriangular(); static float randomTriangular(float max); static float randomTriangular(float min, float max); static float randomTriangular(float min, float max, float mode); static int nextPowerOfTwo(int value); static boolean isPowerOfTwo(int value); static short clamp(short value, short min, short max); static int clamp(int value, int min, int max); static long clamp(long value, long min, long max); static float clamp(float value, float min, float max); static double clamp(double value, double min, double max); static float lerp(float fromValue, float toValue, float progress); static float lerpAngle(float fromRadians, float toRadians, float progress); static float lerpAngleDeg(float fromDegrees, float toDegrees, float progress); static int floor(float value); static int floorPositive(float value); static int ceil(float value); static int ceilPositive(float value); static int round(float value); static int roundPositive(float value); static boolean isZero(float value); static boolean isZero(float value, float tolerance); static boolean isEqual(float a, float b); static boolean isEqual(float a, float b, float tolerance); static float log(float a, float value); static float log2(float value); static final float nanoToSec; static final float FLOAT_ROUNDING_ERROR; static final int FLOAT_ROUND; static final float PI; static final float PI2; static final float E; static final float radiansToDegrees; static final float radDeg; static final float degreesToRadians; static final float degRad; static public Random random; }
@Test public void testClampShort() { Assert.assertEquals((short) 5, MathUtil.clamp((short) 20, (short) 1, (short) 5)); Assert.assertEquals((short) 2, MathUtil.clamp((short) -6, (short) 2, (short) 8)); Assert.assertEquals((short) 4, MathUtil.clamp((short) 4, (short) -7, (short) 19)); Assert.assertEquals((short) 3, MathUtil.clamp((short) 3, (short) 3, (short) 6)); Assert.assertEquals((short) 12, MathUtil.clamp((short) 12, (short) 9, (short) 12)); }
@Test public void testClampInt() { Assert.assertEquals(5, MathUtil.clamp(20, 1, 5)); Assert.assertEquals(2, MathUtil.clamp(-6, 2, 8)); Assert.assertEquals(4, MathUtil.clamp(4, -7, 19)); Assert.assertEquals(3, MathUtil.clamp(3, 3, 6)); Assert.assertEquals(12, MathUtil.clamp(12, 9, 12)); }
@Test public void testClampFloat() { Assert.assertEquals(5.1f, MathUtil.clamp(20.6f, 1.8f, 5.1f), 0); Assert.assertEquals(2.2f, MathUtil.clamp(-6.1f, 2.2f, 8.3f), 0); Assert.assertEquals(4.3f, MathUtil.clamp(4.3f, -7.1f, 19.7f), 0); Assert.assertEquals(3.4f, MathUtil.clamp(3.4f, 3.4f, 6.8f), 0); Assert.assertEquals(12.5f, MathUtil.clamp(12.5f, 9.3f, 12.5f), 0); }
@Test public void testClampDouble() { Assert.assertEquals(5.1d, MathUtil.clamp(20.6d, 1.8d, 5.1d), 0); Assert.assertEquals(2.2d, MathUtil.clamp(-6.1d, 2.2d, 8.3d), 0); Assert.assertEquals(4.3d, MathUtil.clamp(4.3d, -7.1d, 19.7d), 0); Assert.assertEquals(3.4d, MathUtil.clamp(3.4d, 3.4d, 6.8d), 0); Assert.assertEquals(12.5d, MathUtil.clamp(12.5d, 9.3d, 12.5d), 0); }
@Test public void testClampLong() { Assert.assertEquals(5L, MathUtil.clamp(20L, 1L, 5)); Assert.assertEquals(2L, MathUtil.clamp(-6L, 2L, 8)); Assert.assertEquals(4L, MathUtil.clamp(4L, -7L, 19)); Assert.assertEquals(3L, MathUtil.clamp(3L, 3L, 6)); Assert.assertEquals(12L, MathUtil.clamp(12L, 9L, 12)); }