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 Summary
ConstructorsConstructorDescriptionGeometricGraphPosition(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.GeometricGraphPosition(Graph<N, A>.Node node) Creates a new position pointing to the specified graph node. -
Method Summary
Modifier and TypeMethodDescriptionbooleanbooleanequalsOrAdjacent(GeometricGraphPosition<N, A> otherPosition, Graph<N, A> graph) Returnstrueif this position is equal to or adjacent with the specified position,falseotherwise.booleanequalsOrReverse(GeometricGraphPosition<N, A> otherPosition, Graph<N, A> graph) Returnstrueif this position is equal to either the specified position or the reverse position of the specified one, andfalseotherwisegetAdjacent(Graph<N, A> graph) Returns the list of positions that are adjacent to this position, including this same position.getArc()Returns the arc if this position points place on a graph arc,nullotherwisedoubleReturns absolute offset of the place where this position points to, orDouble.NaNif this position points to a graph node.Returns the instance ofGeometricGraphPositionpointing to the very beginning of the arc of this position, ornullif this position points to a nodeReturns the instance ofGeometricGraphPositionpointing to the very end of the arc of this position, ornullif this position points to a nodedoubleReturns relative offset of the place where this position points to, or Double.NaN if this position points to a graph node.getNode()Returns the node if this position points to graph node,nullotherwisegetPoint()Returns thePointof this position that represents the location of this position in 2D-space.getReverse(Graph<N, A> graph) Returns the position pointing to the corresponding point of the reverse arcIf this position points to an arc, returnsPolylinethat constitutes the trajectory from the arc's beginning to this position.If this position points to an arc, returnsPolylinethat constitutes the trajectory from this position to the arc's end.inthashCode()booleanReturnstrueif this position points to the first point of an arc,falseotherwisebooleanReturnstrueif this position points to the last point of an arc,falseotherwisebooleanisOnSameOrReverseArc(GeometricGraphPosition<N, A> otherPosition, Graph<N, A> graph) Returnstrueif this position points to a place on the same or reverse arc with the specified arc.static <N extends GeometricGraphNode,A extends GeometricGraphArc>
GeometricGraphPosition<N, A> Returns an instance ofGeometricGraphPositionpointing to the point on the specified arc located at the specified absolute offset from arc's beginning.static <N extends GeometricGraphNode,A extends GeometricGraphArc>
GeometricGraphPosition<N, A> Returns an instance ofGeometricGraphPositionpointing to the specified graph node.toString()
-
Constructor Details
-
GeometricGraphPosition
Creates a new position pointing to the specified graph node. Ifnullis passed to this constructor, aIllegalArgumentExceptionis thrown- Parameters:
node- specified graph node, must not benull
-
GeometricGraphPosition
Creates a new position pointing to the point on the specified arc located at the specified absolute offset from arc's beginning.A
IllegalArgumentExceptionis thrown in the following cases- If
nullarc 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 benullarcAbsOffset- specified absolute offset on the arc, must be within the range of [0, arc.getValue().getLength()]- See Also:
- If
-
-
Method Details
-
of
public static <N extends GeometricGraphNode,A extends GeometricGraphArc> GeometricGraphPosition<N,A> of(Graph<N, A>.Node node) Returns an instance ofGeometricGraphPositionpointing to the specified graph node. Ifnullis passed to this constructor, aIllegalArgumentExceptionis 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 ofGeometricGraphPositionpointing to the point on the specified arc located at the specified absolute offset from arc's beginning.A
IllegalArgumentExceptionis thrown in the following cases:- If
nullarc 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 benullarcAbsOffset- specified absolute offset on the arc- Returns:
- an instance of
GeometricGraphPosition
- If
-
getNode
Returns the node if this position points to graph node,nullotherwise- Returns:
- node or
null
-
getArc
Returns the arc if this position points place on a graph arc,nullotherwise- Returns:
- arc or
null
-
getArcAbsOffset
public double getArcAbsOffset()Returns absolute offset of the place where this position points to, orDouble.NaNif 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
Returns thePointof this position that represents the location of this position in 2D-space. Never returnsnull- Returns:
Pointof 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()Returnstrueif this position points to the first point of an arc,falseotherwise- Returns:
trueif this position points to zero absolute offset of an arc,falseotherwise
-
getArcEndPosition
Returns the instance ofGeometricGraphPositionpointing to the very end of the arc of this position, ornullif this position points to a node- Returns:
- instance of
GeometricGraphPositionpointing to the very end of the arc of this position, ornull
-
getArcBeginPosition
Returns the instance ofGeometricGraphPositionpointing to the very beginning of the arc of this position, ornullif this position points to a node- Returns:
- instance of
GeometricGraphPositionpointing to the very beginning of the arc of this position, ornull
-
isArcEndPosition
public boolean isArcEndPosition()Returnstrueif this position points to the last point of an arc,falseotherwise- Returns:
trueif this position points to the last point of an arc,falseotherwise
-
getSubPolylineFromArcBegin
If this position points to an arc, returnsPolylinethat 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 aPolylinewith a single point.If this position point to a node, returns
null- Returns:
Polylinethat constitutes the trajectory from arc's beginning to this position, ornull
-
getSubPolylineToArcEnd
If this position points to an arc, returnsPolylinethat 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 aPolylinewith a single point.If this position point to a node, returns
null- Returns:
Polylinethat constitutes the trajectory from this position to the arc's end, ornull
-
getReverse
Returns the position pointing to the corresponding point of the reverse arcReturns 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
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() -
equals
-
equalsOrReverse
Returnstrueif this position is equal to either the specified position or the reverse position of the specified one, andfalseotherwise- Parameters:
otherPosition- specified positiongraph- graph which this position belongs to- Returns:
trueif this position is equal to either the specified position or the reverse position of the specified one, andfalseotherwise- See Also:
-
equalsOrAdjacent
Returnstrueif this position is equal to or adjacent with the specified position,falseotherwise.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 positiongraph- graph which this position belongs to- Returns:
trueif this position is equal to or adjacent with the specified position,falseotherwise- See Also:
-
isOnSameOrReverseArc
Returnstrueif this position points to a place on the same or reverse arc with the specified arc. Returnsfalseif either this or the specified position point to a node- Parameters:
otherPosition- specified positiongraph- graph which this position belongs to- Returns:
trueif this position points to a place on the same or reverse arc with the specified arc,falseotherwise
-
toString
-