Program: 86566
Project: 86566
Buggy source:
/** 
 * Connect a point to a degenerated edge, or to a set of linked degenerated edges.
 * @param iter
 * @param point
 * @param tri
 * @param prevAdded
 * @return An edge that could be shared in another triangle with another edge and point. null if such an edge can't exist.
 * @throws DelaunayError
 */
private Edge connectToDegenerated(ListIterator<Edge> iter,Point point,List<DelaunayTriangle> tri,Edge prevAdded,boolean revertDir) throws DelaunayError {
  Edge current=iter.next();
  Edge ret=null;
  Edge mem=null;
  Edge memBis=null;
  LinkedList<Edge> llMem=new LinkedList<Edge>();
  if (current.isColinear(point)) {
    while (current.isColinear(point) && iter.hasNext() && current.isDegenerated()&& !current.isShared()) {
      current=iter.next();
    }
    if (!current.isColinear(point) || !current.isDegenerated()) {
      current=iter.previous();
      current=iter.previous();
      ret=new Edge(current.getEndPoint(),point);
      ret.setDegenerated(true);
      addedEdges.add(ret);
      iter.next();
      iter.add(ret);
      return ret;
    }
 else {
      ret=new Edge(current.getEndPoint(),point);
      ret.setDegenerated(true);
      addedEdges.add(ret);
      iter.add(ret);
      return ret;
    }
  }
  boolean nextReached=false;
  boolean isUpper=current.isLeft(point);
  iter.previous();
  while (iter.hasNext()) {
    current=iter.next();
    if (!current.isDegenerated()) {
      nextReached=true;
      break;
    }
    if (isUpper) {
      if (revertDir) {
        if (mem == null) {
          mem=new Edge(current.getEndPoint(),point);
          ret=mem;
          addedEdges.add(mem);
        }
        memBis=new Edge(point,current.getStartPoint());
        addedEdges.add(memBis);
        tri.add(new DelaunayTriangle(current,memBis,mem));
        mem=memBis;
        current.setDegenerated(false);
        iter.remove();
      }
 else {
        if (mem == null) {
          ret=new Edge(point,current.getStartPoint());
          mem=ret;
        }
        memBis=new Edge(current.getEndPoint(),point);
        tri.add(new DelaunayTriangle(current,memBis,mem));
        mem=memBis;
        current.setDegenerated(false);
      }
    }
 else {
      if (!revertDir) {
        llMem.addFirst(current);
      }
      current.swap();
      iter.remove();
      if (mem == null) {
        mem=new Edge(current.getEndPoint(),point);
        if (prevAdded != null && mem.equals(prevAdded)) {
          mem=prevAdded;
        }
 else {
          addedEdges.add(mem);
          iter.add(mem);
        }
      }
      memBis=new Edge(point,current.getStartPoint());
      addedEdges.add(memBis);
      tri.add(new DelaunayTriangle(mem,memBis,current));
      mem=memBis;
      current.setDegenerated(false);
    }
  }
  if (isUpper) {
    if (nextReached) {
      iter.previous();
    }
    if (revertDir) {
      iter.add(ret);
      ret=mem;
    }
 else {
      iter.add(mem);
    }
  }
 else {
    if (nextReached) {
      iter.previous();
    }
    iter.add(mem);
    for (    Edge ed : llMem) {
      iter.add(ed);
    }
  }
  return ret;
}

Fixed version (ground truth):
/** 
 * Connect a point to a degenerated edge, or to a set of linked degenerated edges.
 * @param iter
 * @param point
 * @param tri
 * @param prevAdded
 * @return An edge that could be shared in another triangle with another edge and point. null if such an edge can't exist.
 * @throws DelaunayError
 */
private Edge connectToDegenerated(ListIterator<Edge> iter,Point point,List<DelaunayTriangle> tri,Edge prevAdded,boolean revertDir) throws DelaunayError {
  Edge current=iter.next();
  Edge ret=null;
  Edge mem=null;
  Edge memBis=null;
  LinkedList<Edge> llMem=new LinkedList<Edge>();
  if (current.isColinear(point)) {
    while (current.isColinear(point) && iter.hasNext() && current.isDegenerated()&& !current.isShared()) {
      current=iter.next();
    }
    if (!current.isColinear(point) || !current.isDegenerated()) {
      current=iter.previous();
      current=iter.previous();
      ret=new Edge(current.getEndPoint(),point);
      ret.setDegenerated(true);
      addedEdges.add(ret);
      iter.next();
      iter.add(ret);
      return ret;
    }
 else {
      ret=new Edge(current.getEndPoint(),point);
      ret.setDegenerated(true);
      addedEdges.add(ret);
      iter.add(ret);
      return ret;
    }
  }
  boolean nextReached=false;
  boolean isUpper=current.isLeft(point);
  iter.previous();
  while (iter.hasNext()) {
    current=iter.next();
    if (!current.isDegenerated()) {
      nextReached=true;
      break;
    }
    if (isUpper) {
      if (revertDir) {
        if (mem == null) {
          mem=new Edge(current.getEndPoint(),point);
          ret=mem;
          addedEdges.add(mem);
        }
        memBis=new Edge(point,current.getStartPoint());
        addedEdges.add(memBis);
        tri.add(new DelaunayTriangle(current,memBis,mem));
        mem=memBis;
        current.setDegenerated(false);
        iter.remove();
      }
 else {
        if (mem == null) {
          ret=new Edge(point,current.getStartPoint());
          mem=ret;
          addedEdges.add(mem);
        }
        memBis=new Edge(current.getEndPoint(),point);
        addedEdges.add(memBis);
        tri.add(new DelaunayTriangle(current,memBis,mem));
        mem=memBis;
        current.setDegenerated(false);
      }
    }
 else {
      if (!revertDir) {
        llMem.addFirst(current);
      }
      current.swap();
      iter.remove();
      if (mem == null) {
        mem=new Edge(current.getEndPoint(),point);
        if (prevAdded != null && mem.equals(prevAdded)) {
          mem=prevAdded;
        }
 else {
          addedEdges.add(mem);
          iter.add(mem);
        }
      }
      memBis=new Edge(point,current.getStartPoint());
      addedEdges.add(memBis);
      tri.add(new DelaunayTriangle(mem,memBis,current));
      mem=memBis;
      current.setDegenerated(false);
    }
  }
  if (isUpper) {
    if (nextReached) {
      iter.previous();
    }
    if (revertDir) {
      iter.add(ret);
      ret=mem;
    }
 else {
      iter.add(mem);
    }
  }
 else {
    if (nextReached) {
      iter.previous();
    }
    iter.add(mem);
    for (    Edge ed : llMem) {
      iter.add(ed);
    }
  }
  return ret;
}