示例#1
0
  /**
   * splits the facet incident to h and g into two facets with a new diagonal between the two
   * vertices denoted by h and g respectively. The second (new) facet is a copy of the first facet.
   * Returns h->next() after the operation, i.e., the new diagonal. The new face is to the right of
   * the new diagonal, the old face is to the left. The time is proportional to the distance from h
   * to g around the facet.
   */
  public Halfedge splitFacet(Halfedge h, Halfedge g) {
    if (h == null || g == null) throw new Error("splitFacet: null pointer");
    if (h.face != g.face) throw new Error("splitFacet: different incident facets");
    if (h == g || h.next == g || g.next == h) {
      throw new Error("loops and multiple edges are not allowed");
    }

    Halfedge<X> newDiagonal = new Halfedge<X>();
    Halfedge<X> oppositeNewDiagonal = new Halfedge<X>();
    Face<X> newFace = new Face<X>();

    newFace.halfedge = g;
    newDiagonal.opposite = oppositeNewDiagonal;
    oppositeNewDiagonal.opposite = newDiagonal;
    newDiagonal.face = h.face;
    oppositeNewDiagonal.face = newFace;

    // a completer

    Halfedge p = h.next;
    while (p != g) {
      p.face = newFace;
      p = p.next;
    }

    h.next = newDiagonal;
    g.next = oppositeNewDiagonal;
    return newDiagonal;
  }