/** * Returns the coordinate of the from-node. */ public Coordinate getCoordinate() { return from.getCoordinate(); } /**
/** * Adds a node to the map, replacing any that is already at that location. * @return the added node */ public Node add(Node n) { nodeMap.put(n.getCoordinate(), n); return n; }
/** * Constructs a DirectedEdge connecting the <code>from</code> node to the * <code>to</code> node. * * @param directionPt * specifies this DirectedEdge's direction vector * (determined by the vector from the <code>from</code> node * to <code>directionPt</code>) * @param edgeDirection * whether this DirectedEdge's direction is the same as or * opposite to that of the parent Edge (if any) */ public DirectedEdge(Node from, Node to, Coordinate directionPt, boolean edgeDirection) { this.from = from; this.to = to; this.edgeDirection = edgeDirection; p0 = from.getCoordinate(); p1 = directionPt; double dx = p1.x - p0.x; double dy = p1.y - p0.y; quadrant = Quadrant.quadrant(dx, dy); angle = Math.atan2(dy, dx); //Assert.isTrue(! (dx == 0 && dy == 0), "EdgeEnd with identical endpoints found"); }
/** * Removes a node from the graph, along with any associated DirectedEdges and * Edges. */ public void remove(Node node) { // unhook all directed edges List outEdges = node.getOutEdges().getEdges(); for (Iterator i = outEdges.iterator(); i.hasNext(); ) { DirectedEdge de = (DirectedEdge) i.next(); DirectedEdge sym = de.getSym(); // remove the diredge that points to this node if (sym != null) remove(sym); // remove this diredge from the graph collection dirEdges.remove(de); Edge edge = de.getEdge(); if (edge != null) { edges.remove(edge); } } // remove the node from the graph nodeMap.remove(node.getCoordinate()); node.remove(); }