Program: 86576
Project: 86576
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;
  MyEdge currentMemEdge=null;
  MyEdge rm;
  int memoryPos=0;
  int rmCount;
  int mem;
  while (i < eventPoints.size()) {
    currentEvent=eventPoints.get(i);
    abs=currentEvent.getX();
    sortEdgesVertically(edgeBuffer,abs);
    if (currentMemEdge == null) {
      currentMemEdge=edgeMemory.get(0);
    }
    for (; memoryPos < edgeMemory.size(); memoryPos++) {
      currentMemEdge=edgeMemory.get(memoryPos);
      if (currentEvent.equals2D(currentMemEdge.getPointLeft())) {
        insertEdgeVerticalList(currentMemEdge,edgeBuffer,abs);
      }
 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 MyPoint) {
          newEvent=(MyPoint)intersection;
          if (!e1.isExtremity(newEvent) || !e2.isExtremity(newEvent)) {
            if (newEvent.equals2D(currentEvent)) {
              if (!newEvent.equals2D(e2.getPointLeft()) && !newEvent.equals2D(e2.getPointRight())) {
                inter2=new MyEdge(e2.getPointLeft(),newEvent);
                addConstraintEdge(inter2);
                rm=edgeBuffer.remove(j);
                if (!rm.equals(e2)) {
                  throw new RuntimeException("String_Node_Str");
                }
                inter4=new MyEdge(e2.getPointRight(),newEvent);
                insertEdgeVerticalList(inter4,edgeBuffer,abs);
              }
 else               if (newEvent.equals2D(e2.getPointRight())) {
                addConstraintEdge(e2);
                rm=edgeBuffer.remove(j);
                if (!rm.equals(e2)) {
                  throw new RuntimeException("String_Node_Str");
                }
                rmCount++;
              }
              if (!newEvent.equals2D(e1.getPointLeft()) && !newEvent.equals2D(e1.getPointRight())) {
                inter1=new MyEdge(e1.getPointLeft(),newEvent);
                addConstraintEdge(inter1);
                rm=edgeBuffer.remove(j - 1);
                if (!rm.equals(e1)) {
                  throw new RuntimeException("String_Node_Str");
                }
                inter3=new MyEdge(e1.getPointRight(),newEvent);
                insertEdgeVerticalList(inter3,edgeBuffer,abs);
              }
 else               if (newEvent.equals2D(e1.getPointRight())) {
                addConstraintEdge(e1);
                rm=edgeBuffer.remove(j - 1);
                if (!rm.equals(e1)) {
                  throw new RuntimeException("String_Node_Str");
                }
                rmCount++;
              }
              j=(j - rmCount < 0 ? 0 : j - rmCount);
            }
 else {
              addPointToSortedList(newEvent,eventPoints);
            }
          }
 else {
            if (e2.getPointRight().equals2D(currentEvent)) {
              addConstraintEdge(e2);
              rm=edgeBuffer.remove(j);
              if (!rm.equals(e2)) {
                throw new RuntimeException("String_Node_Str");
              }
              rmCount++;
            }
            if (e1.getPointRight().equals2D(currentEvent)) {
              addConstraintEdge(e1);
              rm=edgeBuffer.remove(j - 1);
              if (!rm.equals(e1)) {
                throw new RuntimeException("String_Node_Str");
              }
              rmCount++;
            }
            j=(j - rmCount < 0 ? 0 : j - rmCount);
          }
        }
 else         if (intersection instanceof MyEdge) {
          edgeEvent=(MyEdge)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());
            rm=edgeBuffer.remove(j);
            if (!rm.equals(e2)) {
              throw new RuntimeException("String_Node_Str");
            }
            rm=edgeBuffer.remove(j - 1);
            if (!rm.equals(e1)) {
              throw new RuntimeException("String_Node_Str");
            }
            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) {
              if (inter1.getPointRight().compareTo2D(currentEvent) == 1) {
                addConstraintEdge(inter1);
              }
 else {
                mem=insertEdgeVerticalList(inter1,edgeBuffer,abs);
                j=j <= mem ? j : mem;
              }
            }
            if (inter2.getPointRight().compareTo2D(currentEvent) == 1) {
              mem=insertEdgeVerticalList(inter2,edgeBuffer,abs);
              j=j <= mem ? j : mem;
            }
 else {
              addConstraintEdge(inter2);
            }
            if (inter3 != null) {
              mem=insertEdgeVerticalList(inter3,edgeBuffer,abs);
              j=j <= mem ? j : mem;
            }
          }
 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 RuntimeException("String_Node_Str");
            }
            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 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;
  MyEdge currentMemEdge=null;
  MyEdge rm;
  int memoryPos=0;
  int rmCount;
  int mem;
  while (i < eventPoints.size()) {
    currentEvent=eventPoints.get(i);
    abs=currentEvent.getX();
    sortEdgesVertically(edgeBuffer,abs);
    if (currentMemEdge == null) {
      currentMemEdge=edgeMemory.get(0);
    }
    for (; memoryPos < edgeMemory.size(); memoryPos++) {
      currentMemEdge=edgeMemory.get(memoryPos);
      if (currentEvent.equals2D(currentMemEdge.getPointLeft())) {
        insertEdgeVerticalList(currentMemEdge,edgeBuffer,abs);
      }
 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 MyPoint) {
          newEvent=(MyPoint)intersection;
          if (!e1.isExtremity(newEvent) || !e2.isExtremity(newEvent)) {
            if (newEvent.equals2D(currentEvent)) {
              if (!newEvent.equals2D(e2.getPointLeft()) && !newEvent.equals2D(e2.getPointRight())) {
                inter2=new MyEdge(e2.getPointLeft(),newEvent);
                addConstraintEdge(inter2);
                rm=edgeBuffer.remove(j);
                if (!rm.equals(e2)) {
                  throw new RuntimeException("String_Node_Str");
                }
                inter4=new MyEdge(e2.getPointRight(),newEvent);
                insertEdgeVerticalList(inter4,edgeBuffer,abs);
                rmCount++;
              }
 else               if (newEvent.equals2D(e2.getPointRight())) {
                addConstraintEdge(e2);
                rm=edgeBuffer.remove(j);
                if (!rm.equals(e2)) {
                  throw new RuntimeException("String_Node_Str");
                }
                rmCount++;
              }
              if (!newEvent.equals2D(e1.getPointLeft()) && !newEvent.equals2D(e1.getPointRight())) {
                inter1=new MyEdge(e1.getPointLeft(),newEvent);
                addConstraintEdge(inter1);
                rm=edgeBuffer.remove(j - 1);
                if (!rm.equals(e1)) {
                  throw new RuntimeException("String_Node_Str");
                }
                inter3=new MyEdge(e1.getPointRight(),newEvent);
                insertEdgeVerticalList(inter3,edgeBuffer,abs);
                rmCount++;
              }
 else               if (newEvent.equals2D(e1.getPointRight())) {
                addConstraintEdge(e1);
                rm=edgeBuffer.remove(j - 1);
                if (!rm.equals(e1)) {
                  throw new RuntimeException("String_Node_Str");
                }
                rmCount++;
              }
              j=(j - rmCount < 0 ? 0 : j - rmCount);
            }
 else {
              addPointToSortedList(newEvent,eventPoints);
            }
          }
 else {
            if (e2.getPointRight().equals2D(currentEvent)) {
              addConstraintEdge(e2);
              rm=edgeBuffer.remove(j);
              if (!rm.equals(e2)) {
                throw new RuntimeException("String_Node_Str");
              }
              rmCount++;
            }
            if (e1.getPointRight().equals2D(currentEvent)) {
              addConstraintEdge(e1);
              rm=edgeBuffer.remove(j - 1);
              if (!rm.equals(e1)) {
                throw new RuntimeException("String_Node_Str");
              }
              rmCount++;
            }
            j=(j - rmCount < 0 ? 0 : j - rmCount);
          }
        }
 else         if (intersection instanceof MyEdge) {
          edgeEvent=(MyEdge)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 RuntimeException("String_Node_Str");
            }
            rm=edgeBuffer.remove(j - 1);
            if (!rm.equals(e1)) {
              throw new RuntimeException("String_Node_Str");
            }
            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) {
              if (inter1.getPointRight().compareTo2D(currentEvent) == 1) {
                addConstraintEdge(inter1);
              }
 else {
                mem=insertEdgeVerticalList(inter1,edgeBuffer,abs);
                j=j <= mem ? j : mem;
              }
            }
            if (inter2.getPointRight().compareTo2D(currentEvent) == 1) {
              mem=insertEdgeVerticalList(inter2,edgeBuffer,abs);
              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 RuntimeException("String_Node_Str");
            }
            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++;
  }
}