use of com.revolsys.geometry.planargraph.Node in project com.revolsys.open by revolsys.
the class MiscellaneousTest2 method testDirectedEdgeComparator.
public void testDirectedEdgeComparator() {
final DirectedEdge d1 = new DirectedEdge(new Node(0, 0), new Node(10, 10), new PointDoubleXY(10, 10), true);
final DirectedEdge d2 = new DirectedEdge(new Node(0, 0), new Node(20, 20), new PointDoubleXY(20, 20), false);
assertEquals(0, d2.compareTo(d1));
}
use of com.revolsys.geometry.planargraph.Node in project com.revolsys.open by revolsys.
the class MiscellaneousTest2 method testDirectedEdgeToEdges.
public void testDirectedEdgeToEdges() {
final DirectedEdge d1 = new DirectedEdge(new Node(0, 0), new Node(10, 10), new PointDoubleXY(10, 10), true);
final DirectedEdge d2 = new DirectedEdge(new Node(20, 0), new Node(20, 10), new PointDoubleXY(20, 10), false);
final List edges = DirectedEdge.toEdges(Arrays.asList(d1, d2));
assertEquals(2, edges.size());
assertNull(edges.get(0));
assertNull(edges.get(1));
}
use of com.revolsys.geometry.planargraph.Node in project com.revolsys.open by revolsys.
the class ConnectedSubgraphFinder method addEdges.
/**
* Adds the argument node and all its out edges to the subgraph.
* @param node the node to add
* @param nodeStack the current set of nodes being traversed
*/
private void addEdges(final Node node, final Stack nodeStack, final Subgraph subgraph) {
node.setVisited(true);
for (final Object element : node.getOutEdges()) {
final DirectedEdge de = (DirectedEdge) element;
subgraph.add(de.getEdge());
final Node toNode = de.getToNode();
if (!toNode.isVisited()) {
nodeStack.push(toNode);
}
}
}
use of com.revolsys.geometry.planargraph.Node in project com.revolsys.open by revolsys.
the class ConnectedSubgraphFinder method addReachable.
/**
* Adds all nodes and edges reachable from this node to the subgraph.
* Uses an explicit stack to avoid a large depth of recursion.
*
* @param node a node known to be in the subgraph
*/
private void addReachable(final Node startNode, final Subgraph subgraph) {
final Stack nodeStack = new Stack();
nodeStack.add(startNode);
while (!nodeStack.empty()) {
final Node node = (Node) nodeStack.pop();
addEdges(node, nodeStack, subgraph);
}
}
use of com.revolsys.geometry.planargraph.Node in project com.revolsys.open by revolsys.
the class ConnectedSubgraphFinder method getConnectedSubgraphs.
public List getConnectedSubgraphs() {
final List subgraphs = new ArrayList();
GraphComponent.setVisited(this.graph.nodeIterator(), false);
for (final Iterator i = this.graph.edgeIterator(); i.hasNext(); ) {
final Edge e = (Edge) i.next();
final Node node = e.getDirEdge(0).getFromNode();
if (!node.isVisited()) {
subgraphs.add(findSubgraph(node));
}
}
return subgraphs;
}
Aggregations