public Node split(EmbeddedGraph embeddedGraph, Edge edge) { Graph originalGraph = embeddedGraph.getGraph(); Node newNode = originalGraph.createDummyNode(); originalGraph.removeEdge(edge); List<Edge> newEdges = ListSequence.fromList(new ArrayList<Edge>()); ListSequence.fromList(newEdges).addElement(originalGraph.connect(edge.getSource(), newNode)); ListSequence.fromList(newEdges).addElement(originalGraph.connect(newNode, edge.getTarget())); MapSequence.fromMap(mySplittedEdges).put(edge, newEdges); List<Face> facesToProcess = ListSequence.fromList(new ArrayList<Face>()); ListSequence.fromList(facesToProcess) .addSequence(ListSequence.fromList(embeddedGraph.getAdjacentFaces(edge))); for (Face face : ListSequence.fromList(facesToProcess)) { List<Dart> darts = face.getDarts(); int pos = 0; while (ListSequence.fromList(darts).getElement(pos).getEdge() != edge) { pos++; } Dart dartToReplace = ListSequence.fromList(darts).getElement(pos); for (Edge newEdge : ListSequence.fromList(newEdges)) { if (ListSequence.fromList(newEdge.getAdjacentNodes()).contains(dartToReplace.getSource())) { embeddedGraph.setDart(face, pos, new Dart(newEdge, dartToReplace.getSource())); } } for (Edge newEdge : ListSequence.fromList(newEdges)) { if (ListSequence.fromList(newEdge.getAdjacentNodes()).contains(dartToReplace.getTarget())) { embeddedGraph.insertDart(face, pos + 1, new Dart(newEdge, newNode)); } } } return newNode; }
public EmbeddedGraph find(Graph graph) { mySplittedEdges = MapSequence.fromMap(new HashMap<Edge, List<Edge>>()); EmbeddedGraph embeddedGraph = new EmbeddedGraph(graph); List<Edge> removed = ListSequence.fromList(new ArrayList<Edge>()); Face outerFace = getOuterTreeFace(graph, removed); for (Edge edge : ListSequence.fromList(removed)) { graph.removeEdge(edge); } embeddedGraph.addFace(outerFace); embeddedGraph.setOuterFace(outerFace); for (Edge removedEdge : ListSequence.fromList(removed)) { this.restoreEdge(embeddedGraph, removedEdge); CheckEmbeddedGraph.checkEmbeddedGraph(embeddedGraph, false); } mergeEdges(); return embeddedGraph; }