Class MathUtil
Various utility functions for mathematical and numerical operations.
Inherited Members
Namespace: NetTopologySuite.Mathematics
Assembly: NetTopologySuite.dll
Syntax
public class MathUtil
Fields
| Improve this Doc View SourcePhiInv
The inverse of the Golden Ratio phi.
Declaration
public static readonly double PhiInv
Field Value
Type | Description |
---|---|
Double |
Methods
| Improve this Doc View SourceAverage(Double, Double)
Computes the average of two numbers.
Declaration
public static double Average(double x1, double x2)
Parameters
Type | Name | Description |
---|---|---|
Double | x1 | A number |
Double | x2 | A number |
Returns
Type | Description |
---|---|
Double | The average of the inputs |
Ceiling(Int32, Int32)
Computes the ceiling function of the dividend of two integers.
Declaration
public static int Ceiling(int num, int denom)
Parameters
Type | Name | Description |
---|---|---|
Int32 | num | The numerator |
Int32 | denom | The denominator |
Returns
Type | Description |
---|---|
Int32 | The ceiling of |
Clamp(Double, Double, Double)
Clamps a double
value to a given range.
Declaration
public static double Clamp(double x, double min, double max)
Parameters
Type | Name | Description |
---|---|---|
Double | x | The value to clamp |
Double | min | The minimum value of the range |
Double | max | The maximum value of the range |
Returns
Type | Description |
---|---|
Double | The clamped value |
Clamp(Int32, Int32, Int32)
Clamps a int
value to a given range.
Declaration
public static int Clamp(int x, int min, int max)
Parameters
Type | Name | Description |
---|---|---|
Int32 | x | The value to clamp |
Int32 | min | The minimum value of the range |
Int32 | max | The maximum value of the range |
Returns
Type | Description |
---|---|
Int32 | The clamped value |
ClampMax(Int32, Int32)
Clamps an integer to a given maximum limit.
Declaration
public static int ClampMax(int x, int max)
Parameters
Type | Name | Description |
---|---|---|
Int32 | x | The value to clamp |
Int32 | max | The maximum value of the range |
Returns
Type | Description |
---|---|
Int32 | 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.
Declaration
public static double Log10(double x)
Parameters
Type | Name | Description |
---|---|---|
Double | x | A positive number |
Returns
Type | Description |
---|---|
Double | The value log a, the base-10 logarithm of the input value |
Max(Double, Double, Double)
Computes the maximum fo three values
Declaration
public static double Max(double v1, double v2, double v3)
Parameters
Type | Name | Description |
---|---|---|
Double | v1 | A number |
Double | v2 | A number |
Double | v3 | A number |
Returns
Type | Description |
---|---|
Double | The maximum value of |
Max(Double, Double, Double, Double)
Computes the maximum of four values
Declaration
public static double Max(double v1, double v2, double v3, double v4)
Parameters
Type | Name | Description |
---|---|---|
Double | v1 | A number |
Double | v2 | A number |
Double | v3 | A number |
Double | v4 | A number |
Returns
Type | Description |
---|---|
Double | The maximum value of |
Min(Double, Double, Double)
Computes the minimum of four values
Declaration
public static double Min(double v1, double v2, double v3)
Parameters
Type | Name | Description |
---|---|---|
Double | v1 | A number |
Double | v2 | A number |
Double | v3 | A number |
Returns
Type | Description |
---|---|
Double | The minimum value of |
Min(Double, Double, Double, Double)
Computes the minimum of four values
Declaration
public static double Min(double v1, double v2, double v3, double v4)
Parameters
Type | Name | Description |
---|---|---|
Double | v1 | A number |
Double | v2 | A number |
Double | v3 | A number |
Double | v4 | A number |
Returns
Type | Description |
---|---|
Double | The minimum value of |
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.
Declaration
public static double QuasiRandom(double curr)
Parameters
Type | Name | Description |
---|---|---|
Double | curr | The current number in the sequence |
Returns
Type | Description |
---|---|
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.
Declaration
public static double QuasiRandom(double curr, double alpha)
Parameters
Type | Name | Description |
---|---|---|
Double | curr | The current number in the sequence |
Double | alpha | the sequence's additive constant |
Returns
Type | Description |
---|---|
Double | The next value in the sequence |
Wrap(Int32, Int32)
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
Declaration
public static int Wrap(int index, int max)
Parameters
Type | Name | Description |
---|---|---|
Int32 | index | The index to wrap |
Int32 | max | The maximum value (or modulus) |
Returns
Type | Description |
---|---|
Int32 | The wrapped index |