Class GeometricGraphPosition<N extends GeometricGraphNode,A extends GeometricGraphArc>

java.lang.Object
com.amalgamasimulation.graphagent.GeometricGraphPosition<N,A>

public class GeometricGraphPosition<N extends GeometricGraphNode,A extends GeometricGraphArc> extends Object
Class representing a position that point to the specific place in graph. A position can point either to a graph node or point on graph arc at certain offset from arc's beginning
Author:
Andrey Malykhanov
  • Constructor Details

    • GeometricGraphPosition

      public GeometricGraphPosition(Graph<N,A>.Node node)
      Creates a new position pointing to the specified graph node. If null is passed to this constructor, a IllegalArgumentException is thrown
      Parameters:
      node - specified graph node, must not be null
    • GeometricGraphPosition

      public GeometricGraphPosition(Graph<N,A>.Arc arc, double arcAbsOffset)
      Creates a new position pointing to the point on the specified arc located at the specified absolute offset from arc's beginning.

      A IllegalArgumentException is thrown in the following cases

    • If null arc is passed to this constructor
    • If arcAbsOffset is outside the range of [0, arc.getValue().getLength()] or is a Double.NaN
    • Parameters:
      arc - specified arc, must not be null
      arcAbsOffset - specified absolute offset on the arc, must be within the range of [0, arc.getValue().getLength()]
      See Also:
  • Method Details

    • of

      public static <N extends GeometricGraphNode, A extends GeometricGraphArc> GeometricGraphPosition<N,A> of(Graph<N,A>.Node node)
      Returns an instance of GeometricGraphPosition pointing to the specified graph node. If null is passed to this constructor, a IllegalArgumentException is thrown
      Parameters:
      node - specified graph node, must not be null
      Returns:
      an instance of GeometricGraphPosition
    • of

      public static <N extends GeometricGraphNode, A extends GeometricGraphArc> GeometricGraphPosition<N,A> of(Graph<N,A>.Arc arc, double arcAbsOffset)
      Returns an instance of GeometricGraphPosition pointing to the point on the specified arc located at the specified absolute offset from arc's beginning.

      A IllegalArgumentException is thrown in the following cases:

    • If null arc is passed to this constructor
    • If arcAbsOffset is outside the range of [0, arc.getValue().getLength()] or is a Double.NaN
    • Parameters:
      arc - specified arc, must not be null
      arcAbsOffset - specified absolute offset on the arc
      Returns:
      an instance of GeometricGraphPosition
    • getNode

      public Graph<N,A>.Node getNode()
      Returns the node if this position points to graph node, null otherwise
      Returns:
      node or null
    • getArc

      public Graph<N,A>.Arc getArc()
      Returns the arc if this position points place on a graph arc, null otherwise
      Returns:
      arc or null
    • getArcAbsOffset

      public double getArcAbsOffset()
      Returns absolute offset of the place where this position points to, or Double.NaN if this position points to a graph node. The returned value is always in range of [0, arc.getValue().getLength()]
      Returns:
      absolute offset, or Double.NaN
      See Also:
    • getPoint

      public Point getPoint()
      Returns the Point of this position that represents the location of this position in 2D-space. Never returns null
      Returns:
      Point of this position
    • getArcRelOffset

      public double getArcRelOffset()
      Returns relative offset of the place where this position points to, or Double.NaN if this position points to a graph node. The returned value is always in range of [0, 1]
      Returns:
      absolute offset or Double.NaN
      See Also:
    • isArcBeginPosition

      public boolean isArcBeginPosition()
      Returns true if this position points to the first point of an arc, false otherwise
      Returns:
      true if this position points to zero absolute offset of an arc, false otherwise
    • getArcEndPosition

      public GeometricGraphPosition<N,A> getArcEndPosition()
      Returns the instance of GeometricGraphPosition pointing to the very end of the arc of this position, or null if this position points to a node
      Returns:
      instance of GeometricGraphPosition pointing to the very end of the arc of this position, or null
    • getArcBeginPosition

      public GeometricGraphPosition<N,A> getArcBeginPosition()
      Returns the instance of GeometricGraphPosition pointing to the very beginning of the arc of this position, ornull if this position points to a node
      Returns:
      instance of GeometricGraphPosition pointing to the very beginning of the arc of this position, or null
    • isArcEndPosition

      public boolean isArcEndPosition()
      Returns true if this position points to the last point of an arc, false otherwise
      Returns:
      true if this position points to the last point of an arc, false otherwise
    • getSubPolylineFromArcBegin

      public Polyline getSubPolylineFromArcBegin()
      If this position points to an arc, returns Polyline that constitutes the trajectory from the arc's beginning to this position. If this position points to the first point of the arc (i.e. this.isArcBeginPosition() == true), returns a Polyline with a single point.

      If this position point to a node, returns null

      Returns:
      Polyline that constitutes the trajectory from arc's beginning to this position, or null
    • getSubPolylineToArcEnd

      public Polyline getSubPolylineToArcEnd()
      If this position points to an arc, returns Polyline that constitutes the trajectory from this position to the arc's end. If this position points to the last point of the arc (i.e. this.isArcEndPosition() == true) is, returns a Polyline with a single point.

      If this position point to a node, returns null

      Returns:
      Polyline that constitutes the trajectory from this position to the arc's end, or null
    • getReverse

      public GeometricGraphPosition<N,A> getReverse(Graph<N,A> graph)
      Returns the position pointing to the corresponding point of the reverse arc

      Returns null if this position points to an arc not having a reverse arc

      Parameters:
      graph - graph which this position belongs to
      Returns:
      position pointing to the corresponding point of the reverse arc, or null
    • getAdjacent

      public List<GeometricGraphPosition<N,A>> getAdjacent(Graph<N,A> graph)
      Returns the list of positions that are adjacent to this position, including this same position. The returned list cannot be empty and always contains at least this position.
      Parameters:
      graph - graph which this position belongs to
      Returns:
      list of positions that are adjacent to this position, including this position
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • equalsOrReverse

      public boolean equalsOrReverse(GeometricGraphPosition<N,A> otherPosition, Graph<N,A> graph)
      Returns true if this position is equal to either the specified position or the reverse position of the specified one, and false otherwise
      Parameters:
      otherPosition - specified position
      graph - graph which this position belongs to
      Returns:
      true if this position is equal to either the specified position or the reverse position of the specified one, and false otherwise
      See Also:
    • equalsOrAdjacent

      public boolean equalsOrAdjacent(GeometricGraphPosition<N,A> otherPosition, Graph<N,A> graph)
      Returns true if this position is equal to or adjacent with the specified position, false otherwise.

      Node that there can be no path between two adjacent positions, and, if such path exists, it can be a non-zero length path. Such situations can occur when at least one of the adjacent positions belongs to a monodirectional arc.

      Parameters:
      otherPosition - specified position
      graph - graph which this position belongs to
      Returns:
      true if this position is equal to or adjacent with the specified position, false otherwise
      See Also:
    • isOnSameOrReverseArc

      public boolean isOnSameOrReverseArc(GeometricGraphPosition<N,A> otherPosition, Graph<N,A> graph)
      Returns true if this position points to a place on the same or reverse arc with the specified arc. Returns false if either this or the specified position point to a node
      Parameters:
      otherPosition - specified position
      graph - graph which this position belongs to
      Returns:
      true if this position points to a place on the same or reverse arc with the specified arc, false otherwise
    • toString

      public String toString()
      Overrides:
      toString in class Object