Package org.locationtech.jts.planargraph
Class DirectedEdge
- java.lang.Object
-
- org.locationtech.jts.planargraph.GraphComponent
-
- org.locationtech.jts.planargraph.DirectedEdge
-
- All Implemented Interfaces:
Comparable
- Direct Known Subclasses:
LineMergeDirectedEdge
public class DirectedEdge extends GraphComponent implements Comparable
Represents a directed edge in aPlanarGraph. A DirectedEdge may or may not have a reference to a parentEdge(some applications of planar graphs may not require explicit Edge objects to be created). Usually a client using aPlanarGraphwill subclassDirectedEdgeto add its own application-specific data and methods.- Version:
- 1.7
-
-
Field Summary
Fields Modifier and Type Field Description protected doubleangleprotected booleanedgeDirectionprotected Nodefromprotected Coordinatep0protected Coordinatep1protected EdgeparentEdgeprotected intquadrantprotected DirectedEdgesymprotected Nodeto-
Fields inherited from class org.locationtech.jts.planargraph.GraphComponent
isMarked, isVisited
-
-
Constructor Summary
Constructors Constructor Description DirectedEdge(Node from, Node to, Coordinate directionPt, boolean edgeDirection)Constructs a DirectedEdge connecting thefromnode to thetonode.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareDirection(DirectedEdge e)Returns 1 if this DirectedEdge has a greater angle with the positive x-axis than b", 0 if the DirectedEdges are collinear, and -1 otherwise.intcompareTo(Object obj)Returns 1 if this DirectedEdge has a greater angle with the positive x-axis than b", 0 if the DirectedEdges are collinear, and -1 otherwise.doublegetAngle()Returns the angle that the start of this DirectedEdge makes with the positive x-axis, in radians.CoordinategetCoordinate()Returns the coordinate of the from-node.CoordinategetDirectionPt()Returns a point to which an imaginary line is drawn from the from-node to specify this DirectedEdge's orientation.EdgegetEdge()Returns this DirectedEdge's parent Edge, or null if it has none.booleangetEdgeDirection()Returns whether the direction of the parent Edge (if any) is the same as that of this Directed Edge.NodegetFromNode()Returns the node from which this DirectedEdge leaves.intgetQuadrant()Returns 0, 1, 2, or 3, indicating the quadrant in which this DirectedEdge's orientation lies.DirectedEdgegetSym()Returns the symmetric DirectedEdge -- the other DirectedEdge associated with this DirectedEdge's parent Edge.NodegetToNode()Returns the node to which this DirectedEdge goes.booleanisRemoved()Tests whether this directed edge has been removed from its containing graphvoidprint(PrintStream out)Prints a detailed string representation of this DirectedEdge to the given PrintStream.voidsetEdge(Edge parentEdge)Associates this DirectedEdge with an Edge (possibly null, indicating no associated Edge).voidsetSym(DirectedEdge sym)Sets this DirectedEdge's symmetric DirectedEdge, which runs in the opposite direction.static ListtoEdges(Collection dirEdges)Returns a List containing the parent Edge (possibly null) for each of the given DirectedEdges.-
Methods inherited from class org.locationtech.jts.planargraph.GraphComponent
getComponentWithVisitedState, getContext, getData, isMarked, isVisited, setContext, setData, setMarked, setMarked, setVisited, setVisited
-
-
-
-
Field Detail
-
parentEdge
protected Edge parentEdge
-
from
protected Node from
-
to
protected Node to
-
p0
protected Coordinate p0
-
p1
protected Coordinate p1
-
sym
protected DirectedEdge sym
-
edgeDirection
protected boolean edgeDirection
-
quadrant
protected int quadrant
-
angle
protected double angle
-
-
Constructor Detail
-
DirectedEdge
public DirectedEdge(Node from, Node to, Coordinate directionPt, boolean edgeDirection)
Constructs a DirectedEdge connecting thefromnode to thetonode.- Parameters:
directionPt- specifies this DirectedEdge's direction vector (determined by the vector from thefromnode todirectionPt)edgeDirection- whether this DirectedEdge's direction is the same as or opposite to that of the parent Edge (if any)
-
-
Method Detail
-
toEdges
public static List toEdges(Collection dirEdges)
Returns a List containing the parent Edge (possibly null) for each of the given DirectedEdges.
-
getEdge
public Edge getEdge()
Returns this DirectedEdge's parent Edge, or null if it has none.
-
setEdge
public void setEdge(Edge parentEdge)
Associates this DirectedEdge with an Edge (possibly null, indicating no associated Edge).
-
getQuadrant
public int getQuadrant()
Returns 0, 1, 2, or 3, indicating the quadrant in which this DirectedEdge's orientation lies.
-
getDirectionPt
public Coordinate getDirectionPt()
Returns a point to which an imaginary line is drawn from the from-node to specify this DirectedEdge's orientation.
-
getEdgeDirection
public boolean getEdgeDirection()
Returns whether the direction of the parent Edge (if any) is the same as that of this Directed Edge.
-
getFromNode
public Node getFromNode()
Returns the node from which this DirectedEdge leaves.
-
getToNode
public Node getToNode()
Returns the node to which this DirectedEdge goes.
-
getCoordinate
public Coordinate getCoordinate()
Returns the coordinate of the from-node.
-
getAngle
public double getAngle()
Returns the angle that the start of this DirectedEdge makes with the positive x-axis, in radians.
-
getSym
public DirectedEdge getSym()
Returns the symmetric DirectedEdge -- the other DirectedEdge associated with this DirectedEdge's parent Edge.
-
setSym
public void setSym(DirectedEdge sym)
Sets this DirectedEdge's symmetric DirectedEdge, which runs in the opposite direction.
-
isRemoved
public boolean isRemoved()
Tests whether this directed edge has been removed from its containing graph- Specified by:
isRemovedin classGraphComponent- Returns:
trueif this directed edge is removed
-
compareTo
public int compareTo(Object obj)
Returns 1 if this DirectedEdge has a greater angle with the positive x-axis than b", 0 if the DirectedEdges are collinear, and -1 otherwise.Using the obvious algorithm of simply computing the angle is not robust, since the angle calculation is susceptible to roundoff. A robust algorithm is:
- first compare the quadrants. If the quadrants are different, it it trivial to determine which vector is "greater".
- if the vectors lie in the same quadrant, the robust
Orientation#computeOrientation(Coordinate, Coordinate, Coordinate)function can be used to decide the relative orientation of the vectors.
- Specified by:
compareToin interfaceComparable
-
compareDirection
public int compareDirection(DirectedEdge e)
Returns 1 if this DirectedEdge has a greater angle with the positive x-axis than b", 0 if the DirectedEdges are collinear, and -1 otherwise.Using the obvious algorithm of simply computing the angle is not robust, since the angle calculation is susceptible to roundoff. A robust algorithm is:
- first compare the quadrants. If the quadrants are different, it it trivial to determine which vector is "greater".
- if the vectors lie in the same quadrant, the robust
Orientation#computeOrientation(Coordinate, Coordinate, Coordinate)function can be used to decide the relative orientation of the vectors.
-
print
public void print(PrintStream out)
Prints a detailed string representation of this DirectedEdge to the given PrintStream.
-
-