Class Polyline

All Implemented Interfaces:
Shape
Direct Known Subclasses:
Polygon

class Polyline extends FlatShape
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 with float 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:
  1. 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.
  2. 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 Classes
    Modifier and Type
    Class
    Description
    (package private) static final class 
    Iterator over polyline(s) or polygon(s) coordinates.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final float[]
    The "compressed" coordinate values as (x,y) tuples.
    private final AffineTransform
    The transform from coordinates values to the values given by Polyline.Iter.

    Fields inherited from class org.apache.sis.internal.feature.j2d.FlatShape

    bounds
  • Constructor Summary

    Constructors
    Constructor
    Description
    Polyline(double[] coordinates, int size)
    Creates a new polylines with the given coordinates.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    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.
    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
    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).
    Returns a string representation for debugging purposes.

    Methods inherited from class org.apache.sis.internal.feature.j2d.FlatShape

    contains, fastClip, getBounds, getBounds2D, getPathIterator

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • coordinates

      private final float[] coordinates
      The "compressed" coordinate values as (x,y) tuples. To get the desired coordinates, those values must be converted by the inflate transform.
    • inflate

      private final AffineTransform inflate
      The transform from coordinates values to the values given by Polyline.Iter. This transform is usually only a translation.
  • Constructor Details

    • Polyline

      Polyline(double[] coordinates, int size)
      Creates a new polylines with the given coordinates. The coordinates array shall not be empty.
      Parameters:
      coordinates - the coordinate values as (x,y) tuples.
      size - number of valid value in coordinates 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) of float 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 return true if an intersection is probable but accurate answer would be too costly to compute.
    • intersects

      public boolean intersects(Rectangle2D r)
      Tests if the interior of this shape intersects the interior of the given rectangle. May conservatively return true 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 return false if an accurate answer would be too costly to compute.
    • contains

      public boolean contains(Rectangle2D r)
      Tests if the interior of this shape entirely contains the interior of the given rectangle. May conservatively return false if an accurate answer would be too costly to compute.
    • iterator

      private PathIterator iterator()
      Returns an iterator over coordinates without user transform.
    • getPathIterator

      public final PathIterator getPathIterator(AffineTransform at)
      Returns an iterator over coordinates in this polyline.
    • toString

      public String toString()
      Returns a string representation for debugging purposes.
      Overrides:
      toString in class Object
      Returns:
      a debug string representation.