예제 #1
0
 private void restoreEdge(EmbeddedGraph embeddedGraph, Edge removedEdge) {
   MapSequence.fromMap(mySplittedEdges)
       .put(removedEdge, ListSequence.fromList(new ArrayList<Edge>()));
   Graph graph = embeddedGraph.getGraph();
   DualGraph dualGraph = new DualGraph(embeddedGraph);
   List<Node> newNodes = ListSequence.fromList(new ArrayList<Node>());
   for (Node node : ListSequence.fromList(removedEdge.getAdjacentNodes())) {
     Node newNode = dualGraph.createDummyNode();
     for (Edge nodeEdge : ListSequence.fromList(node.getEdges(Edge.Direction.BOTH))) {
       for (Face face : ListSequence.fromList(embeddedGraph.getAdjacentFaces(nodeEdge))) {
         dualGraph.connect(newNode, MapSequence.fromMap(dualGraph.getNodesMap()).get(face));
       }
     }
     ListSequence.fromList(newNodes).addElement(newNode);
   }
   List<Edge> path =
       ShortestPath.getPath(
           dualGraph,
           ListSequence.fromList(newNodes).getElement(0),
           ListSequence.fromList(newNodes).getElement(1),
           Edge.Direction.BOTH);
   List<Node> nodePath = ListSequence.fromList(new ArrayList<Node>());
   List<Face> facePath = ListSequence.fromList(new ArrayList<Face>());
   ListSequence.fromList(nodePath)
       .addElement(ListSequence.fromList(removedEdge.getAdjacentNodes()).getElement(0));
   Node cur = ListSequence.fromList(newNodes).getElement(0);
   for (Edge edge : ListSequence.fromList(path)) {
     Edge realEdge = MapSequence.fromMap(dualGraph.getEdgesMap()).get(edge);
     if (embeddedGraph.getAdjacentFaces(realEdge) != null) {
       ListSequence.fromList(nodePath)
           .addElement(
               split(embeddedGraph, MapSequence.fromMap(dualGraph.getEdgesMap()).get(edge)));
     }
     cur = edge.getOpposite(cur);
     Face curFace = MapSequence.fromMap(dualGraph.getFacesMap()).get(cur);
     if (curFace != null) {
       ListSequence.fromList(facePath).addElement(curFace);
     }
   }
   ListSequence.fromList(nodePath)
       .addElement(ListSequence.fromList(removedEdge.getAdjacentNodes()).getElement(1));
   for (int i = 0; i < ListSequence.fromList(nodePath).count() - 1; i++) {
     Edge newEdge =
         graph.connect(
             ListSequence.fromList(nodePath).getElement(i),
             ListSequence.fromList(nodePath).getElement(i + 1));
     ListSequence.fromList(MapSequence.fromMap(mySplittedEdges).get(removedEdge))
         .addElement(newEdge);
     splitFace(embeddedGraph, ListSequence.fromList(facePath).getElement(i), newEdge);
   }
 }
 @Override
 protected void preprocessRoot(final Node root) {
   Edge edge = ListSequence.fromList(root.getEdges()).first();
   Dart dart =
       ListSequence.fromList(myEmbeddedGraph.getDarts(edge))
           .findFirst(
               new IWhereFilter<Dart>() {
                 public boolean accept(Dart it) {
                   return it.getSource() == root;
                 }
               });
   MapSequence.fromMap(myDirections).put(dart, Direction2D.RIGHT);
   MapSequence.fromMap(myDirections)
       .put(
           myEmbeddedGraph.getOpposite(dart),
           MapSequence.fromMap(myDirections).get(dart).opposite());
 }
 @Override
 protected void preprocess(final Node node, Edge from) {
   List<Dart> darts =
       ListSequence.fromList(node.getEdges())
           .select(
               new ISelector<Edge, Dart>() {
                 public Dart select(Edge edge) {
                   return ListSequence.fromList(myEmbeddedGraph.getDarts(edge))
                       .findFirst(
                           new IWhereFilter<Dart>() {
                             public boolean accept(Dart dart) {
                               return dart.getSource() == node;
                             }
                           });
                 }
               })
           .toListSequence();
   Dart first =
       ListSequence.fromList(darts)
           .findFirst(
               new IWhereFilter<Dart>() {
                 public boolean accept(Dart dart) {
                   return MapSequence.fromMap(myDirections).containsKey(dart);
                 }
               });
   List<Dart> orderedDarts = ListSequence.fromList(new ArrayList<Dart>());
   ListSequence.fromList(orderedDarts).addElement(first);
   Dart cur = first;
   do {
     Dart next = myEmbeddedGraph.getNextSourceDart(cur);
     MapSequence.fromMap(myDirections)
         .put(
             next,
             MapSequence.fromMap(myDirections)
                 .get(cur)
                 .turnClockwise(MapSequence.fromMap(myAngles).get(cur)));
     MapSequence.fromMap(myDirections)
         .put(
             myEmbeddedGraph.getOpposite(next),
             MapSequence.fromMap(myDirections).get(next).opposite());
     cur = next;
   } while (cur != first);
 }