- java.lang.Object
-
- eu.ess.xaos.core.util.MathUtils
-
public class MathUtils extends Object
Miscellaneous mathematical utility functions.- Author:
- claudio.rosati@esss.se
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static double
clamp(double value, double extrema1, double extrema2)
Returnsvalue
if it included inside the range made of the twoextrema
parameters, otherwise returns the range's minimum ifvalue
is lower than it, or the range's maximum.static float
clamp(float value, float extrema1, float extrema2)
Returnsvalue
if it included inside the range made of the twoextrema
parameters, otherwise returns the range's minimum ifvalue
is lower than it, or the range's maximum.static int
clamp(int value, int extrema1, int extrema2)
Returnsvalue
if it included inside the range made of the twoextrema
parameters, otherwise returns the range's minimum ifvalue
is lower than it, or the range's maximum.static long
clamp(long value, long extrema1, long extrema2)
Returnsvalue
if it included inside the range made of the twoextrema
parameters, otherwise returns the range's minimum ifvalue
is lower than it, or the range's maximum.static boolean
inside(double value, double extrema1, double extrema2)
Check if the givenvalue
is inside the range made of the twoextrema
parameters,static boolean
inside(float value, float extrema1, float extrema2)
Check if the givenvalue
is inside the range made of the twoextrema
parameters,static boolean
inside(int value, int extrema1, int extrema2)
Check if the givenvalue
is inside the range made of the twoextrema
parameters,static boolean
inside(long value, long extrema1, long extrema2)
Check if the givenvalue
is inside the range made of the twoextrema
parameters,static boolean
outside(double value, double extrema1, double extrema2)
Check if the givenvalue
is outside the range made of the twoextrema
parameters,static boolean
outside(float value, float extrema1, float extrema2)
Check if the givenvalue
is outside the range made of the twoextrema
parameters,static boolean
outside(int value, int extrema1, int extrema2)
Check if the givenvalue
is outside the range made of the twoextrema
parameters,static boolean
outside(long value, long extrema1, long extrema2)
Check if the givenvalue
is outside the range made of the twoextrema
parameters,static double
proportion(double x, double x0, double x1, double y0, double y1)
Computesstatic float
proportion(float x, float x0, float x1, float y0, float y1)
Computesstatic boolean
strictlyInside(double value, double extrema1, double extrema2)
Check if the givenvalue
is strictly inside the range made of the twoextrema
parameters,static boolean
strictlyInside(float value, float extrema1, float extrema2)
Check if the givenvalue
is strictly inside the range made of the twoextrema
parameters,static boolean
strictlyInside(int value, int extrema1, int extrema2)
Check if the givenvalue
is strictly inside the range made of the twoextrema
parameters,static boolean
strictlyInside(long value, long extrema1, long extrema2)
Check if the givenvalue
is strictly inside the range made of the twoextrema
parameters,
-
-
-
Method Detail
-
clamp
public static int clamp(int value, int extrema1, int extrema2)
Returnsvalue
if it included inside the range made of the twoextrema
parameters, otherwise returns the range's minimum ifvalue
is lower than it, or the range's maximum.- Parameters:
value
- The value to be returned if inside the given range, or clamped.extrema1
- One of the two extrema defining the value's validity range.extrema2
- The other extrema defining the value's validity range.- Returns:
value
if inside the specified range, or one of the range's extrema.
-
clamp
public static long clamp(long value, long extrema1, long extrema2)
Returnsvalue
if it included inside the range made of the twoextrema
parameters, otherwise returns the range's minimum ifvalue
is lower than it, or the range's maximum.- Parameters:
value
- The value to be returned if inside the given range, or clamped.extrema1
- One of the two extrema defining the value's validity range.extrema2
- The other extrema defining the value's validity range.- Returns:
value
if inside the specified range, or one of the range's extrema.
-
clamp
public static float clamp(float value, float extrema1, float extrema2)
Returnsvalue
if it included inside the range made of the twoextrema
parameters, otherwise returns the range's minimum ifvalue
is lower than it, or the range's maximum.- Parameters:
value
- The value to be returned if inside the given range, or clamped.extrema1
- One of the two extrema defining the value's validity range.extrema2
- The other extrema defining the value's validity range.- Returns:
value
if inside the specified range, or one of the range's extrema.
-
clamp
public static double clamp(double value, double extrema1, double extrema2)
Returnsvalue
if it included inside the range made of the twoextrema
parameters, otherwise returns the range's minimum ifvalue
is lower than it, or the range's maximum.- Parameters:
value
- The value to be returned if inside the given range, or clamped.extrema1
- One of the two extrema defining the value's validity range.extrema2
- The other extrema defining the value's validity range.- Returns:
value
if inside the specified range, or one of the range's extrema.
-
inside
public static boolean inside(int value, int extrema1, int extrema2)
Check if the givenvalue
is inside the range made of the twoextrema
parameters,- Parameters:
value
- The number to be checked.extrema1
- One of the two extrema defining the value's validity range.extrema2
- The other extrema defining the value's validity range.- Returns:
value >= min(extrema1, extrema2) && value <= max(extrema1, extrema2)
,
-
inside
public static boolean inside(long value, long extrema1, long extrema2)
Check if the givenvalue
is inside the range made of the twoextrema
parameters,- Parameters:
value
- The number to be checked.extrema1
- One of the two extrema defining the value's validity range.extrema2
- The other extrema defining the value's validity range.- Returns:
value >= min(extrema1, extrema2) && value <= max(extrema1, extrema2)
,
-
inside
public static boolean inside(float value, float extrema1, float extrema2)
Check if the givenvalue
is inside the range made of the twoextrema
parameters,- Parameters:
value
- The number to be checked.extrema1
- One of the two extrema defining the value's validity range.extrema2
- The other extrema defining the value's validity range.- Returns:
value >= min(extrema1, extrema2) && value <= max(extrema1, extrema2)
,
-
inside
public static boolean inside(double value, double extrema1, double extrema2)
Check if the givenvalue
is inside the range made of the twoextrema
parameters,- Parameters:
value
- The number to be checked.extrema1
- One of the two extrema defining the value's validity range.extrema2
- The other extrema defining the value's validity range.- Returns:
value >= min(extrema1, extrema2) && value <= max(extrema1, extrema2)
,
-
outside
public static boolean outside(int value, int extrema1, int extrema2)
Check if the givenvalue
is outside the range made of the twoextrema
parameters,- Parameters:
value
- The number to be checked.extrema1
- One of the two extrema defining the value's validity range.extrema2
- The other extrema defining the value's validity range.- Returns:
value < min(extrema1, extrema2) || value > max(extrema1, extrema2)
,
-
outside
public static boolean outside(long value, long extrema1, long extrema2)
Check if the givenvalue
is outside the range made of the twoextrema
parameters,- Parameters:
value
- The number to be checked.extrema1
- One of the two extrema defining the value's validity range.extrema2
- The other extrema defining the value's validity range.- Returns:
value < min(extrema1, extrema2) || value > max(extrema1, extrema2)
,
-
outside
public static boolean outside(float value, float extrema1, float extrema2)
Check if the givenvalue
is outside the range made of the twoextrema
parameters,- Parameters:
value
- The number to be checked.extrema1
- One of the two extrema defining the value's validity range.extrema2
- The other extrema defining the value's validity range.- Returns:
value < min(extrema1, extrema2) || value > max(extrema1, extrema2)
,
-
outside
public static boolean outside(double value, double extrema1, double extrema2)
Check if the givenvalue
is outside the range made of the twoextrema
parameters,- Parameters:
value
- The number to be checked.extrema1
- One of the two extrema defining the value's validity range.extrema2
- The other extrema defining the value's validity range.- Returns:
value < min(extrema1, extrema2) || value > max(extrema1, extrema2)
,
-
proportion
public static float proportion(float x, float x0, float x1, float y0, float y1)
Computesy1 - y0 y = (x - x0) * ------- + y0 x1 - x0
If
x1 == x0
then(y1 + y0) / 2
will be returned.- Parameters:
x
- The value for which a proportion must be computed.x0
- The first sample of x.x1
- The second sample of x.y0
- The first sample of y.y1
- The second sample of y.- Returns:
- The computed proportion.
-
proportion
public static double proportion(double x, double x0, double x1, double y0, double y1)
Computesy1 - y0 y = (x - x0) * ------- + y0 x1 - x0
If
x1 == x0
then(y1 + y0) / 2
will be returned.- Parameters:
x
- The value for which a proportion must be computed.x0
- The first sample of x.x1
- The second sample of x.y0
- The first sample of y.y1
- The second sample of y.- Returns:
- The computed proportion.
-
strictlyInside
public static boolean strictlyInside(int value, int extrema1, int extrema2)
Check if the givenvalue
is strictly inside the range made of the twoextrema
parameters,- Parameters:
value
- The number to be checked.extrema1
- One of the two extrema defining the value's validity range.extrema2
- The other extrema defining the value's validity range.- Returns:
value > min(extrema1, extrema2) && value < max(extrema1, extrema2)
,
-
strictlyInside
public static boolean strictlyInside(long value, long extrema1, long extrema2)
Check if the givenvalue
is strictly inside the range made of the twoextrema
parameters,- Parameters:
value
- The number to be checked.extrema1
- One of the two extrema defining the value's validity range.extrema2
- The other extrema defining the value's validity range.- Returns:
value > min(extrema1, extrema2) && value < max(extrema1, extrema2)
,
-
strictlyInside
public static boolean strictlyInside(float value, float extrema1, float extrema2)
Check if the givenvalue
is strictly inside the range made of the twoextrema
parameters,- Parameters:
value
- The number to be checked.extrema1
- One of the two extrema defining the value's validity range.extrema2
- The other extrema defining the value's validity range.- Returns:
value > min(extrema1, extrema2) && value < max(extrema1, extrema2)
,
-
strictlyInside
public static boolean strictlyInside(double value, double extrema1, double extrema2)
Check if the givenvalue
is strictly inside the range made of the twoextrema
parameters,- Parameters:
value
- The number to be checked.extrema1
- One of the two extrema defining the value's validity range.extrema2
- The other extrema defining the value's validity range.- Returns:
value > min(extrema1, extrema2) && value < max(extrema1, extrema2)
,
-
-