Package org.locationtech.jts.math
Class MathUtil
- java.lang.Object
-
- org.locationtech.jts.math.MathUtil
-
public class MathUtil extends java.lang.Object
Various utility functions for mathematical and numerical operations.- Author:
- mbdavis
-
-
Constructor Summary
Constructors Constructor Description MathUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static double
average(double x1, double x2)
Computes the average of two numbers.static double
clamp(double x, double min, double max)
Clamps a double value to a given range.static int
clamp(int x, int min, int max)
Clamps an int value to a given range.static double
log10(double x)
Computes the base-10 logarithm of a double value.static double
max(double v1, double v2, double v3)
static double
max(double v1, double v2, double v3, double v4)
static double
min(double v1, double v2, double v3, double v4)
static int
wrap(int index, int max)
Computes an index which wraps around a given maximum value.
-
-
-
Method Detail
-
clamp
public static double clamp(double x, double min, double max)
Clamps a double value to a given range.- Parameters:
x
- the value to clampmin
- the minimum value of the rangemax
- the maximum value of the range- Returns:
- the clamped value
-
clamp
public static int clamp(int x, int min, int max)
Clamps an int value to a given range.- Parameters:
x
- the value to clampmin
- the minimum value of the rangemax
- the maximum value of the range- Returns:
- the clamped value
-
log10
public static double log10(double x)
Computes the base-10 logarithm of a double value.- If the argument is NaN or less than zero, then the result is NaN.
- If the argument is positive infinity, then the result is positive infinity.
- If the argument is positive zero or negative zero, then the result is negative infinity.
- Parameters:
x
- a positive number- Returns:
- the value log a, the base-10 logarithm of the input value
-
wrap
public static int wrap(int index, int max)
Computes an index which wraps around a given maximum value. For values >= 0, this is equals to val % max. For values < 0, this is equal to max - (-val) % max- Parameters:
index
- the value to wrapmax
- the maximum value (or modulus)- Returns:
- the wrapped index
-
average
public static double average(double x1, double x2)
Computes the average of two numbers.- Parameters:
x1
- a numberx2
- a number- Returns:
- the average of the inputs
-
max
public static double max(double v1, double v2, double v3)
-
max
public static double max(double v1, double v2, double v3, double v4)
-
min
public static double min(double v1, double v2, double v3, double v4)
-
-