Class MathUtil
- Namespace
- NetTopologySuite.Mathematics
- Assembly
- NetTopologySuite.dll
Various utility functions for mathematical and numerical operations.
public class MathUtil
- Inheritance
-
MathUtil
- Inherited Members
Constructors
MathUtil()
public MathUtil()
Fields
PhiInv
The inverse of the Golden Ratio phi.
public static readonly double PhiInv
Field Value
Methods
Average(double, double)
Computes the average of two numbers.
public static double Average(double x1, double x2)
Parameters
Returns
- double
The average of the inputs
Ceiling(int, int)
Computes the ceiling function of the dividend of two integers.
public static int Ceiling(int num, int denom)
Parameters
Returns
- int
The ceiling of
num / denom
Clamp(double, double, double)
Clamps a double
value to a given range.
public static double Clamp(double x, double min, double max)
Parameters
x
doubleThe value to clamp
min
doubleThe minimum value of the range
max
doubleThe maximum value of the range
Returns
- double
The clamped value
Clamp(int, int, int)
Clamps a int
value to a given range.
public static int Clamp(int x, int min, int max)
Parameters
x
intThe value to clamp
min
intThe minimum value of the range
max
intThe maximum value of the range
Returns
- int
The clamped value
ClampMax(int, int)
Clamps an integer to a given maximum limit.
public static int ClampMax(int x, int max)
Parameters
Returns
- int
The clamped value
Log10(double)
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.
public static double Log10(double x)
Parameters
x
doubleA positive number
Returns
- double
The value log a, the base-10 logarithm of the input value
Max(double, double, double)
Computes the maximum fo three values
public static double Max(double v1, double v2, double v3)
Parameters
Returns
- double
The maximum value of
v1
,v2
andv3
Max(double, double, double, double)
Computes the maximum of four values
public static double Max(double v1, double v2, double v3, double v4)
Parameters
Returns
- double
The maximum value of
v1
,v2
,v3
andv4
Min(double, double, double)
Computes the minimum of four values
public static double Min(double v1, double v2, double v3)
Parameters
Returns
- double
The minimum value of
v1
,v2
andv3
Min(double, double, double, double)
Computes the minimum of four values
public static double Min(double v1, double v2, double v3, double v4)
Parameters
Returns
- double
The minimum value of
v1
,v2
,v3
andv4
QuasiRandom(double)
Generates a quasi-random sequence of numbers in the range [0,1]. They are produced by an additive recurrence with 1/φ as the constant. This produces a low-discrepancy sequence which is more evenly distribute than random numbers.
See Wikipedia: Low-discrepancy Sequences - Additive Recurrence. The sequence is initialized by calling it with any positive fractional number; 0 works well for most uses.public static double QuasiRandom(double curr)
Parameters
curr
doubleThe current number in the sequence
Returns
- double
The next value in the sequence
QuasiRandom(double, double)
Generates a quasi-random sequence of numbers in the range [0,1]. They are produced by an additive recurrence with constant α.
R(α) : tn = { t0 + nα }, n = 1,2,3,...
When α is irrational this produces a Low discrepancy sequence which is more evenly distributed than random numbers.
The sequence is initialized by calling it with any positive fractional number. 0 works well for most uses.public static double QuasiRandom(double curr, double alpha)
Parameters
Returns
- double
The next value in the sequence
Wrap(int, int)
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
public static int Wrap(int index, int max)
Parameters
Returns
- int
The wrapped index