- 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 doubleclamp(double value, double extrema1, double extrema2)Returnsvalueif it included inside the range made of the twoextremaparameters, otherwise returns the range's minimum ifvalueis lower than it, or the range's maximum.static floatclamp(float value, float extrema1, float extrema2)Returnsvalueif it included inside the range made of the twoextremaparameters, otherwise returns the range's minimum ifvalueis lower than it, or the range's maximum.static intclamp(int value, int extrema1, int extrema2)Returnsvalueif it included inside the range made of the twoextremaparameters, otherwise returns the range's minimum ifvalueis lower than it, or the range's maximum.static longclamp(long value, long extrema1, long extrema2)Returnsvalueif it included inside the range made of the twoextremaparameters, otherwise returns the range's minimum ifvalueis lower than it, or the range's maximum.static booleaninside(double value, double extrema1, double extrema2)Check if the givenvalueis inside the range made of the twoextremaparameters,static booleaninside(float value, float extrema1, float extrema2)Check if the givenvalueis inside the range made of the twoextremaparameters,static booleaninside(int value, int extrema1, int extrema2)Check if the givenvalueis inside the range made of the twoextremaparameters,static booleaninside(long value, long extrema1, long extrema2)Check if the givenvalueis inside the range made of the twoextremaparameters,static booleanoutside(double value, double extrema1, double extrema2)Check if the givenvalueis outside the range made of the twoextremaparameters,static booleanoutside(float value, float extrema1, float extrema2)Check if the givenvalueis outside the range made of the twoextremaparameters,static booleanoutside(int value, int extrema1, int extrema2)Check if the givenvalueis outside the range made of the twoextremaparameters,static booleanoutside(long value, long extrema1, long extrema2)Check if the givenvalueis outside the range made of the twoextremaparameters,static doubleproportion(double x, double x0, double x1, double y0, double y1)Computesstatic floatproportion(float x, float x0, float x1, float y0, float y1)Computesstatic booleanstrictlyInside(double value, double extrema1, double extrema2)Check if the givenvalueis strictly inside the range made of the twoextremaparameters,static booleanstrictlyInside(float value, float extrema1, float extrema2)Check if the givenvalueis strictly inside the range made of the twoextremaparameters,static booleanstrictlyInside(int value, int extrema1, int extrema2)Check if the givenvalueis strictly inside the range made of the twoextremaparameters,static booleanstrictlyInside(long value, long extrema1, long extrema2)Check if the givenvalueis strictly inside the range made of the twoextremaparameters,
-
-
-
Method Detail
-
clamp
public static int clamp(int value, int extrema1, int extrema2)Returnsvalueif it included inside the range made of the twoextremaparameters, otherwise returns the range's minimum ifvalueis 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:
valueif inside the specified range, or one of the range's extrema.
-
clamp
public static long clamp(long value, long extrema1, long extrema2)Returnsvalueif it included inside the range made of the twoextremaparameters, otherwise returns the range's minimum ifvalueis 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:
valueif inside the specified range, or one of the range's extrema.
-
clamp
public static float clamp(float value, float extrema1, float extrema2)Returnsvalueif it included inside the range made of the twoextremaparameters, otherwise returns the range's minimum ifvalueis 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:
valueif inside the specified range, or one of the range's extrema.
-
clamp
public static double clamp(double value, double extrema1, double extrema2)Returnsvalueif it included inside the range made of the twoextremaparameters, otherwise returns the range's minimum ifvalueis 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:
valueif 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 givenvalueis inside the range made of the twoextremaparameters,- 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 givenvalueis inside the range made of the twoextremaparameters,- 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 givenvalueis inside the range made of the twoextremaparameters,- 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 givenvalueis inside the range made of the twoextremaparameters,- 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 givenvalueis outside the range made of the twoextremaparameters,- 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 givenvalueis outside the range made of the twoextremaparameters,- 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 givenvalueis outside the range made of the twoextremaparameters,- 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 givenvalueis outside the range made of the twoextremaparameters,- 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 - x0If
x1 == x0then(y1 + y0) / 2will 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 - x0If
x1 == x0then(y1 + y0) / 2will 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 givenvalueis strictly inside the range made of the twoextremaparameters,- 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 givenvalueis strictly inside the range made of the twoextremaparameters,- 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 givenvalueis strictly inside the range made of the twoextremaparameters,- 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 givenvalueis strictly inside the range made of the twoextremaparameters,- 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),
-
-