Program: 43045
Project: 43045
Buggy source:
/** 
 * Collapse an edge.
 * @param e   The edge to collapse
 * @param pos The position of the new common vertex
 */
public boolean collapseEdge(int e,Point3d pos,EdgeCollapseParams ecp,EdgeCollapseResult ecr){
  int hR=Edge.getHe(edges,e);
  int v0=HalfEdge.getEnd(hedges,hR);
  int v1=HalfEdge.getStart(hedges,hR);
  int he;
  int hL=HalfEdge.getTwin(hedges,hR);
  int fL=HalfEdge.getLeft(hedges,hL);
  int fR=HalfEdge.getLeft(hedges,hR);
  if (DEBUG)   printf("String_Node_Str",fR,fL);
  int hLp=HalfEdge.getPrev(hedges,hL), hLpt=HalfEdge.getTwin(hedges,hLp), hLn=HalfEdge.getNext(hedges,hL), hLnt=HalfEdge.getTwin(hedges,hLn), hRn=HalfEdge.getNext(hedges,hR), hRnt=HalfEdge.getTwin(hedges,hRn), hRp=HalfEdge.getPrev(hedges,hR), hRpt=HalfEdge.getTwin(hedges,hRp);
  int vR=HalfEdge.getStart(hedges,hRp), vL=HalfEdge.getEnd(hedges,hLn);
  int e1R=HalfEdge.getEdge(hedges,hRp), e1L=HalfEdge.getEdge(hedges,hLn), e0R=HalfEdge.getEdge(hedges,hRn), e0L=HalfEdge.getEdge(hedges,hLp);
  StructSet v1set=m_vset;
  v1set.clear();
  he=HalfEdge.getNext(hedges,hLnt);
  while (he != hRpt) {
    v1set.add(HalfEdge.getEnd(hedges,he));
    he=HalfEdge.getNext(hedges,HalfEdge.getTwin(hedges,he));
  }
  he=HalfEdge.getNext(hedges,hRnt);
  while (he != hLpt) {
    if (v1set.contains(HalfEdge.getEnd(hedges,he))) {
      if (DEBUG)       printf("String_Node_Str");
      ecr.returnCode=EdgeCollapseResult.FAILURE_SURFACE_PINCH;
      return false;
    }
    he=HalfEdge.getNext(hedges,HalfEdge.getTwin(hedges,he));
  }
  he=hLnt;
  Vertex.getPoint(vertices,v1,pv1);
  if (ecp.maxEdgeLength2 > 0.) {
    while (he != hRp) {
      int start=HalfEdge.getStart(hedges,he);
      int next=HalfEdge.getNext(hedges,he);
      Vertex.getPoint(vertices,start,p0);
      Vertex.getPoint(vertices,HalfEdge.getEnd(hedges,next),p1);
      if (pos.distanceSquared(p0) > ecp.maxEdgeLength2) {
        ecr.returnCode=EdgeCollapseResult.FAILURE_LONG_EDGE;
        return false;
      }
      if (m_faceFlipChecker.checkFaceFlip(p0,p1,pv1,pos)) {
        ecr.returnCode=EdgeCollapseResult.FAILURE_FACE_FLIP;
        return false;
      }
      he=HalfEdge.getTwin(hedges,next);
    }
  }
 else {
    while (he != hRp) {
      int start=HalfEdge.getStart(hedges,he);
      int next=HalfEdge.getNext(hedges,he);
      Vertex.getPoint(vertices,start,p0);
      Vertex.getPoint(vertices,HalfEdge.getEnd(hedges,next),p1);
      if (m_faceFlipChecker.checkFaceFlip(p0,p1,pv1,pos)) {
        ecr.returnCode=EdgeCollapseResult.FAILURE_FACE_FLIP;
        return false;
      }
      he=HalfEdge.getTwin(hedges,next);
    }
  }
  he=hRnt;
  Vertex.getPoint(vertices,v0,pv0);
  if (ecp.maxEdgeLength2 > 0.) {
    while (he != hLp) {
      int start=HalfEdge.getStart(hedges,he);
      int next=HalfEdge.getNext(hedges,he);
      Vertex.getPoint(vertices,start,p0);
      Vertex.getPoint(vertices,HalfEdge.getEnd(hedges,next),p1);
      if (pos.distanceSquared(p0) > ecp.maxEdgeLength2) {
        ecr.returnCode=EdgeCollapseResult.FAILURE_LONG_EDGE;
        return false;
      }
      if (m_faceFlipChecker.checkFaceFlip(p0,p1,pv0,pos)) {
        ecr.returnCode=EdgeCollapseResult.FAILURE_FACE_FLIP;
        return false;
      }
      he=HalfEdge.getTwin(hedges,next);
    }
  }
 else {
    while (he != hLp) {
      int start=HalfEdge.getStart(hedges,he);
      int next=HalfEdge.getNext(hedges,he);
      Vertex.getPoint(vertices,start,p0);
      Vertex.getPoint(vertices,HalfEdge.getEnd(hedges,next),p1);
      if (m_faceFlipChecker.checkFaceFlip(p0,p1,pv0,pos)) {
        ecr.returnCode=EdgeCollapseResult.FAILURE_FACE_FLIP;
        return false;
      }
      he=HalfEdge.getTwin(hedges,next);
    }
  }
  Vertex.setPoint(pos.x,pos.y,pos.z,vertices,v1);
  removeEdge(e);
  removeEdge(e0R);
  removeEdge(e0L);
  if (DEBUG) {
    printf("String_Node_Str",v0,v1);
    printf("String_Node_Str",vL,vR);
    printf("String_Node_Str",hL,hR);
    printf("String_Node_Str",hLp,hLpt);
    printf("String_Node_Str",hLn,hLnt);
    printf("String_Node_Str",hRp,hRpt);
    printf("String_Node_Str",hRn,hRnt);
  }
  int end=hLp;
  he=hRnt;
  int maxcount=30;
  if (DEBUG)   printf("String_Node_Str");
  do {
    int next=HalfEdge.getNext(hedges,he);
    if (DEBUG)     printf("String_Node_Str",he,next);
    HalfEdge.setEnd(v1,hedges,he);
    HalfEdge.setStart(v1,hedges,next);
    if (DEBUG)     printf("String_Node_Str",he,next);
    if (--maxcount < 0) {
      printf("String_Node_Str",Vertex.getID(vertices,v0));
      break;
    }
    he=HalfEdge.getTwin(hedges,next);
  }
 while (he != end);
  removeFace(fL);
  removeFace(fR);
  betwin(hRnt,hRpt);
  betwin(hLpt,hLnt);
  HalfEdge.setEdge(e1R,hedges,hRnt);
  Edge.setHe(hRnt,edges,e1R);
  HalfEdge.setEdge(e1L,hedges,hLpt);
  Edge.setHe(hLpt,edges,e1L);
  Vertex.setLink(hLnt,vertices,vL);
  Vertex.setLink(hRnt,vertices,vR);
  Vertex.setLink(hRpt,vertices,v1);
  Edge.setHe(-1,edges,e);
  Edge.setHe(-1,edges,e0L);
  Edge.setHe(-1,edges,e0R);
  if (DEBUG)   printf("String_Node_Str",Vertex.getID(vertices,v0));
  removeVertex(v0);
  ecr.removedEdges[0]=e;
  ecr.removedEdges[1]=e0L;
  ecr.removedEdges[2]=e0R;
  ecr.insertedVertex=v1;
  ecr.faceCount=2;
  ecr.edgeCount=3;
  ecr.vertexCount=1;
  ecr.returnCode=EdgeCollapseResult.SUCCESS;
  return true;
}

Fixed version (ground truth):
/** 
 * Collapse an edge.
 * @param e   The edge to collapse
 * @param pos The position of the new common vertex
 */
public boolean collapseEdge(int e,Point3d pos,EdgeCollapseParams ecp,EdgeCollapseResult ecr){
  collapseCnt++;
  int hR=Edge.getHe(edges,e);
  int v0=HalfEdge.getEnd(hedges,hR);
  int v1=HalfEdge.getStart(hedges,hR);
  int he;
  int hL=HalfEdge.getTwin(hedges,hR);
  int fL=HalfEdge.getLeft(hedges,hL);
  int fR=HalfEdge.getLeft(hedges,hR);
  if (DEBUG)   printf("String_Node_Str",fR,fL);
  int hLp=HalfEdge.getPrev(hedges,hL), hLpt=HalfEdge.getTwin(hedges,hLp), hLn=HalfEdge.getNext(hedges,hL), hLnt=HalfEdge.getTwin(hedges,hLn), hRn=HalfEdge.getNext(hedges,hR), hRnt=HalfEdge.getTwin(hedges,hRn), hRp=HalfEdge.getPrev(hedges,hR), hRpt=HalfEdge.getTwin(hedges,hRp);
  int vR=HalfEdge.getStart(hedges,hRp), vL=HalfEdge.getEnd(hedges,hLn);
  int e1R=HalfEdge.getEdge(hedges,hRp), e1L=HalfEdge.getEdge(hedges,hLn), e0R=HalfEdge.getEdge(hedges,hRn), e0L=HalfEdge.getEdge(hedges,hLp);
  StructSet v1set=m_vset;
  v1set.clear();
  he=HalfEdge.getNext(hedges,hLnt);
  while (he != hRpt) {
    v1set.add(HalfEdge.getEnd(hedges,he));
    he=HalfEdge.getNext(hedges,HalfEdge.getTwin(hedges,he));
  }
  he=HalfEdge.getNext(hedges,hRnt);
  while (he != hLpt) {
    if (v1set.contains(HalfEdge.getEnd(hedges,he))) {
      if (DEBUG)       printf("String_Node_Str");
      ecr.returnCode=EdgeCollapseResult.FAILURE_SURFACE_PINCH;
      return false;
    }
    he=HalfEdge.getNext(hedges,HalfEdge.getTwin(hedges,he));
  }
  he=hLnt;
  Vertex.getPoint(vertices,v1,pv1);
  if (ecp.maxEdgeLength2 > 0.) {
    while (he != hRp) {
      int start=HalfEdge.getStart(hedges,he);
      int next=HalfEdge.getNext(hedges,he);
      Vertex.getPoint(vertices,start,p0);
      Vertex.getPoint(vertices,HalfEdge.getEnd(hedges,next),p1);
      if (pos.distanceSquared(p0) > ecp.maxEdgeLength2) {
        ecr.returnCode=EdgeCollapseResult.FAILURE_LONG_EDGE;
        return false;
      }
      if (m_faceFlipChecker.checkFaceFlip(p0,p1,pv1,pos)) {
        ecr.returnCode=EdgeCollapseResult.FAILURE_FACE_FLIP;
        return false;
      }
      he=HalfEdge.getTwin(hedges,next);
    }
  }
 else {
    while (he != hRp) {
      int start=HalfEdge.getStart(hedges,he);
      int next=HalfEdge.getNext(hedges,he);
      Vertex.getPoint(vertices,start,p0);
      Vertex.getPoint(vertices,HalfEdge.getEnd(hedges,next),p1);
      if (m_faceFlipChecker.checkFaceFlip(p0,p1,pv1,pos)) {
        ecr.returnCode=EdgeCollapseResult.FAILURE_FACE_FLIP;
        return false;
      }
      he=HalfEdge.getTwin(hedges,next);
    }
  }
  he=hRnt;
  Vertex.getPoint(vertices,v0,pv0);
  if (ecp.maxEdgeLength2 > 0.) {
    while (he != hLp) {
      int start=HalfEdge.getStart(hedges,he);
      int next=HalfEdge.getNext(hedges,he);
      Vertex.getPoint(vertices,start,p0);
      Vertex.getPoint(vertices,HalfEdge.getEnd(hedges,next),p1);
      if (pos.distanceSquared(p0) > ecp.maxEdgeLength2) {
        ecr.returnCode=EdgeCollapseResult.FAILURE_LONG_EDGE;
        return false;
      }
      if (m_faceFlipChecker.checkFaceFlip(p0,p1,pv0,pos)) {
        ecr.returnCode=EdgeCollapseResult.FAILURE_FACE_FLIP;
        return false;
      }
      he=HalfEdge.getTwin(hedges,next);
    }
  }
 else {
    while (he != hLp) {
      int start=HalfEdge.getStart(hedges,he);
      int next=HalfEdge.getNext(hedges,he);
      Vertex.getPoint(vertices,start,p0);
      Vertex.getPoint(vertices,HalfEdge.getEnd(hedges,next),p1);
      if (m_faceFlipChecker.checkFaceFlip(p0,p1,pv0,pos)) {
        ecr.returnCode=EdgeCollapseResult.FAILURE_FACE_FLIP;
        return false;
      }
      he=HalfEdge.getTwin(hedges,next);
    }
  }
  Vertex.setPoint(pos.x,pos.y,pos.z,vertices,v1);
  removeEdge(e);
  removeEdge(e0R);
  removeEdge(e0L);
  if (DEBUG) {
    printf("String_Node_Str",v0,v1);
    printf("String_Node_Str",vL,vR);
    printf("String_Node_Str",hL,hR);
    printf("String_Node_Str",hLp,hLpt);
    printf("String_Node_Str",hLn,hLnt);
    printf("String_Node_Str",hRp,hRpt);
    printf("String_Node_Str",hRn,hRnt);
  }
  int end=hLp;
  he=hRnt;
  int maxcount=30;
  if (DEBUG)   printf("String_Node_Str");
  do {
    int next=HalfEdge.getNext(hedges,he);
    if (DEBUG)     printf("String_Node_Str",he,next);
    HalfEdge.setEnd(v1,hedges,he);
    HalfEdge.setStart(v1,hedges,next);
    if (DEBUG)     printf("String_Node_Str",he,next);
    if (--maxcount < 0) {
      printf("String_Node_Str",Vertex.getID(vertices,v0));
      break;
    }
    he=HalfEdge.getTwin(hedges,next);
  }
 while (he != end);
  removeFace(fL);
  removeFace(fR);
  betwin(hRnt,hRpt);
  betwin(hLpt,hLnt);
  HalfEdge.setEdge(e1R,hedges,hRnt);
  Edge.setHe(hRnt,edges,e1R);
  HalfEdge.setEdge(e1L,hedges,hLpt);
  Edge.setHe(hLpt,edges,e1L);
  Vertex.setLink(hLnt,vertices,vL);
  Vertex.setLink(hRnt,vertices,vR);
  Vertex.setLink(hRpt,vertices,v1);
  Edge.setHe(-1,edges,e);
  Edge.setHe(-1,edges,e0L);
  Edge.setHe(-1,edges,e0R);
  if (DEBUG)   printf("String_Node_Str",Vertex.getID(vertices,v0));
  removeVertex(v0);
  ecr.removedEdges[0]=e;
  ecr.removedEdges[1]=e0L;
  ecr.removedEdges[2]=e0R;
  ecr.insertedVertex=v1;
  ecr.faceCount=2;
  ecr.edgeCount=3;
  ecr.vertexCount=1;
  ecr.returnCode=EdgeCollapseResult.SUCCESS;
  return true;
}