/** flips an edge in the triangulation and returns the new edge */ public HalfedgeHandle<X> flipEdge(HalfedgeHandle<X> e) { TriangulationDSFace_2<X> f1 = e.getFace(); TriangulationDSFace_2<X> f2 = e.getOpposite().getFace(); // retrieve vertices of quadrangle ArrayList<TriangulationDSVertex_2<X>> vert = new ArrayList<TriangulationDSVertex_2<X>>(); vert.add(f1.vertex(e.index())); vert.add(f1.vertex((e.index() + 1) % 3)); vert.add(f2.vertex(e.getOpposite().index())); vert.add(f1.vertex((e.index() + 2) % 3)); // retrieve neighboring faces of quadrangle ArrayList<TriangulationDSFace_2<X>> neighb = new ArrayList<TriangulationDSFace_2<X>>(); neighb.add(f1.neighbor((e.index() + 2) % 3)); neighb.add(f2.neighbor((e.getOpposite().index() + 1) % 3)); neighb.add(f2.neighbor((e.getOpposite().index() + 2) % 3)); neighb.add(f1.neighbor((e.index() + 1) % 3)); // reset the vertices of the 2 quadrangle faces f1.setVertex(0, vert.get(0)); f1.setVertex(1, vert.get(1)); f1.setVertex(2, vert.get(2)); f2.setVertex(0, vert.get(0)); f2.setVertex(1, vert.get(2)); f2.setVertex(2, vert.get(3)); // reset the incident faces of the quandrangle vertices vert.get(0).setFace(f1); vert.get(1).setFace(f1); vert.get(2).setFace(f2); vert.get(3).setFace(f2); // reset the neighbors of the 2 quadrangle faces f1.setNeighbor(0, neighb.get(1)); f1.setNeighbor(1, f2); f1.setNeighbor(2, neighb.get(0)); f2.setNeighbor(0, neighb.get(2)); f2.setNeighbor(1, neighb.get(3)); f2.setNeighbor(2, f1); // reset the neighbors of the quadrangle neighbors (only modify what needs to be modified) if (neighb.get(1) != null) neighb.get(1).setNeighbor(neighb.get(1).index(f2), f1); if (neighb.get(3) != null) neighb.get(3).setNeighbor(neighb.get(3).index(f1), f2); // reset the marks of the edges of the two faces for (int i = 0; i < 3; i++) { f1.unmark(i); f2.unmark(i); } // restore the marks of the quadrangle edges (or rather their inner halfedges) for (int i = 0; i < 3; i++) { e = new HalfedgeHandle<X>(f1, i); if (f1.neighbor(i) != null) e.setMark(e.getOpposite().isMarked()); e = new HalfedgeHandle<X>(f2, i); if (f2.neighbor(i) != null) e.setMark(e.getOpposite().isMarked()); } // return the new diagonal edge return new HalfedgeHandle<X>(f1, 1); }