java.lang.Object
org.apache.commons.geometry.euclidean.internal.AbstractPathConnector<E>
Type Parameters:
E - Element type
Direct Known Subclasses:
AbstractGreatArcConnector, AbstractLinePathConnector

public abstract class AbstractPathConnector<E extends AbstractPathConnector.ConnectableElement<E>> extends Object
Abstract base class for joining unconnected path elements into connected, directional paths. The connection algorithm is exposed as a set of protected methods, allowing subclasses to define their own public API. Implementations must supply their own subclass of AbstractPathConnector.ConnectableElement specific for the objects being connected.

The connection algorithm proceeds as follows:

This class is not thread-safe.

See Also:
  • Field Details

  • Constructor Details

    • AbstractPathConnector

      public AbstractPathConnector()
  • Method Details

    • connectPathElements

      protected void connectPathElements(Iterable<E> elements)
      Add a collection of path elements to the connector and attempt to connect each new element with previously added ones.
      Parameters:
      elements - path elements to connect
    • addPathElement

      protected void addPathElement(E element)
      Add a single path element to the connector, leaving it unconnected until a later call to to connectPathElements(Iterable) or computePathRoots().
      Parameters:
      element - value to add to the connector
      See Also:
    • computePathRoots

      protected List<E> computePathRoots()
      Compute all connected paths and return a list of path elements representing the roots (start locations) of each. Each returned element is the head of a (possibly circular) linked list that follows a connected path.

      The connector is reset after this call. Further calls to add elements will result in new paths being generated.

      Returns:
      a list of root elements for the computed connected paths
    • followForwardConnections

      private void followForwardConnections(E start)
      Find and follow forward connections from the given start element.
      Parameters:
      start - element to begin the connection operation with
    • makeForwardConnection

      private E makeForwardConnection(E element)
      Connect the end point of the given element to the start point of another element. Returns the newly connected element or null if no forward connection was made.
      Parameters:
      element - element to connect
      Returns:
      the next element in the path or null if no connection was made
    • findPossibleConnections

      private void findPossibleConnections(E element)
      Find possible connections for the given element and place them in the possibleConnections and possiblePointConnections lists.
      Parameters:
      element - the element to find connections for
    • addPossibleConnection

      private boolean addPossibleConnection(E element, E candidate)
      Add the candidate to one of the connection lists if it represents a possible connection. Returns true if the candidate was added, otherwise false.
      Parameters:
      element - element to check for connections with
      candidate - candidate connection element
      Returns:
      true if the candidate is a possible connection
    • selectPointConnection

      protected E selectPointConnection(E incoming, List<E> outgoingList)
      Method called to select a connection to use for a given element when multiple zero-length connections are available. The algorithm here attempts to choose the point most likely to produce a logical path by selecting the outgoing element with the smallest relative angle with the incoming element, with unconnected element preferred over ones that are already connected (thereby allowing other connections to occur in the path).
      Parameters:
      incoming - the incoming element
      outgoingList - list of available outgoing point-like connections
      Returns:
      the connection to use
    • selectConnection

      protected abstract E selectConnection(E incoming, List<E> outgoing)
      Method called to select a connection to use for a given segment when multiple non-length-zero connections are available. In this case, the selection of the outgoing connection depends only on the desired characteristics of the connected path.
      Parameters:
      incoming - the incoming segment
      outgoing - list of available outgoing connections; will always contain at least two elements
      Returns:
      the connection to use