public final class MathUtils extends Object
Modifier and Type | Field and Description |
---|---|
static double |
EPSILON
Precision for floating point numbers; used to decide equality.
|
Modifier and Type | Method and Description |
---|---|
static double |
findMax(double[] a)
Find the maximum in a double array.
|
static double |
findMin(double[] a)
Find the minimum in a double array.
|
static boolean |
isAlmostEqual(double x,
double y)
Are two doubles equal?
|
static boolean |
isAlmostZero(double x)
Is a double zero?
|
static boolean |
isBetween(double value,
double min,
double max)
Is a value between two limits?
|
static boolean |
isBetween(int value,
int min,
int max)
Is a value between two limits?
|
static double |
limitTo(double value,
double min,
double max)
Limit a value to 2 boundaries.
|
static int |
limitTo(int value,
int min,
int max)
Limit a value to 2 boundaries.
|
static int |
random(int min,
int max)
Produce a random number between [min..max] (inclusive).
|
static void |
setRandomSeed(long seed)
Set the randomizer seed.
|
static double |
wrapValueToWithinLimits(double value,
int limit)
Map a value to [-limit, limit).
|
public static final double EPSILON
public static double findMin(@Nonnull double[] a)
a
- An array of doubles.public static double findMax(@Nonnull double[] a)
a
- An array of doubles.public static boolean isAlmostZero(double x)
x
- The double to be tested.public static boolean isAlmostEqual(double x, double y)
x
- One double.y
- The other double.public static boolean isBetween(int value, int min, int max)
value
- Value to check.min
- Minimum. Must be <= max.max
- Maximum.public static boolean isBetween(double value, double min, double max)
value
- Value to check.min
- Minimum. Must be <= max.max
- Maximum.public static int limitTo(int value, int min, int max)
value
- Value to limit.min
- Minimum (inclusive). Must be <= max.max
- Maximum (inclusive).public static double limitTo(double value, double min, double max)
value
- Value to limit.min
- Minimum (inclusive). Must be <= max.max
- Maximum (inclusive).public static int random(int min, int max)
min
- Minimum (inclusive). Must be <= max.max
- Maximum (inclusive).public static void setRandomSeed(long seed)
seed
- Seed.public static double wrapValueToWithinLimits(double value, int limit)
value
- Any value.Copyright © 2018 TomTom International BV. All rights reserved.