MathUtils
public
class
MathUtils
extends Object
java.lang.Object
|
↳ |
androidx.core.math.MathUtils
|
A utility class providing functions useful for common mathematical operations.
Summary
Public methods |
static
double
|
clamp(double value, double min, double max)
This method takes a numerical value and ensures it fits in a given numerical range.
|
static
long
|
clamp(long value, long min, long max)
This method takes a numerical value and ensures it fits in a given numerical range.
|
static
float
|
clamp(float value, float min, float max)
This method takes a numerical value and ensures it fits in a given numerical range.
|
static
int
|
clamp(int value, int min, int max)
This method takes a numerical value and ensures it fits in a given numerical range.
|
Inherited methods |
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
Public methods
clamp
public static double clamp (double value,
double min,
double max)
This method takes a numerical value and ensures it fits in a given numerical range. If the
number is smaller than the minimum required by the range, then the minimum of the range will
be returned. If the number is higher than the maximum allowed by the range then the maximum
of the range will be returned.
Parameters |
value |
double : the value to be clamped. |
min |
double : minimum resulting value. |
max |
double : maximum resulting value. |
Returns |
double |
the clamped value.
|
clamp
public static long clamp (long value,
long min,
long max)
This method takes a numerical value and ensures it fits in a given numerical range. If the
number is smaller than the minimum required by the range, then the minimum of the range will
be returned. If the number is higher than the maximum allowed by the range then the maximum
of the range will be returned.
Parameters |
value |
long : the value to be clamped. |
min |
long : minimum resulting value. |
max |
long : maximum resulting value. |
Returns |
long |
the clamped value.
|
clamp
public static float clamp (float value,
float min,
float max)
This method takes a numerical value and ensures it fits in a given numerical range. If the
number is smaller than the minimum required by the range, then the minimum of the range will
be returned. If the number is higher than the maximum allowed by the range then the maximum
of the range will be returned.
Parameters |
value |
float : the value to be clamped. |
min |
float : minimum resulting value. |
max |
float : maximum resulting value. |
Returns |
float |
the clamped value.
|
clamp
public static int clamp (int value,
int min,
int max)
This method takes a numerical value and ensures it fits in a given numerical range. If the
number is smaller than the minimum required by the range, then the minimum of the range will
be returned. If the number is higher than the maximum allowed by the range then the maximum
of the range will be returned.
Parameters |
value |
int : the value to be clamped. |
min |
int : minimum resulting value. |
max |
int : maximum resulting value. |
Returns |
int |
the clamped value.
|