Class Polyline
java.lang.Object
org.apache.sis.internal.feature.AbstractGeometry
org.apache.sis.internal.feature.j2d.FlatShape
org.apache.sis.internal.feature.j2d.Polyline
- All Implemented Interfaces:
Shape
- Direct Known Subclasses:
Polygon
A polylines or polygons as a Java2D
Shape
. This class has some similarities
with Path2D
with the following differences:
- No synchronization.
- Line segments only (no Bézier curves).
- No multi-polylines (e.g. no "move to" operation in the middle).
- Coordinates "compressed" (with a simple translation) as
float
.
Precision and pseudo-compression
Coordinates are stored withfloat
precision for reducing memory usage with large polylines.
This is okay if coordinates are approximate anyway, for example if they are values interpolated by
the Isolines
class. For attenuating the precision lost, coordinate values are converted by
applications of the two following steps:
- First, translate coordinates toward zero. For example, latitude or longitude values in the [50 … 60]° range have a precision of about 4E-6° (about 0.4 meter). But translating those coordinates to the [-5 … 5]° range increases their precision to 0.05 meter. The precision gain is more important when the original coordinates are projected coordinates with high "false easting" / "false northing" parameters.
- Next, if minimum or maximum coordinate values are outside the range allowed by
float
exponent values, multiply coordinates by a power of 2 (Not yet implemented). Note that precision gain happens only when values are made closer to zero by a translation. Making coordinates closer to zero by a multiplication has no effect on the precision. This step is required only for avoiding overflow or underflow.
- Since:
- 1.1
- Version:
- 1.3
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static final class
Iterator over polyline(s) or polygon(s) coordinates. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final float[]
The "compressed" coordinate values as (x,y) tuples.private final AffineTransform
The transform fromcoordinates
values to the values given byPolyline.Iter
. -
Constructor Summary
ConstructorsConstructorDescriptionPolyline
(double[] coordinates, int size) Creates a new polylines with the given coordinates. -
Method Summary
Modifier and TypeMethodDescriptionboolean
contains
(double x, double y) Tests if the given coordinates are inside the boundary of this shape.boolean
contains
(double x, double y, double w, double h) Tests if the interior of this shape entirely contains the interior of the given rectangle.boolean
Tests if the interior of this shape entirely contains the interior of the given rectangle.final PathIterator
Returns an iterator over coordinates in this polyline.boolean
intersects
(double x, double y, double w, double h) Tests if the interior of this shape intersects the interior of the given rectangle.boolean
Tests if the interior of this shape intersects the interior of the given rectangle.private PathIterator
iterator()
Returns an iterator over coordinates without user transform.private static double
round
(double center, double min, double max) Rounds the translation to an arbitrary number of bits (currently 20).toString()
Returns a string representation for debugging purposes.Methods inherited from class org.apache.sis.internal.feature.j2d.FlatShape
contains, fastClip, getBounds, getBounds2D, getPathIterator
-
Field Details
-
coordinates
private final float[] coordinatesThe "compressed" coordinate values as (x,y) tuples. To get the desired coordinates, those values must be converted by theinflate
transform. -
inflate
The transform fromcoordinates
values to the values given byPolyline.Iter
. This transform is usually only a translation.
-
-
Constructor Details
-
Polyline
Polyline(double[] coordinates, int size) Creates a new polylines with the given coordinates. Thecoordinates
array shall not be empty.- Parameters:
coordinates
- the coordinate values as (x,y) tuples.size
- number of valid value incoordinates
array.
-
-
Method Details
-
round
private static double round(double center, double min, double max) Rounds the translation to an arbitrary number of bits (currently 20). The intent is to avoid that zero values become something like 1E-9. The number of bits that we kept should be less that the number of bits in the significand (mantissa) offloat
type. -
contains
public boolean contains(double x, double y) Tests if the given coordinates are inside the boundary of this shape. -
intersects
public boolean intersects(double x, double y, double w, double h) Tests if the interior of this shape intersects the interior of the given rectangle. May conservatively returntrue
if an intersection is probable but accurate answer would be too costly to compute. -
intersects
Tests if the interior of this shape intersects the interior of the given rectangle. May conservatively returntrue
if an intersection is probable but accurate answer would be too costly to compute. -
contains
public boolean contains(double x, double y, double w, double h) Tests if the interior of this shape entirely contains the interior of the given rectangle. May conservatively returnfalse
if an accurate answer would be too costly to compute. -
contains
Tests if the interior of this shape entirely contains the interior of the given rectangle. May conservatively returnfalse
if an accurate answer would be too costly to compute. -
iterator
Returns an iterator over coordinates without user transform. -
getPathIterator
Returns an iterator over coordinates in this polyline. -
toString
Returns a string representation for debugging purposes.
-