Program: 86568
Project: 86568
Buggy source:
/** 
 * This method will force the integrity of the constraints used to compute the delaunay triangulation. After execution : * duplicates are removed * intersection points are added to the mesh points * secant edges are split
 */
public final void forceConstraintIntegrity() throws DelaunayError {
  ArrayList<Point> eventPoints=new ArrayList<Point>();
  for (  Edge edge : constraintEdges) {
    addToSortedList(edge.getStart(),eventPoints,-2);
    addToSortedList(edge.getEnd(),eventPoints,-2);
  }
  Point currentEvent=null;
  VerticalList edgeBuffer=new VerticalList(0);
  List<Edge> edgeMemory=constraintEdges;
  constraintEdges=new ArrayList<Edge>();
  double abs;
  int i=0;
  int j=0;
  Edge e1, e2;
  Edge inter1=null;
  Edge inter2=null;
  Edge inter3=null;
  Edge inter4=null;
  Point newEvent=null;
  Edge edgeEvent=null;
  Point leftMost=null;
  Point rightMost=null;
  Element intersection=null;
  Edge currentMemEdge=null;
  Edge rm;
  int memoryPos=0;
  int rmCount;
  int mem;
  while (i < eventPoints.size()) {
    currentEvent=eventPoints.get(i);
    abs=currentEvent.getX();
    edgeBuffer.setAbs(abs);
    if (currentMemEdge == null) {
      currentMemEdge=edgeMemory.get(0);
    }
    for (; memoryPos < edgeMemory.size(); memoryPos++) {
      currentMemEdge=edgeMemory.get(memoryPos);
      if (currentEvent.equals2D(currentMemEdge.getPointLeft())) {
        edgeBuffer.addEdge(currentMemEdge);
      }
 else {
        break;
      }
    }
    if (edgeBuffer.size() > 1) {
      e2=edgeBuffer.get(0);
      j=1;
      while (j < edgeBuffer.size()) {
        j=j < 1 ? 1 : j;
        e1=edgeBuffer.get(j - 1);
        e2=edgeBuffer.get(j);
        intersection=e1.getIntersection(e2);
        rmCount=0;
        if (intersection instanceof Point) {
          newEvent=(Point)intersection;
          if (!e1.isExtremity(newEvent) || !e2.isExtremity(newEvent)) {
            if (newEvent.equals2D(currentEvent)) {
              if (!newEvent.equals2D(e2.getPointLeft()) && !newEvent.equals2D(e2.getPointRight())) {
                inter2=new Edge(e2.getPointLeft(),newEvent);
                addConstraintEdge(inter2);
                rm=edgeBuffer.remove(j);
                if (!rm.equals(e2)) {
                  throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
                }
                inter4=new Edge(e2.getPointRight(),newEvent);
                edgeBuffer.addEdge(inter4);
                rmCount++;
              }
 else               if (newEvent.equals2D(e2.getPointRight())) {
                addConstraintEdge(e2);
                rm=edgeBuffer.remove(j);
                if (!rm.equals(e2)) {
                  throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
                }
                rmCount++;
              }
              if (!newEvent.equals2D(e1.getPointLeft()) && !newEvent.equals2D(e1.getPointRight())) {
                inter1=new Edge(e1.getPointLeft(),newEvent);
                addConstraintEdge(inter1);
                rm=edgeBuffer.remove(j - 1);
                if (!rm.equals(e1)) {
                  throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
                }
                inter3=new Edge(e1.getPointRight(),newEvent);
                edgeBuffer.addEdge(inter3);
                rmCount++;
              }
 else               if (newEvent.equals2D(e1.getPointRight())) {
                addConstraintEdge(e1);
                rm=edgeBuffer.remove(j - 1);
                if (!rm.equals(e1)) {
                  throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
                }
                rmCount++;
              }
              j=(j - rmCount < 0 ? 0 : j - rmCount);
            }
 else {
              addToSortedList(newEvent,eventPoints,-2);
            }
          }
 else {
            if (e2.getPointRight().equals2D(currentEvent)) {
              addConstraintEdge(e2);
              rm=edgeBuffer.remove(j);
              if (!rm.equals(e2)) {
                throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
              }
              rmCount++;
            }
            if (e1.getPointRight().equals2D(currentEvent)) {
              addConstraintEdge(e1);
              rm=edgeBuffer.remove(j - 1);
              if (!rm.equals(e1)) {
                throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
              }
              rmCount++;
            }
            j=(j - rmCount < 0 ? 0 : j - rmCount);
          }
        }
 else         if (intersection instanceof Edge) {
          edgeEvent=(Edge)intersection;
          newEvent=edgeEvent.getPointLeft();
          if (newEvent.equals2D(currentEvent)) {
            leftMost=(e1.getPointLeft().compareTo2D(e2.getPointLeft()) < 1 ? e1.getPointLeft() : e2.getPointLeft());
            rightMost=(e1.getPointRight().compareTo2D(e2.getPointRight()) < 1 ? e2.getPointRight() : e1.getPointRight());
            inter1=null;
            inter2=null;
            inter3=null;
            rm=edgeBuffer.remove(j);
            if (!rm.equals(e2)) {
              throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
            }
            rm=edgeBuffer.remove(j - 1);
            if (!rm.equals(e1)) {
              throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
            }
            j--;
            if (leftMost.compareTo2D(newEvent) == -1) {
              inter1=new Edge(leftMost,newEvent);
            }
            inter2=edgeEvent;
            if (rightMost.compareTo2D(edgeEvent.getPointRight()) == 1) {
              inter3=new Edge(edgeEvent.getPointRight(),rightMost);
            }
            if (inter1 != null) {
              if (inter1.getPointRight().compareTo2D(currentEvent) == 1) {
                addConstraintEdge(inter1);
              }
 else {
                mem=edgeBuffer.addEdge(inter1);
                j=j <= mem ? j : mem;
              }
            }
            if (inter2.getPointRight().compareTo2D(currentEvent) == 1) {
              mem=edgeBuffer.addEdge(inter2);
              j=j <= mem ? j : mem;
            }
 else {
              addConstraintEdge(inter2);
            }
            if (inter3 != null) {
              addEdgeToLeftSortedList(edgeMemory,inter3);
            }
            j=j - 2 < 0 ? 0 : j - 2;
          }
 else {
            throw new DelaunayError("String_Node_Str");
          }
        }
 else {
          if (e1.getPointRight().equals2D(currentEvent)) {
            addConstraintEdge(e1);
            rm=edgeBuffer.remove(j - 1);
            if (!rm.equals(e1)) {
              throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
            }
            j--;
            j=j - 1 < 0 ? 0 : j - 1;
          }
        }
        j++;
      }
    }
 else     if (edgeBuffer.size() == 1 && edgeBuffer.get(0).getPointRight().equals2D(currentEvent)) {
      addConstraintEdge(edgeBuffer.get(0));
      edgeBuffer.remove(0);
    }
    i++;
  }
}

Fixed version (ground truth):
/** 
 * This method will force the integrity of the constraints used to compute the delaunay triangulation. After execution : * duplicates are removed * intersection points are added to the mesh points * secant edges are split
 */
public final void forceConstraintIntegrity() throws DelaunayError {
  ArrayList<Point> eventPoints=new ArrayList<Point>();
  for (  Edge edge : constraintEdges) {
    addToSortedList(edge.getStart(),eventPoints,-2);
    addToSortedList(edge.getEnd(),eventPoints,-2);
  }
  Point currentEvent=null;
  VerticalList edgeBuffer=new VerticalList(0);
  List<Edge> edgeMemory=constraintEdges;
  constraintEdges=new ArrayList<Edge>();
  double abs;
  int i=0;
  int j=0;
  Edge e1, e2;
  Edge inter1=null;
  Edge inter2=null;
  Edge inter3=null;
  Edge inter4=null;
  Point newEvent=null;
  Edge edgeEvent=null;
  Point leftMost=null;
  Point rightMost=null;
  Element intersection=null;
  Edge currentMemEdge=null;
  Edge rm;
  int memoryPos=0;
  int rmCount;
  int mem;
  while (i < eventPoints.size()) {
    currentEvent=eventPoints.get(i);
    abs=currentEvent.getX();
    edgeBuffer.setAbs(abs);
    if (currentMemEdge == null) {
      currentMemEdge=edgeMemory.get(0);
    }
    for (; memoryPos < edgeMemory.size(); memoryPos++) {
      currentMemEdge=edgeMemory.get(memoryPos);
      if (currentEvent.equals2D(currentMemEdge.getPointLeft())) {
        edgeBuffer.addEdge(currentMemEdge);
      }
 else {
        break;
      }
    }
    if (edgeBuffer.size() > 1) {
      e2=edgeBuffer.get(0);
      j=1;
      while (j < edgeBuffer.size()) {
        j=j < 1 ? 1 : j;
        e1=edgeBuffer.get(j - 1);
        e2=edgeBuffer.get(j);
        intersection=e1.getIntersection(e2);
        rmCount=0;
        if (intersection instanceof Point) {
          newEvent=(Point)intersection;
          if (!e1.isExtremity(newEvent) || !e2.isExtremity(newEvent)) {
            if (newEvent.equals2D(currentEvent)) {
              if (!newEvent.equals2D(e2.getPointLeft()) && !newEvent.equals2D(e2.getPointRight())) {
                if (newEvent.equals2D(e1.getPointLeft())) {
                  newEvent=e1.getPointLeft();
                }
                if (newEvent.equals2D(e1.getPointRight())) {
                  newEvent=e1.getPointRight();
                }
                inter2=new Edge(newEvent,e2.getPointLeft());
                addConstraintEdge(inter2);
                rm=edgeBuffer.remove(j);
                if (!rm.equals(e2)) {
                  throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
                }
                inter4=new Edge(newEvent,e2.getPointRight());
                edgeBuffer.addEdge(inter4);
                rmCount++;
              }
 else               if (newEvent.equals2D(e2.getPointRight())) {
                addConstraintEdge(e2);
                rm=edgeBuffer.remove(j);
                if (!rm.equals(e2)) {
                  throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
                }
                rmCount++;
              }
              if (!newEvent.equals2D(e1.getPointLeft()) && !newEvent.equals2D(e1.getPointRight())) {
                if (newEvent.equals2D(e2.getPointLeft())) {
                  newEvent=e2.getPointLeft();
                }
                if (newEvent.equals2D(e2.getPointRight())) {
                  newEvent=e2.getPointRight();
                }
                inter1=new Edge(e1.getPointLeft(),newEvent);
                addConstraintEdge(inter1);
                rm=edgeBuffer.remove(j - 1);
                if (!rm.equals(e1)) {
                  throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
                }
                inter3=new Edge(e1.getPointRight(),newEvent);
                edgeBuffer.addEdge(inter3);
                rmCount++;
              }
 else               if (newEvent.equals2D(e1.getPointRight())) {
                addConstraintEdge(e1);
                rm=edgeBuffer.remove(j - 1);
                if (!rm.equals(e1)) {
                  throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
                }
                rmCount++;
              }
              j=(j - rmCount < 0 ? 0 : j - rmCount);
            }
 else {
              addToSortedList(newEvent,eventPoints,-2);
            }
          }
 else {
            if (e2.getPointRight().equals2D(currentEvent)) {
              addConstraintEdge(e2);
              rm=edgeBuffer.remove(j);
              if (!rm.equals(e2)) {
                throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
              }
              rmCount++;
            }
            if (e1.getPointRight().equals2D(currentEvent)) {
              addConstraintEdge(e1);
              rm=edgeBuffer.remove(j - 1);
              if (!rm.equals(e1)) {
                throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
              }
              rmCount++;
            }
            j=(j - rmCount < 0 ? 0 : j - rmCount);
          }
        }
 else         if (intersection instanceof Edge) {
          edgeEvent=(Edge)intersection;
          newEvent=edgeEvent.getPointLeft();
          if (newEvent.equals2D(currentEvent)) {
            leftMost=(e1.getPointLeft().compareTo2D(e2.getPointLeft()) < 1 ? e1.getPointLeft() : e2.getPointLeft());
            rightMost=(e1.getPointRight().compareTo2D(e2.getPointRight()) < 1 ? e2.getPointRight() : e1.getPointRight());
            inter1=null;
            inter2=null;
            inter3=null;
            rm=edgeBuffer.remove(j);
            if (!rm.equals(e2)) {
              throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
            }
            rm=edgeBuffer.remove(j - 1);
            if (!rm.equals(e1)) {
              throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
            }
            j--;
            if (leftMost.compareTo2D(newEvent) == -1) {
              inter1=new Edge(leftMost,newEvent);
            }
            inter2=edgeEvent;
            if (rightMost.compareTo2D(edgeEvent.getPointRight()) == 1) {
              inter3=new Edge(edgeEvent.getPointRight(),rightMost);
            }
            if (inter1 != null) {
              if (inter1.getPointRight().compareTo2D(currentEvent) == 1) {
                addConstraintEdge(inter1);
              }
 else {
                mem=edgeBuffer.addEdge(inter1);
                j=j <= mem ? j : mem;
              }
            }
            if (inter2.getPointRight().compareTo2D(currentEvent) == 1) {
              mem=edgeBuffer.addEdge(inter2);
              j=j <= mem ? j : mem;
            }
 else {
              addConstraintEdge(inter2);
            }
            if (inter3 != null) {
              addEdgeToLeftSortedList(edgeMemory,inter3);
            }
            j=j - 2 < 0 ? 0 : j - 2;
          }
 else {
            throw new DelaunayError("String_Node_Str");
          }
        }
 else {
          if (e1.getPointRight().equals2D(currentEvent)) {
            addConstraintEdge(e1);
            rm=edgeBuffer.remove(j - 1);
            if (!rm.equals(e1)) {
              throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
            }
            j--;
            j=j - 1 < 0 ? 0 : j - 1;
          }
        }
        j++;
        if (j >= edgeBuffer.size()) {
          e2=edgeBuffer.get(edgeBuffer.size() - 1);
          if (e2.getPointRight().equals(currentEvent)) {
            edgeBuffer.remove(edgeBuffer.size() - 1);
            addConstraintEdge(e2);
          }
        }
      }
    }
 else     if (edgeBuffer.size() == 1 && edgeBuffer.get(0).getPointRight().equals2D(currentEvent)) {
      addConstraintEdge(edgeBuffer.get(0));
      edgeBuffer.remove(0);
    }
    i++;
  }
}