Class PrecisionModel
Specifies the precision model of the Coordinate
s in a Geometry
.
In other words, specifies the grid of allowable points for a Geometry
.
A precision model may befloating (Floating or FloatingSingle),
in which case normal floating-point value semantics apply.
Inherited Members
Namespace: NetTopologySuite.Geometries
Assembly: NetTopologySuite.dll
Syntax
[Serializable]
public class PrecisionModel : IComparable, IComparable<PrecisionModel>
Remarks
For a Fixed precision model the MakePrecise(Coordinate) method allows rounding a coordinate to a "precise" value; that is, one whose precision is known exactly.
Coordinates are assumed to be precise in geometries. That is, the coordinates are assumed to be rounded to the precision model given for the geometry.
All internal operations
assume that coordinates are rounded to the precision model.
Constructive methods (such as bool operations) always round computed
coordinates to the appropriate precision model.
Three types of precision model are supported:
Floating | Represents full double precision floating point. This is the default precision model used in NTS |
FloatingSingle | Represents single precision floating point |
Fixed | Represents a model with a fixed number of decimal places. A Fixed Precision Model is specified by a scale factor. The scale factor specifies the size of the grid which numbers are rounded to. |
jtsPt.X = Math.Round( inputPt.X * scale, MidPointRounding.AwayFromZero ) / scale )
jtsPt.Y = Math.Round( inputPt.Y * scale, MidPointRounding.AwayFromZero ) / scale )
For example, to specify 3 decimal places of precision, use a scale factor of 1000. To specify -3 decimal places of precision (i.e. rounding to the nearest 1000), use a scale factor of 0.001.
It is also supported to specify a precise grid size by providing it as a negative scale factor. This allows setting a precise grid size rather than using a fractional scale, which provides more accurate and robust rounding. For example, to specify rounding to the nearest 1000 use a scale factor of -1000.Coordinates are represented internally as Java double-precision values. .NET uses the IEEE-394 floating point standard, which provides 53 bits of precision. (Thus the maximum precisely representable integer is 9,007,199,254,740,992 - or almost 16 decimal digits of precision).
Constructors
| Improve this Doc View SourcePrecisionModel()
Creates a PrecisionModel
with a default precision
of Floating.
Declaration
public PrecisionModel()
PrecisionModel(PrecisionModel)
Copy constructor to create a new PrecisionModel
from an existing one.
Declaration
public PrecisionModel(PrecisionModel pm)
Parameters
Type | Name | Description |
---|---|---|
PrecisionModel | pm |
PrecisionModel(PrecisionModels)
Creates a PrecisionModel
that specifies
an explicit precision model type.
If the model type is Fixed the scale factor will default to 1.
Declaration
public PrecisionModel(PrecisionModels modelType)
Parameters
Type | Name | Description |
---|---|---|
PrecisionModels | modelType | The type of the precision model. |
PrecisionModel(Double)
Creates a PrecisionModel
that specifies Fixed precision.
Fixed-precision coordinates are represented as precise internal coordinates,
which are rounded to the grid defined by the scale factor.
The provided scale may be negative, to specify an exact grid size. The scale is then computed as the reciprocal.
Declaration
public PrecisionModel(double scale)
Parameters
Type | Name | Description |
---|---|---|
Double | scale | Amount by which to multiply a coordinate, to obtain a precise coordinate. Must be non-zero |
Fields
| Improve this Doc View SourceMaximumPreciseValue
The maximum precise value representable in a double. Since IEE754 double-precision numbers allow 53 bits of mantissa, the value is equal to 2^53 - 1. This provides almost 16 decimal digits of precision.
Declaration
public const double MaximumPreciseValue = 9007199254740992
Field Value
Type | Description |
---|---|
Double |
Properties
| Improve this Doc View SourceFixed
Gets a value indicating a precision model with a scale of 1
.
Declaration
public static Lazy<PrecisionModel> Fixed { get; }
Property Value
Type | Description |
---|---|
Lazy<PrecisionModel> | A fixed precision model |
Floating
Gets a value indicating a precision model with double precision.
Declaration
public static Lazy<PrecisionModel> Floating { get; }
Property Value
Type | Description |
---|---|
Lazy<PrecisionModel> | A double precision model |
FloatingSingle
Gets a value indicating a precision model with single precision.
Declaration
public static Lazy<PrecisionModel> FloatingSingle { get; }
Property Value
Type | Description |
---|---|
Lazy<PrecisionModel> | A single precision model |
GridSize
Computes the grid size for a fixed precision model. This is equal to the reciprocal of the scale factor. If the grid size has been set explicity (via a negative scale factor) it will be returned.
Declaration
public double GridSize { get; }
Property Value
Type | Description |
---|---|
Double | The grid size at a fixed precision scale. |
IsFloating
Tests whether the precision model supports floating point.
Declaration
public bool IsFloating { get; }
Property Value
Type | Description |
---|---|
Boolean |
|
MaximumSignificantDigits
Returns the maximum number of significant digits provided by this precision model. Intended for use by routines which need to print out precise values.
Declaration
public int MaximumSignificantDigits { get; }
Property Value
Type | Description |
---|---|
Int32 | The maximum number of decimal places provided by this precision model. |
PrecisionModelType
Gets the type of this PrecisionModel.
Declaration
public PrecisionModels PrecisionModelType { get; }
Property Value
Type | Description |
---|---|
PrecisionModels |
Scale
Returns the scale factor used to specify a fixed precision model.
Declaration
public double Scale { get; set; }
Property Value
Type | Description |
---|---|
Double | The scale factor for the fixed precision model |
Remarks
The number of decimal places of precision is equal to the base-10 logarithm of the scale factor. Non-integral and negative scale factors are supported. Negative scale factors indicate that the places of precision is to the left of the decimal point.
Methods
| Improve this Doc View SourceCompareTo(PrecisionModel)
Declaration
public int CompareTo(PrecisionModel other)
Parameters
Type | Name | Description |
---|---|---|
PrecisionModel | other |
Returns
Type | Description |
---|---|
Int32 |
CompareTo(Object)
Compares this PrecisionModel
object with the specified object for order.
A PrecisionModel is greater than another if it provides greater precision.
The comparison is based on the value returned by the
{getMaximumSignificantDigits) method.
This comparison is not strictly accurate when comparing floating precision models
to fixed models; however, it is correct when both models are either floating or fixed.
Declaration
public int CompareTo(object o)
Parameters
Type | Name | Description |
---|---|---|
Object | o | The |
Returns
Type | Description |
---|---|
Int32 | A negative integer, zero, or a positive integer as this |
Equals(PrecisionModel)
Declaration
public bool Equals(PrecisionModel otherPrecisionModel)
Parameters
Type | Name | Description |
---|---|---|
PrecisionModel | otherPrecisionModel |
Returns
Type | Description |
---|---|
Boolean |
Equals(Object)
Declaration
public override bool Equals(object other)
Parameters
Type | Name | Description |
---|---|---|
Object | other |
Returns
Type | Description |
---|---|
Boolean |
Overrides
| Improve this Doc View SourceGetHashCode()
Declaration
public override int GetHashCode()
Returns
Type | Description |
---|---|
Int32 |
Overrides
| Improve this Doc View SourceMakePrecise(Coordinate)
Rounds a Coordinate to the PrecisionModel grid.
Declaration
public void MakePrecise(Coordinate coord)
Parameters
Type | Name | Description |
---|---|---|
Coordinate | coord |
MakePrecise(Double)
Rounds a numeric value to the PrecisionModel grid. Symmetric Arithmetic Rounding is used, to provide uniform rounding behaviour no matter where the number is on the number line.
Declaration
public double MakePrecise(double val)
Parameters
Type | Name | Description |
---|---|---|
Double | val |
Returns
Type | Description |
---|---|
Double |
Remarks
This method has no effect on NaN values
MostPrecise(PrecisionModel, PrecisionModel)
Determines which of two PrecisionModels is the most precise
Declaration
public static PrecisionModel MostPrecise(PrecisionModel pm1, PrecisionModel pm2)
Parameters
Type | Name | Description |
---|---|---|
PrecisionModel | pm1 | A precision model |
PrecisionModel | pm2 | A precision model |
Returns
Type | Description |
---|---|
PrecisionModel | The PrecisionModel which is most precise |
ToString()
Declaration
public override string ToString()
Returns
Type | Description |
---|---|
String |
Overrides
Operators
| Improve this Doc View SourceEquality(PrecisionModel, PrecisionModel)
Declaration
public static bool operator ==(PrecisionModel obj1, PrecisionModel obj2)
Parameters
Type | Name | Description |
---|---|---|
PrecisionModel | obj1 | |
PrecisionModel | obj2 |
Returns
Type | Description |
---|---|
Boolean |
Inequality(PrecisionModel, PrecisionModel)
Declaration
public static bool operator !=(PrecisionModel obj1, PrecisionModel obj2)
Parameters
Type | Name | Description |
---|---|---|
PrecisionModel | obj1 | |
PrecisionModel | obj2 |
Returns
Type | Description |
---|---|
Boolean |