Program: 86582
Project: 86582
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 void forceConstraintIntegrity() throws DelaunayError {
  ArrayList<MyPoint> eventPoints=new ArrayList<MyPoint>();
  for (  MyEdge edge : constraintEdges) {
    addPointToSortedList(edge.getStart(),eventPoints);
    addPointToSortedList(edge.getEnd(),eventPoints);
  }
  MyPoint currentEvent=null;
  ArrayList<MyEdge> edgeBuffer=new ArrayList<MyEdge>();
  ArrayList<MyEdge> edgeMemory=constraintEdges;
  constraintEdges=new ArrayList<MyEdge>();
  double abs;
  int i=0;
  int j=0;
  MyEdge e1, e2;
  MyEdge inter1=null;
  MyEdge inter2=null;
  MyEdge inter3=null;
  MyEdge inter4=null;
  MyPoint newEvent=null;
  MyEdge edgeEvent=null;
  MyPoint leftMost=null;
  MyPoint rightMost=null;
  MyElement intersection=null;
  boolean rme1=false;
  boolean rme2=false;
  while (i < eventPoints.size()) {
    currentEvent=eventPoints.get(i);
    abs=currentEvent.getX();
    sortEdgesVertically(edgeBuffer,abs);
    while (!edgeMemory.isEmpty() && currentEvent.equals(edgeMemory.get(0).getPointLeft())) {
      insertEdgeVerticalList(edgeMemory.get(0),edgeBuffer,abs);
      edgeMemory.remove(0);
    }
    if (edgeBuffer.size() > 1) {
      e2=edgeBuffer.get(0);
      j=1;
      while (j < edgeBuffer.size()) {
        e1=edgeBuffer.get(j - 1);
        e2=edgeBuffer.get(j);
        intersection=e1.getIntersection(e2);
        if (intersection instanceof MyPoint) {
          newEvent=(MyPoint)intersection;
          if (!e1.isExtremity(newEvent) || !e2.isExtremity(newEvent)) {
            if (newEvent.equals(currentEvent)) {
              if (!newEvent.equals(e2.getPointLeft())) {
                inter2=new MyEdge(e2.getPointLeft(),newEvent);
                addConstraintEdge(inter2);
                edgeBuffer.remove(j);
              }
              j--;
              if (!newEvent.equals(e1.getPointLeft())) {
                inter1=new MyEdge(e1.getPointLeft(),newEvent);
                addConstraintEdge(inter1);
                edgeBuffer.remove(j);
              }
              if (!newEvent.equals(e1.getPointRight()) && !newEvent.equals(e1.getPointLeft())) {
                inter3=new MyEdge(e1.getPointRight(),newEvent);
                insertEdgeVerticalList(inter3,edgeBuffer,abs);
              }
              if (!newEvent.equals(e2.getPointRight()) && !newEvent.equals(e2.getPointLeft())) {
                inter4=new MyEdge(e2.getPointRight(),newEvent);
                insertEdgeVerticalList(inter4,edgeBuffer,abs);
              }
            }
 else {
              addPointToSortedList(newEvent,eventPoints);
            }
          }
 else {
            if (j > 0 && e1.getPointRight().equals(currentEvent)) {
              addConstraintEdge(e1);
              edgeBuffer.remove(j - 1);
            }
            if (j == edgeMemory.size() - 1 && e2.getPointRight().equals(currentEvent)) {
              addConstraintEdge(e2);
              edgeBuffer.remove(j);
            }
          }
        }
 else         if (intersection instanceof MyEdge) {
          edgeEvent=(MyEdge)intersection;
          newEvent=edgeEvent.getPointLeft();
          if (!(e1.isExtremity(newEvent) && e2.isExtremity(newEvent))) {
            addPointToSortedList(edgeEvent.getPointRight(),eventPoints);
          }
 else {
            if (newEvent.equals(currentEvent)) {
              leftMost=(e1.getPointLeft().compareTo2D(e2.getPointLeft()) < 1 ? e1.getPointLeft() : e2.getPointLeft());
              rightMost=(e1.getPointRight().compareTo2D(e2.getPointRight()) < 1 ? e1.getPointRight() : e2.getPointRight());
              edgeBuffer.remove(j);
              j--;
              edgeBuffer.remove(j);
              if (leftMost.compareTo2D(newEvent) == -1) {
                inter1=new MyEdge(leftMost,newEvent);
              }
              inter2=edgeEvent;
              if (rightMost.compareTo2D(edgeEvent.getPointRight()) == 1) {
                inter3=new MyEdge(edgeEvent.getPointRight(),rightMost);
              }
              if (inter1 != null) {
                addConstraintEdge(inter1);
              }
              if (inter2.getPointRight().compareTo2D(currentEvent) == 1) {
                insertEdgeVerticalList(inter2,edgeBuffer,abs);
              }
 else {
                addConstraintEdge(inter2);
              }
              if (inter3 != null) {
                insertEdgeVerticalList(inter2,edgeBuffer,abs);
              }
            }
 else {
              throw new DelaunayError("String_Node_Str");
            }
          }
        }
 else {
          if (e1.getPointRight().equals(currentEvent)) {
            addConstraintEdge(e1);
            edgeBuffer.remove(j - 1);
          }
          if (j == edgeMemory.size() - 1 && e2.getPointRight().equals(currentEvent)) {
            addConstraintEdge(e2);
            edgeBuffer.remove(j);
          }
        }
        j++;
      }
    }
 else     if (edgeBuffer.size() == 1 && edgeBuffer.get(0).getPointRight().equals(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 void forceConstraintIntegrity() throws DelaunayError {
  ArrayList<MyPoint> eventPoints=new ArrayList<MyPoint>();
  for (  MyEdge edge : constraintEdges) {
    addPointToSortedList(edge.getStart(),eventPoints);
    addPointToSortedList(edge.getEnd(),eventPoints);
  }
  MyPoint currentEvent=null;
  ArrayList<MyEdge> edgeBuffer=new ArrayList<MyEdge>();
  ArrayList<MyEdge> edgeMemory=constraintEdges;
  constraintEdges=new ArrayList<MyEdge>();
  double abs;
  int i=0;
  int j=0;
  MyEdge e1, e2;
  MyEdge inter1=null;
  MyEdge inter2=null;
  MyEdge inter3=null;
  MyEdge inter4=null;
  MyPoint newEvent=null;
  MyEdge edgeEvent=null;
  MyPoint leftMost=null;
  MyPoint rightMost=null;
  MyElement intersection=null;
  boolean rme1=false;
  boolean rme2=false;
  while (i < eventPoints.size()) {
    currentEvent=eventPoints.get(i);
    abs=currentEvent.getX();
    sortEdgesVertically(edgeBuffer,abs);
    while (!edgeMemory.isEmpty() && currentEvent.equals(edgeMemory.get(0).getPointLeft())) {
      insertEdgeVerticalList(edgeMemory.get(0),edgeBuffer,abs);
      edgeMemory.remove(0);
    }
    if (edgeBuffer.size() > 1) {
      e2=edgeBuffer.get(0);
      j=1;
      while (j < edgeBuffer.size()) {
        e1=edgeBuffer.get(j - 1);
        e2=edgeBuffer.get(j);
        intersection=e1.getIntersection(e2);
        if (intersection instanceof MyPoint) {
          newEvent=(MyPoint)intersection;
          if (!e1.isExtremity(newEvent) || !e2.isExtremity(newEvent)) {
            if (newEvent.equals(currentEvent)) {
              if (!newEvent.equals(e2.getPointLeft()) && !newEvent.equals(e2.getPointRight())) {
                inter2=new MyEdge(e2.getPointLeft(),newEvent);
                addConstraintEdge(inter2);
                edgeBuffer.remove(j);
                inter4=new MyEdge(e2.getPointRight(),newEvent);
                insertEdgeVerticalList(inter4,edgeBuffer,abs);
              }
 else               if (newEvent.equals(e2.getPointLeft())) {
                addConstraintEdge(e2);
                edgeBuffer.remove(j);
              }
              j--;
              if (!newEvent.equals(e1.getPointLeft()) && !newEvent.equals(e1.getPointRight())) {
                inter1=new MyEdge(e1.getPointLeft(),newEvent);
                addConstraintEdge(inter1);
                edgeBuffer.remove(j);
                inter3=new MyEdge(e1.getPointRight(),newEvent);
                insertEdgeVerticalList(inter3,edgeBuffer,abs);
              }
 else               if (newEvent.equals(e1.getPointLeft())) {
                addConstraintEdge(e1);
                edgeBuffer.remove(j);
              }
            }
 else {
              addPointToSortedList(newEvent,eventPoints);
            }
          }
 else {
            if (e1.getPointRight().equals(currentEvent)) {
              addConstraintEdge(e1);
              edgeBuffer.remove(j - 1);
            }
            if (e2.getPointRight().equals(currentEvent)) {
              addConstraintEdge(e2);
              edgeBuffer.remove(j);
            }
          }
        }
 else         if (intersection instanceof MyEdge) {
          edgeEvent=(MyEdge)intersection;
          newEvent=edgeEvent.getPointLeft();
          if (!(e1.isExtremity(newEvent) && e2.isExtremity(newEvent))) {
            addPointToSortedList(edgeEvent.getPointRight(),eventPoints);
          }
 else {
            if (newEvent.equals(currentEvent)) {
              leftMost=(e1.getPointLeft().compareTo2D(e2.getPointLeft()) < 1 ? e1.getPointLeft() : e2.getPointLeft());
              rightMost=(e1.getPointRight().compareTo2D(e2.getPointRight()) < 1 ? e1.getPointRight() : e2.getPointRight());
              edgeBuffer.remove(j);
              j--;
              edgeBuffer.remove(j);
              if (leftMost.compareTo2D(newEvent) == -1) {
                inter1=new MyEdge(leftMost,newEvent);
              }
              inter2=edgeEvent;
              if (rightMost.compareTo2D(edgeEvent.getPointRight()) == 1) {
                inter3=new MyEdge(edgeEvent.getPointRight(),rightMost);
              }
              if (inter1 != null) {
                addConstraintEdge(inter1);
              }
              if (inter2.getPointRight().compareTo2D(currentEvent) == 1) {
                insertEdgeVerticalList(inter2,edgeBuffer,abs);
              }
 else {
                addConstraintEdge(inter2);
              }
              if (inter3 != null) {
                insertEdgeVerticalList(inter2,edgeBuffer,abs);
              }
            }
 else {
              throw new DelaunayError("String_Node_Str");
            }
          }
        }
 else {
          if (e1.getPointRight().equals(currentEvent)) {
            addConstraintEdge(e1);
            edgeBuffer.remove(j - 1);
          }
          if (e2.getPointRight().equals(currentEvent)) {
            addConstraintEdge(e2);
            edgeBuffer.remove(j);
          }
        }
        j++;
      }
    }
 else     if (edgeBuffer.size() == 1 && edgeBuffer.get(0).getPointRight().equals(currentEvent)) {
      addConstraintEdge(edgeBuffer.get(0));
      edgeBuffer.remove(0);
    }
    i++;
  }
}