Class PolylineBuffer

java.lang.Object
org.apache.sis.internal.processing.isoline.PolylineBuffer

final class PolylineBuffer extends Object
Coordinates of a polyline under construction. Coordinates can be appended in only one direction. If the polyline may growth on both directions (which happens if the polyline crosses the bottom side and the right side of a cell), then the two directions are handled by two distinct instances connected by their opposite field.

When a polyline has been completed, its content is copied to Tracer.Level.path and the PolylineBuffer object is recycled for a new polyline.

Since:
1.1
Version:
1.3
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) double[]
    Coordinates as (x,y) tuples.
    (package private) static final int
    Number of coordinates in a tuple.
    (package private) PolylineBuffer
    If the polyline has points added to its two extremities, the other extremity.
    (package private) int
    Number of valid elements in the coordinates array.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an initially empty polyline.
    PolylineBuffer(double[] data)
    Creates a new polyline wrapping the given coordinates.
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) final void
    append(double x, double y)
    Appends given coordinates to this polyline.
    (package private) final PolylineBuffer
    Declares that the specified polyline will add points in the direction opposite to this polyline.
    (package private) final void
    Discards all coordinates in this polyline.
    (package private) final boolean
    Returns whether this polyline is empty.
    (package private) final void
    Appends the pixel coordinates of this polyline to the given path, for debugging purposes only.
    Returns a string representation of this Polyline for debugging purposes.
    (package private) final PolylineBuffer
    Transfers all coordinates from given polylines to this polylines, in same order.
    (package private) final boolean
    Transfers all coordinates from this polyline to the polyline going in opposite direction.

    Methods inherited from class java.lang.Object

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

    • DIMENSION

      static final int DIMENSION
      Number of coordinates in a tuple.
      See Also:
    • coordinates

      double[] coordinates
      Coordinates as (x,y) tuples. This array is expanded as needed.
    • size

      int size
      Number of valid elements in the coordinates array. This is twice the number of points.
    • opposite

      PolylineBuffer opposite
      If the polyline has points added to its two extremities, the other extremity. Otherwise null. The first point of opposite polyline is connected to the first point of this polyline. Consequently, when those two polylines are joined in a single polyline, the coordinates of either this or opposite must be iterated in reverse order.
  • Constructor Details

    • PolylineBuffer

      PolylineBuffer()
      Creates an initially empty polyline.
    • PolylineBuffer

      PolylineBuffer(double[] data)
      Creates a new polyline wrapping the given coordinates. Used for wrapping Fragments instances in objects expected by Tracer.writeTo(Joiner, Polyline[], boolean). Those Polyline instances are temporary.
  • Method Details

    • clear

      final void clear()
      Discards all coordinates in this polyline. This method does not clear the opposite polyline; it is caller's responsibility to do so.
    • isEmpty

      final boolean isEmpty()
      Returns whether this polyline is empty. This method is used only for assert isEmpty() statement because of the check for opposite == null: an empty polyline should not have a non-null opposite value.
    • attach

      final PolylineBuffer attach(PolylineBuffer other)
      Declares that the specified polyline will add points in the direction opposite to this polyline. This happens when the polyline crosses the bottom side and the right side of a cell (assuming an iteration from left to right and top to bottom).

      This method is typically invoked in the following pattern (but this is not mandatory). An important aspect is that this and other should be on perpendicular axes:

      Returns:
      this for method calls chaining.
    • transferFrom

      final PolylineBuffer transferFrom(PolylineBuffer source)
      Transfers all coordinates from given polylines to this polylines, in same order. This is used when polyline on the left side continues on bottom side, or conversely when polyline on the top side continues on right side. This polyline shall be empty before this method is invoked. The given source will become empty after this method returned.
      Parameters:
      source - the source from which to take data.
      Returns:
      this for method calls chaining.
    • transferToOpposite

      final boolean transferToOpposite()
      Transfers all coordinates from this polyline to the polyline going in opposite direction. This is used when this polyline reached the right image border, in which case its data will be lost if we do not copy them somewhere.
      Returns:
      true if coordinates have been transferred, or false if there is no opposite direction.
    • append

      final void append(double x, double y)
      Appends given coordinates to this polyline.
      Parameters:
      x - first coordinate of the (x,y) tuple to add.
      y - second coordinate of the (x,y) tuple to add.
    • toString

      public String toString()
      Returns a string representation of this Polyline for debugging purposes.
      Overrides:
      toString in class Object
    • toRawPath

      @Debug final void toRawPath(Map<PolylineStage,Path2D> appendTo)
      Appends the pixel coordinates of this polyline to the given path, for debugging purposes only. The #gridToCRS transform is not applied by this method. For avoiding confusing behavior, that transform should be null.
      Parameters:
      appendTo - where to append the coordinates.
      See Also: