/** * Initializes this Edge's two DirectedEdges, and for each DirectedEdge: sets the * Edge, sets the symmetric DirectedEdge, and adds this Edge to its from-Node. */ public void setDirectedEdges(DirectedEdge de0, DirectedEdge de1) { dirEdge = new DirectedEdge[] { de0, de1 }; de0.setEdge(this); de1.setEdge(this); de0.setSym(de1); de1.setSym(de0); de0.getFromNode().addOutEdge(de0); de1.getFromNode().addOutEdge(de1); }
/** * Constructs an Edge initialized with the given DirectedEdges, and for each * DirectedEdge: sets the Edge, sets the symmetric DirectedEdge, and adds * this Edge to its from-Node. */ public Edge(DirectedEdge de0, DirectedEdge de1) { setDirectedEdges(de0, de1); }
/** * Returns an {@link Iterator} over the {@link Node}s in this graph. * @return an iterator over the nodes */ public Iterator nodeIterator() { return nodeMap.iterator(); }
/** * Removes a {@link DirectedEdge} from its from-{@link Node} and from this graph. * This method does not remove the {@link Node}s associated with the DirectedEdge, * even if the removal of the DirectedEdge reduces the degree of a Node to zero. */ public void remove(DirectedEdge de) { DirectedEdge sym = de.getSym(); if (sym != null) sym.setSym(null); de.getFromNode().remove(de); de.remove(); dirEdges.remove(de); }
/** * Returns all Edges that connect the two nodes (which are assumed to be different). */ public static Collection getEdgesBetween(Node node0, Node node1) { List edges0 = DirectedEdge.toEdges(node0.getOutEdges().getEdges()); Set commonEdges = new HashSet(edges0); List edges1 = DirectedEdge.toEdges(node1.getOutEdges().getEdges()); commonEdges.retainAll(edges1); return commonEdges; }
/** * If <code>node</code> is one of the two nodes associated with this Edge, * returns the other node; otherwise returns null. */ public Node getOppositeNode(Node node) { if (dirEdge[0].getFromNode() == node) return dirEdge[0].getToNode(); if (dirEdge[1].getFromNode() == node) return dirEdge[1].getToNode(); // node not found // possibly should throw an exception here? return null; }
/** * Adds the Edge and its DirectedEdges with this PlanarGraph. * Assumes that the Edge has already been created with its associated DirectEdges. * Only subclasses can add Edges, to ensure the edges added are of the right class. */ protected void add(Edge edge) { edges.add(edge); add(edge.getDirEdge(0)); add(edge.getDirEdge(1)); }
private static Node findLowestDegreeNode(Subgraph graph) { int minDegree = Integer.MAX_VALUE; Node minDegreeNode = null; for (Iterator i = graph.nodeIterator(); i.hasNext(); ) { Node node = (Node) i.next(); if (minDegreeNode == null || node.getDegree() < minDegree) { minDegree = node.getDegree(); minDegreeNode = node; } } return minDegreeNode; }
/** * Returns the coordinate for the node at wich this star is based */ public Coordinate getCoordinate() { Iterator it = iterator(); if (! it.hasNext()) return null; DirectedEdge e = (DirectedEdge) it.next(); return e.getCoordinate(); }
/** * Adds an outgoing DirectedEdge to this Node. */ public void addOutEdge(DirectedEdge de) { deStar.add(de); }
/** * Removes a {@link DirectedEdge} incident on this node. * Does not change the state of the directed edge. */ public void remove(DirectedEdge de) { deStar.remove(de); }
/** * Constructs a Node with the given location. */ public Node(Coordinate pt) { this(pt, new DirectedEdgeStar()); }
/** * Adds a node to the map, replacing any that is already at that location. * Only subclasses can add Nodes, to ensure Nodes are of the right type. * * @param node the node to add */ protected void add(Node node) { nodeMap.add(node); }
/** * Returns the {@link Node} at the given location, * or null if no {@link Node} was there. * * @param pt the location to query * @return the node found * or <code>null</code> if this graph contains no node at the location */ public Node findNode(Coordinate pt) { return (Node) nodeMap.find(pt); }
/** * Returns the DirectedEdges, in ascending order by angle with the positive x-axis. */ public List getEdges() { sortEdges(); return outEdges; }
/** * Returns the number of edges around this Node. */ public int getDegree() { return deStar.getDegree(); } /**
/** * Returns the zero-based index of the given Edge, after sorting in ascending order * by angle with the positive x-axis. */ public int getIndex(Edge edge) { return deStar.getIndex(edge); }
/** * Returns the {@link DirectedEdge} that starts from the given node, or null if the * node is not one of the two nodes associated with this Edge. */ public DirectedEdge getDirEdge(Node fromNode) { if (dirEdge[0].getFromNode() == fromNode) return dirEdge[0]; if (dirEdge[1].getFromNode() == fromNode) return dirEdge[1]; // node not found // possibly should throw an exception here? return null; }
/** * Returns the coordinate of the from-node. */ public Coordinate getCoordinate() { return from.getCoordinate(); } /**
/** * Returns an Iterator over the Nodes in this PlanarGraph. */ public Iterator nodeIterator() { return nodeMap.iterator(); } /**