PrecisionModel class
Specifies the precision model of the {@link Coordinate}s in a {@link Geometry}.
In other words, specifies the grid of allowable
points for all Geometry
s.
The {@link #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. JTS input routines automatically round coordinates to the precision model before creating Geometries. 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.
Currently three types of precision model are supported:
- FLOATING - represents full double precision floating point. This is the default precision model used in JTS
- FLOATING_SINGLE - 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.
Input coordinates are mapped to fixed coordinates according to the following
equations:
- jtsPt.x = round( (inputPt.x * scale ) / scale
- jtsPt.y = round( (inputPt.y * scale ) / scale
Coordinates are represented internally as Java double-precision values. Since Java uses the IEEE-394 floating point standard, this 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).
JTS binary methods currently do not handle inputs which have different precision models. The precision model of any constructed geometric value is undefined.
@version 1.7
- Implemented types
Constructors
- PrecisionModel()
-
Creates a
PrecisionModel
with a default precision of FLOATING. - PrecisionModel.fixedPrecision(double scale)
-
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. - PrecisionModel.fromPrecisionModel(PrecisionModel pm)
-
Copy constructor to create a new
PrecisionModel
from an existing one. - PrecisionModel.fromType(Type modelType)
-
Creates a
PrecisionModel
that specifies an explicit precision model type. If the model type is FIXED the scale factor will default to 1.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- modelType ↔ Type
-
The type of PrecisionModel this represents.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scale ↔ double
-
The scale factor which determines the number of decimal places in fixed precision.
getter/setter pair
Methods
-
compareTo(
dynamic o) → int -
Compares this {@link 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
{@link #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.
override
-
equals(
Object other) → bool -
getMaximumSignificantDigits(
) → int - Returns the maximum number of significant digits provided by this precision model. Intended for use by routines which need to print out decimal representations of precise values (such as {@link WKTWriter}).
-
getScale(
) → double - Returns the scale factor used to specify a fixed precision model. 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.
-
getType(
) → Type - Gets the type of this precision model @return the type of this precision model @see Type
-
isFloating(
) → bool -
Tests whether the precision model supports floating point
@return
true
if the precision model supports floating point -
makeCoordinatePrecise(
Coordinate coord) → void - Rounds a Coordinate to the PrecisionModel grid.
-
makePrecise(
double val) → double - Rounds a numeric value to the PrecisionModel grid. Asymmetric Arithmetic Rounding is used, to provide uniform rounding behaviour no matter where the number is on the number line.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
setScale(
double scale) → void - Sets the multiplying factor used to obtain a precise coordinate. This method is because PrecisionModel is an immutable (value) type.
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- FIXED → Type
-
Fixed Precision indicates that coordinates have a fixed number of decimal places.
The number of decimal places is determined by the log10 of the scale factor.
final
- FLOATING → Type
-
Floating precision corresponds to the standard Java
double-precision floating-point representation, which is
based on the IEEE-754 standard
final
- maximumPreciseValue → double
-
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.
final
Static Methods
-
mostPrecise(
PrecisionModel pm1, PrecisionModel pm2) → PrecisionModel - Determines which of two {@link PrecisionModel}s is the most precise (allows the greatest number of significant digits).