Program: 70648
Project: 70648
Buggy source:
/** 
 * Sqrt-3 subdivision
 * @param mesh mesh to subdivide
 * @param even set first iteration to an "even" split, where borders are not divided
 * @param niters number of iterations
 */
public static void sqrt3Subdivide(PolygonalMesh mesh,boolean even,int niters){
  if (!mesh.isTriangular()) {
    mesh.triangulate();
  }
  boolean splitBorders=!even;
  ArrayList<VertexData> vdata=new ArrayList<VertexData>(mesh.numVertices());
  HashMap<Vertex3d,HashSet<Vertex3d>> borderNeighbors=new HashMap<>();
  for (  Vertex3d vtx : mesh.getVertices()) {
    Vertex3d[] nbrs=new Vertex3d[2];
    int nborders=0;
    HalfEdgeNode hen=vtx.incidentHedges;
    while (hen != null) {
      HalfEdge he=hen.he;
      if (isBorderEdge(he)) {
        if (nborders == 0) {
          nbrs[0]=he.tail;
          ++nborders;
        }
 else         if (nborders == 1) {
          if (he.tail != nbrs[0]) {
            nbrs[1]=he.tail;
            ++nborders;
          }
        }
 else {
          ++nborders;
          break;
        }
      }
      if (he.next.opposite == null) {
        if (nborders == 0) {
          nbrs[0]=he.next.head;
          ++nborders;
        }
 else         if (nborders == 1) {
          if (he.next.head != nbrs[0]) {
            nbrs[1]=he.next.head;
            ++nborders;
          }
        }
 else {
          ++nborders;
          break;
        }
      }
      hen=hen.next;
    }
    if (nborders == 0) {
      vdata.add(new CentralVertexData(vtx));
    }
 else     if (nborders == 1) {
      vdata.add(new BorderVertexData(null,vtx,nbrs[0]));
    }
 else     if (nborders == 2) {
      vdata.add(new BorderVertexData(nbrs[0],vtx,nbrs[1]));
    }
 else {
      vdata.add(new BorderVertexData(null,vtx,null));
    }
  }
  for (  Face face : mesh.getFaces()) {
    HalfEdge he0=face.he0;
    HalfEdge he=he0;
    do {
      he.clearVisited();
      he=he.next;
    }
 while (he != he0);
  }
  for (int k=0; k < niters; ++k) {
    int oldNumVertices=mesh.numVertices();
    int nFaces=mesh.numFaces();
    for (int i=0; i < nFaces; ++i) {
      Face face=mesh.getFace(i);
      if (splitBorders && isBorderEdge(face.he0)) {
        HalfEdge he=face.he0;
        if (he.opposite == null || he.opposite.face.getIndex() < face.getIndex()) {
          Vertex3d head=he.head;
          Vertex3d tail=he.tail;
          BorderVertexData headData=(BorderVertexData)vdata.get(head.getIndex());
          BorderVertexData tailData=(BorderVertexData)vdata.get(tail.getIndex());
          Vertex3d left=tailData.getOtherNeighbour(head);
          Vertex3d right=headData.getOtherNeighbour(tail);
          HalfEdge be0=edgeSplit3(face.he0);
          HalfEdge be1=be0.next.opposite.next;
          HalfEdge be2=be1.next.opposite.next;
          if (left != null) {
            Point3d b0=be0.head.getPosition();
            Point3d lpos=left.getPosition();
            Point3d cpos=tail.getPosition();
            Point3d rpos=head.getPosition();
            b0.x=(1.0 * lpos.x + 16.0 * cpos.x + 10.0 * rpos.x) / 27.0;
            b0.y=(1.0 * lpos.y + 16.0 * cpos.y + 10.0 * rpos.y) / 27.0;
            b0.z=(1.0 * lpos.z + 16.0 * cpos.z + 10.0 * rpos.z) / 27.0;
          }
          if (right != null) {
            Point3d b1=be1.head.getPosition();
            Point3d lpos=tail.getPosition();
            Point3d cpos=head.getPosition();
            Point3d rpos=right.getPosition();
            b1.x=(1.0 * rpos.x + 16.0 * cpos.x + 10.0 * lpos.x) / 27.0;
            b1.y=(1.0 * rpos.y + 16.0 * cpos.y + 10.0 * lpos.y) / 27.0;
            b1.z=(1.0 * rpos.z + 16.0 * cpos.z + 10.0 * lpos.z) / 27.0;
          }
          headData.queueNeighbour(tail,be2.tail);
          tailData.queueNeighbour(head,be0.head);
          vdata.add(new BorderVertexData(be0.tail,be0.head,be1.tail));
          vdata.add(new BorderVertexData(be1.tail,be1.head,be2.tail));
        }
      }
 else {
        Vertex3d vtxm=midpointSplit(face);
        vdata.add(new CentralVertexData(vtxm));
      }
    }
    for (    Face f : mesh.getFaces()) {
      HalfEdge he0=f.he0;
      if (!isBorderEdge(he0)) {
        he0.setVisited();
      }
    }
    nFaces=mesh.numFaces();
    for (int i=0; i < nFaces; ++i) {
      Face face=mesh.getFace(i);
      HalfEdge he=face.he0;
      if (he.isVisited() && (he.opposite.face.getIndex() < face.getIndex() || isBorderEdge(he.opposite.face.he0))) {
        rotateEdge(he);
        he.clearVisited();
        he.opposite.clearVisited();
        if (he.face.he0 != he) {
          he.face.he0=he;
        }
        HalfEdge be=he.next;
        do {
          if (isBorderEdge(be)) {
            he.face.he0=be;
            break;
          }
          be=be.next;
        }
 while (be != he);
        HalfEdge te=he.opposite;
        if (te.face.he0 != te) {
          te.face.he0=te;
        }
        be=te.next;
        do {
          if (isBorderEdge(be)) {
            te.face.he0=be;
            break;
          }
          be=be.next;
        }
 while (be != te);
      }
    }
    for (int i=0; i < oldNumVertices; ++i) {
      VertexData dat=vdata.get(i);
      if (splitBorders || !dat.isBorder()) {
        dat.relax();
      }
    }
    splitBorders=!splitBorders;
  }
  mesh.notifyStructureChanged();
  mesh.notifyVertexPositionsModified();
}

Fixed version (ground truth):
/** 
 * Sqrt-3 subdivision
 * @param mesh mesh to subdivide
 * @param even set first iteration to an "even" split, where borders are not divided
 * @param niters number of iterations
 */
public static void sqrt3Subdivide(PolygonalMesh mesh,boolean even,int niters){
  if (!mesh.isTriangular()) {
    mesh.triangulate();
  }
  boolean splitBorders=!even;
  ArrayList<VertexData> vdata=new ArrayList<VertexData>(mesh.numVertices());
  HashMap<Vertex3d,HashSet<Vertex3d>> borderNeighbors=new HashMap<>();
  for (  Vertex3d vtx : mesh.getVertices()) {
    Vertex3d[] nbrs=new Vertex3d[2];
    int nborders=0;
    HashSet<Vertex3d> opposites=new HashSet<>();
    HalfEdgeNode hen=vtx.incidentHedges;
    while (hen != null) {
      HalfEdge he=hen.he;
      if (opposites.contains(he.tail)) {
        nborders=-1;
        break;
      }
 else {
        opposites.add(he.tail);
      }
      if (isBorderEdge(he)) {
        if (nborders == 0) {
          nbrs[0]=he.tail;
          ++nborders;
        }
 else         if (nborders == 1) {
          if (he.tail != nbrs[0]) {
            nbrs[1]=he.tail;
            ++nborders;
          }
        }
 else {
          ++nborders;
          break;
        }
      }
      if (he.next.opposite == null) {
        if (opposites.contains(he.next.head)) {
          nborders=-1;
          break;
        }
 else {
          opposites.add(he.next.head);
        }
        if (nborders == 0) {
          nbrs[0]=he.next.head;
          ++nborders;
        }
 else         if (nborders == 1) {
          if (he.next.head != nbrs[0]) {
            nbrs[1]=he.next.head;
            ++nborders;
          }
        }
 else {
          ++nborders;
          break;
        }
      }
      hen=hen.next;
    }
    if (nborders == 0) {
      vdata.add(new CentralVertexData(vtx));
    }
 else     if (nborders == 1) {
      vdata.add(new BorderVertexData(null,vtx,nbrs[0]));
    }
 else     if (nborders == 2) {
      vdata.add(new BorderVertexData(nbrs[0],vtx,nbrs[1]));
    }
 else {
      vdata.add(new BorderVertexData(null,vtx,null));
    }
  }
  for (  Face face : mesh.getFaces()) {
    HalfEdge he0=face.he0;
    HalfEdge he=he0;
    do {
      he.clearVisited();
      he=he.next;
    }
 while (he != he0);
  }
  for (int k=0; k < niters; ++k) {
    int oldNumVertices=mesh.numVertices();
    int nFaces=mesh.numFaces();
    for (int i=0; i < nFaces; ++i) {
      Face face=mesh.getFace(i);
      if (splitBorders && isBorderEdge(face.he0)) {
        HalfEdge he=face.he0;
        if (he.opposite == null || he.opposite.face.getIndex() < face.getIndex()) {
          Vertex3d head=he.head;
          Vertex3d tail=he.tail;
          Vertex3d left=null;
          Vertex3d right=null;
          VertexData vdat=vdata.get(head.getIndex());
          BorderVertexData headData=null;
          if (vdat.isBorder()) {
            headData=(BorderVertexData)vdat;
            right=headData.getOtherNeighbour(tail);
          }
 else {
            System.out.println("String_Node_Str" + head.getIndex());
          }
          vdat=vdata.get(tail.getIndex());
          BorderVertexData tailData=null;
          if (vdat.isBorder()) {
            tailData=(BorderVertexData)vdat;
            left=tailData.getOtherNeighbour(head);
          }
 else {
            System.out.println("String_Node_Str" + tail.getIndex());
          }
          HalfEdge be0=edgeSplit3(face.he0);
          HalfEdge be1=be0.next.opposite.next;
          HalfEdge be2=be1.next.opposite.next;
          if (left != null) {
            Point3d b0=be0.head.getPosition();
            Point3d lpos=left.getPosition();
            Point3d cpos=tail.getPosition();
            Point3d rpos=head.getPosition();
            b0.x=(1.0 * lpos.x + 16.0 * cpos.x + 10.0 * rpos.x) / 27.0;
            b0.y=(1.0 * lpos.y + 16.0 * cpos.y + 10.0 * rpos.y) / 27.0;
            b0.z=(1.0 * lpos.z + 16.0 * cpos.z + 10.0 * rpos.z) / 27.0;
          }
          if (right != null) {
            Point3d b1=be1.head.getPosition();
            Point3d lpos=tail.getPosition();
            Point3d cpos=head.getPosition();
            Point3d rpos=right.getPosition();
            b1.x=(1.0 * rpos.x + 16.0 * cpos.x + 10.0 * lpos.x) / 27.0;
            b1.y=(1.0 * rpos.y + 16.0 * cpos.y + 10.0 * lpos.y) / 27.0;
            b1.z=(1.0 * rpos.z + 16.0 * cpos.z + 10.0 * lpos.z) / 27.0;
          }
          if (headData != null) {
            headData.queueNeighbour(tail,be2.tail);
          }
          if (tailData != null) {
            tailData.queueNeighbour(head,be0.head);
          }
          vdata.add(new BorderVertexData(be0.tail,be0.head,be1.tail));
          vdata.add(new BorderVertexData(be1.tail,be1.head,be2.tail));
        }
      }
 else {
        Vertex3d vtxm=midpointSplit(face);
        vdata.add(new CentralVertexData(vtxm));
      }
    }
    for (    Face f : mesh.getFaces()) {
      HalfEdge he0=f.he0;
      if (!isBorderEdge(he0)) {
        he0.setVisited();
      }
    }
    nFaces=mesh.numFaces();
    for (int i=0; i < nFaces; ++i) {
      Face face=mesh.getFace(i);
      HalfEdge he=face.he0;
      if (he.isVisited() && (he.opposite.face.getIndex() < face.getIndex() || isBorderEdge(he.opposite.face.he0))) {
        rotateEdge(he);
        he.clearVisited();
        he.opposite.clearVisited();
        if (he.face.he0 != he) {
          he.face.he0=he;
        }
        HalfEdge be=he.next;
        do {
          if (isBorderEdge(be)) {
            he.face.he0=be;
            break;
          }
          be=be.next;
        }
 while (be != he);
        HalfEdge te=he.opposite;
        if (te.face.he0 != te) {
          te.face.he0=te;
        }
        be=te.next;
        do {
          if (isBorderEdge(be)) {
            te.face.he0=be;
            break;
          }
          be=be.next;
        }
 while (be != te);
      }
    }
    for (int i=0; i < oldNumVertices; ++i) {
      VertexData dat=vdata.get(i);
      if (splitBorders || !dat.isBorder()) {
        dat.relax();
      }
    }
    splitBorders=!splitBorders;
  }
  mesh.notifyStructureChanged();
  mesh.notifyVertexPositionsModified();
}