Class PrecisionUtility
Functions for computing precision model scale factors that ensure robust geometry operations. In particular, these can be used to automatically determine appropriate scale factors for operations using limited-precision noding (such as OverlayNG).
WARNING: the inherentScale
and robustScale
functions can be very slow, due to the method used to determine
number of decimal places of a number.
These are not recommended for production use.
Inherited Members
Namespace: NetTopologySuite.Operation.OverlayNG
Assembly: NetTopologySuite.dll
Syntax
public static class PrecisionUtility
Fields
| Improve this Doc View SourceMAX_ROBUST_DP_DIGITS
A number of digits of precision which leaves some computational "headroom" to ensure robust evaluation of certain double-precision floating point geometric operations.
This value should be less than the maximum decimal precision of double-precision values (16).
Declaration
public static int MAX_ROBUST_DP_DIGITS
Field Value
Type | Description |
---|---|
Int32 |
Methods
| Improve this Doc View SourceInherentScale(Geometry)
Computes the inherent scale of a geometry. The inherent scale is the scale factor for rounding which preserves all digits of precision (significant digits) present in the geometry ordinates.
This is the maximum inherent scale of all ordinate values in the geometry.
WARNING: this is very slow.
Declaration
public static double InherentScale(Geometry geom)
Parameters
Type | Name | Description |
---|---|---|
Geometry | geom | A geometry |
Returns
Type | Description |
---|---|
Double | The inherent scale factor in the geometry's ordinates |
InherentScale(Geometry, Geometry)
Computes the inherent scale of two geometries. The inherent scale is the scale factor for rounding which preserves all digits of precision (significant digits) present in the geometry ordinates.
This is the maximum inherent scale of all ordinate values in the geometries.
Declaration
public static double InherentScale(Geometry a, Geometry b)
Parameters
Type | Name | Description |
---|---|---|
Geometry | a | A geometry |
Geometry | b | A geomety (which may be |
Returns
Type | Description |
---|---|
Double | The inherent scale factor in the geometries' ordinates |
InherentScale(Double)
Computes the inherent scale of a number. The inherent scale is the scale factor for rounding which preserves all digits of precision (significant digits) present in the numeric value. In other words, it is the scale factor which does not change the numeric value when rounded:
num = round( num, inherentScale(num) )
Declaration
public static double InherentScale(double value)
Parameters
Type | Name | Description |
---|---|---|
Double | value | A number |
Returns
Type | Description |
---|---|
Double | The inherent scale factor of the number |
RobustPM(Geometry)
Determines a precision model to use for robust overlay operations for one geometry. The precision scale factor is chosen to maximize output precision while avoiding round-off issues.
NOTE: this is a heuristic determination, so is not guaranteed to eliminate precision issues.
WARNING: this is very slow.
Declaration
public static PrecisionModel RobustPM(Geometry a)
Parameters
Type | Name | Description |
---|---|---|
Geometry | a | A geometry |
Returns
Type | Description |
---|---|
PrecisionModel | A suitable precision model for overlay |
RobustScale(Geometry)
Determines a scale factor which maximizes the digits of precision and is safe to use for overlay operations. The robust scale is the minimum of the inherent scale and the safe scale factors.
Declaration
public static double RobustScale(Geometry a)
Parameters
Type | Name | Description |
---|---|---|
Geometry | a | A geometry |
Returns
Type | Description |
---|---|
Double | A scale factor for use in overlay operations |
RobustScale(Geometry, Geometry)
Determines a scale factor which maximizes the digits of precision and is safe to use for overlay operations. The robust scale is the minimum of the inherent scale and the safe scale factors.
WARNING: this is very slow.
Declaration
public static double RobustScale(Geometry a, Geometry b)
Parameters
Type | Name | Description |
---|---|---|
Geometry | a | A geometry |
Geometry | b | A geometry |
Returns
Type | Description |
---|---|
Double | A scale factor for use in overlay operations |
SafeScale(Geometry)
Computes a safe scale factor for a geometry. A safe scale factor ensures that rounded number has no more than MAX_ROBUST_DP_DIGITS digits of precision.
Declaration
public static double SafeScale(Geometry geom)
Parameters
Type | Name | Description |
---|---|---|
Geometry | geom | A geometry. |
Returns
Type | Description |
---|---|
Double | A safe scale factor for the geometry ordinates |
SafeScale(Geometry, Geometry)
Computes a safe scale factor for two geometry. A safe scale factor ensures that rounded number has no more than MAX_ROBUST_DP_DIGITS digits of precision.
Declaration
public static double SafeScale(Geometry a, Geometry b)
Parameters
Type | Name | Description |
---|---|---|
Geometry | a | A geometry. |
Geometry | b | A geometry (which may be |
Returns
Type | Description |
---|---|
Double | A safe scale factor for the geometry ordinates |
SafeScale(Double)
Computes a safe scale factor for a numeric value. A safe scale factor ensures that rounded number has no more than MAX_ROBUST_DP_DIGITS digits of precision.
Declaration
public static double SafeScale(double value)
Parameters
Type | Name | Description |
---|---|---|
Double | value | A numeric value. |
Returns
Type | Description |
---|---|
Double | A safe scale factor for the value |