java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
java.util.ArrayList<double[]>
org.apache.sis.internal.processing.isoline.Fragments
All Implemented Interfaces:
Serializable, Cloneable, Iterable<double[]>, Collection<double[]>, List<double[]>, RandomAccess

final class Fragments extends ArrayList<double[]>
List of PolylineBuffer coordinates that have not yet been closed. Each double[] in this list is a copy of a PolylineBuffer used by Tracer.Level. Those copies are performed for saving data before they are overwritten by next iterated cell.

List indices and ordering of points

For a given Fragments list, all double[] arrays at even indices shall have their points read in reverse order and all double[] arrays at odd indices shall have their points read in forward order. The list size must be even and the list may contain null elements when there is no data in the corresponding iteration order. This convention makes easy to reverse the order of all points, simply by reversing the order of double[] arrays: because even indices become odd and odd indices become even, points order are implicitly reverted without the need to rewrite all double[] array contents.
Since:
1.1
Version:
1.3
See Also:
  • Field Details

    • firstPoint

      private Point firstPoint
      The first points and last point in this list of polylines. By convention the coordinate having fraction digits has all its bits inverted by the ~ operator. May be null if a coordinate is NaN. Do not modify Point field values, because those instances are keys in Tracer.Level.partialPaths.
    • lastPoint

      private Point lastPoint
      The first points and last point in this list of polylines. By convention the coordinate having fraction digits has all its bits inverted by the ~ operator. May be null if a coordinate is NaN. Do not modify Point field values, because those instances are keys in Tracer.Level.partialPaths.
  • Constructor Details

    • Fragments

      Fragments(PolylineBuffer polylineOnLeft, PolylineBuffer polylineOnTop)
      Creates a list of polylines initialized to the given items. The given polylines and their opposite directions are cleared by this method.
      Parameters:
      polylineOnLeft - first polyline with points in forward order. Shall not be null.
      polylineOnTop - next polyline with points in reverse order, or null if none.
  • Method Details

    • take

      private void take(PolylineBuffer polyline)
      Takes a copy of coordinate values of given polyline, then clears that polyline.
    • isExtremity

      final boolean isExtremity(Point key)
      Returns true if the given point is equal to the start point or end point. This is used in assertions for checking key validity in Tracer.Level.partialPaths.
    • addOrMerge

      final boolean addOrMerge(Map<Point,Fragments> partialPaths)
      Associates this polyline to its two extremities in the given map. If other polylines already exist for one or both extremities, then this polyline will be merged with previously existing polylines. This method returns true if caller should store the coordinates in Tracer.Level.path immediately. It may be either because the polyline has been closed as a polygon, or because the two extremities contains NaN values in which case the polylines are not anymore in partialPaths.
      Parameters:
      partialPaths - where to add or merge polylines.
      Returns:
      true if this polyline became a closed polygon as a result of merge operation.
    • addAll

      private Point addAll(Fragments other, boolean prepend)
      Prepends or appends the given polylines to this list of polylines. Points order will be changed as needed in order to match extremities. The other instance should be forgotten after this method call.
      Parameters:
      other - the other polyline to append or prepend to this polyline.
      prepend - true for prepend operation, false for append.
      Returns:
      extremity of other which has not been assigned to this.
    • reverse

      private void reverse()
      Reverse the order of all points. The last polyline will become the first polyline and vice-versa. For each polyline, points will be iterated in opposite order. The trick on point order is done by moving polylines at even indices to odd indices, and conversely (see class javadoc for convention about even/odd indices).
    • toPolylines

      final PolylineBuffer[] toPolylines()
      Returns the content of this list as an array of PolylineBuffer instances. PolylineBuffer instances at even index should be written with their points in reverse order.
      Returns:
      elements of this array as polylines. May contain null elements.
      See Also:
      • #writeTo(Joiner, PolylineBuffer[], boolean)