Program: 86558
Project: 86558
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 {
  List<DPoint> eventPoints=points;
  DPoint currentEvent=null;
  VerticalList edgeBuffer=new VerticalList(0);
  List<DEdge> edgeMemory=constraintEdges;
  constraintEdges=new ArrayList<DEdge>();
  double abs;
  int i=0;
  int j=0;
  DEdge e1, e2;
  DEdge inter1=null;
  DEdge inter2=null;
  DEdge inter3=null;
  DEdge inter4=null;
  DPoint newEvent=null;
  DEdge edgeEvent=null;
  DPoint leftMost=null;
  DPoint rightMost=null;
  Element intersection=null;
  DEdge currentMemEdge=null;
  DEdge rm;
  int memoryPos=0;
  int rmCount;
  int mem;
  while (i < eventPoints.size()) {
    int maxWeight=Integer.MIN_VALUE;
    Double z=Double.NaN;
    int w1;
    int w2;
    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,weights);
        rmCount=0;
        if (intersection instanceof DPoint) {
          newEvent=(DPoint)intersection;
          if (!e1.isExtremity(newEvent) || !e2.isExtremity(newEvent)) {
            if (newEvent.equals2D(currentEvent)) {
              if (!weights.isEmpty()) {
                w1=e1.getMaxWeight(weights);
                w2=e2.getMaxWeight(weights);
                if (w1 < maxWeight && w2 < maxWeight) {
                  if (Double.isNaN(z)) {
                    throw new DelaunayError("String_Node_Str");
                  }
                  newEvent.setZ(z);
                }
 else {
                  maxWeight=Math.max(w1,w2);
                  z=newEvent.getZ();
                  currentEvent.setZ(z);
                }
              }
              newEvent.setX(abs);
              List<DEdge> toBeInsert=new ArrayList<DEdge>();
              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 DEdge(newEvent,e2.getPointLeft());
                inter2.setProperty(e2.getProperty());
                addConstraintEdge(inter2);
                rm=edgeBuffer.remove(j);
                if (!rm.equals(e2)) {
                  throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
                }
                inter4=new DEdge(newEvent,e2.getPointRight());
                inter4.setProperty(e2.getProperty());
                toBeInsert.add(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 DEdge(e1.getPointLeft(),newEvent);
                inter1.setProperty(e1.getProperty());
                addConstraintEdge(inter1);
                rm=edgeBuffer.remove(j - 1);
                if (!rm.equals(e1)) {
                  throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
                }
                inter3=new DEdge(e1.getPointRight(),newEvent);
                inter3.setProperty(e1.getProperty());
                toBeInsert.add(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++;
              }
              for (              DEdge yed : toBeInsert) {
                edgeBuffer.addEdge(yed);
              }
              j=(j - rmCount < 0 ? 0 : j - rmCount);
            }
 else {
              ensurePointPosition(e2,newEvent);
              ensurePointPosition(e1,newEvent);
              addToSortedList(newEvent,eventPoints);
            }
          }
 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++;
            }
 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);
              }
              rmCount++;
              j--;
            }
            j=(j - rmCount < 0 ? 0 : j - rmCount);
          }
        }
 else         if (intersection instanceof DEdge) {
          edgeEvent=(DEdge)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 DEdge(leftMost,newEvent);
            }
            inter2=edgeEvent;
            if (rightMost.compareTo2D(edgeEvent.getPointRight()) == 1) {
              inter3=new DEdge(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.contains(currentEvent) && !e1.isExtremity(currentEvent)) {
          DEdge inter=new DEdge(e1.getPointLeft(),currentEvent);
          inter.setProperty(e1.getProperty());
          inter.setLocked(e1.isLocked());
          addConstraintEdge(inter);
          if (e1.getStartPoint().equals(e1.getPointLeft())) {
            e1.setStartPoint(currentEvent);
          }
 else {
            e1.setEndPoint(currentEvent);
          }
          if (!weights.isEmpty()) {
            int w=e1.getMaxWeight(weights);
            if (w > maxWeight) {
              maxWeight=w;
            }
          }
        }
 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 (edgeBuffer.size() > 0 && j >= edgeBuffer.size()) {
          e2=edgeBuffer.get(edgeBuffer.size() - 1);
          if (e2.contains(currentEvent) && !e2.isExtremity(currentEvent)) {
            DEdge temp=new DEdge(e2.getPointLeft(),currentEvent);
            temp.setLocked(e2.isLocked());
            temp.setProperty(e2.getProperty());
            addConstraintEdge(temp);
            if (e2.getStartPoint().equals(e2.getPointLeft())) {
              e2.setStartPoint(currentEvent);
            }
 else {
              e2.setEndPoint(currentEvent);
            }
          }
          if (e2.getPointRight().equals(currentEvent)) {
            edgeBuffer.remove(edgeBuffer.size() - 1);
            addConstraintEdge(e2);
          }
        }
      }
    }
 else     if (edgeBuffer.size() == 1) {
      DEdge e0=edgeBuffer.get(0);
      if (e0.contains(currentEvent) && !e0.isExtremity(currentEvent)) {
        DEdge temp=new DEdge(e0.getPointLeft(),currentEvent);
        temp.setLocked(e0.isLocked());
        temp.setProperty(e0.getProperty());
        addConstraintEdge(temp);
        if (e0.getStartPoint().equals(e0.getPointLeft())) {
          e0.setStartPoint(currentEvent);
        }
 else {
          e0.setEndPoint(currentEvent);
        }
      }
 else       if (e0.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 This methos is supposed to be used just before a call to processDelaunay(). If you use it after, you will break the unicity of edges GID.
 */
public final void forceConstraintIntegrity() throws DelaunayError {
  edgeGID=0;
  List<DPoint> eventPoints=points;
  DPoint currentEvent=null;
  VerticalList edgeBuffer=new VerticalList(0);
  List<DEdge> edgeMemory=constraintEdges;
  constraintEdges=new ArrayList<DEdge>();
  double abs;
  int i=0;
  int j=0;
  DEdge e1, e2;
  DEdge inter1=null;
  DEdge inter2=null;
  DEdge inter3=null;
  DEdge inter4=null;
  DPoint newEvent=null;
  DEdge edgeEvent=null;
  DPoint leftMost=null;
  DPoint rightMost=null;
  Element intersection=null;
  DEdge currentMemEdge=null;
  DEdge rm;
  int memoryPos=0;
  int rmCount;
  int mem;
  while (i < eventPoints.size()) {
    int maxWeight=Integer.MIN_VALUE;
    Double z=Double.NaN;
    int w1;
    int w2;
    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,weights);
        rmCount=0;
        if (intersection instanceof DPoint) {
          newEvent=(DPoint)intersection;
          if (!e1.isExtremity(newEvent) || !e2.isExtremity(newEvent)) {
            if (newEvent.equals2D(currentEvent)) {
              if (!weights.isEmpty()) {
                w1=e1.getMaxWeight(weights);
                w2=e2.getMaxWeight(weights);
                if (w1 < maxWeight && w2 < maxWeight) {
                  if (Double.isNaN(z)) {
                    throw new DelaunayError("String_Node_Str");
                  }
                  newEvent.setZ(z);
                }
 else {
                  maxWeight=Math.max(w1,w2);
                  z=newEvent.getZ();
                  currentEvent.setZ(z);
                }
              }
              newEvent.setX(abs);
              List<DEdge> toBeInsert=new ArrayList<DEdge>();
              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 DEdge(newEvent,e2.getPointLeft());
                inter2.setProperty(e2.getProperty());
                addConstraintEdge(inter2);
                rm=edgeBuffer.remove(j);
                if (!rm.equals(e2)) {
                  throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
                }
                inter4=new DEdge(newEvent,e2.getPointRight());
                inter4.setProperty(e2.getProperty());
                toBeInsert.add(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 DEdge(e1.getPointLeft(),newEvent);
                inter1.setProperty(e1.getProperty());
                addConstraintEdge(inter1);
                rm=edgeBuffer.remove(j - 1);
                if (!rm.equals(e1)) {
                  throw new DelaunayError(DelaunayError.DELAUNAY_ERROR_REMOVING_EDGE);
                }
                inter3=new DEdge(e1.getPointRight(),newEvent);
                inter3.setProperty(e1.getProperty());
                toBeInsert.add(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++;
              }
              for (              DEdge yed : toBeInsert) {
                edgeBuffer.addEdge(yed);
              }
              j=(j - rmCount < 0 ? 0 : j - rmCount);
            }
 else {
              ensurePointPosition(e2,newEvent);
              ensurePointPosition(e1,newEvent);
              addToSortedList(newEvent,eventPoints);
            }
          }
 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++;
            }
 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);
              }
              rmCount++;
              j--;
            }
            j=(j - rmCount < 0 ? 0 : j - rmCount);
          }
        }
 else         if (intersection instanceof DEdge) {
          edgeEvent=(DEdge)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 DEdge(leftMost,newEvent);
            }
            inter2=edgeEvent;
            if (rightMost.compareTo2D(edgeEvent.getPointRight()) == 1) {
              inter3=new DEdge(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.contains(currentEvent) && !e1.isExtremity(currentEvent)) {
          DEdge inter=new DEdge(e1.getPointLeft(),currentEvent);
          inter.setProperty(e1.getProperty());
          inter.setLocked(e1.isLocked());
          addConstraintEdge(inter);
          if (e1.getStartPoint().equals(e1.getPointLeft())) {
            e1.setStartPoint(currentEvent);
          }
 else {
            e1.setEndPoint(currentEvent);
          }
          if (!weights.isEmpty()) {
            int w=e1.getMaxWeight(weights);
            if (w > maxWeight) {
              maxWeight=w;
            }
          }
        }
 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 (edgeBuffer.size() > 0 && j >= edgeBuffer.size()) {
          e2=edgeBuffer.get(edgeBuffer.size() - 1);
          if (e2.contains(currentEvent) && !e2.isExtremity(currentEvent)) {
            DEdge temp=new DEdge(e2.getPointLeft(),currentEvent);
            temp.setLocked(e2.isLocked());
            temp.setProperty(e2.getProperty());
            addConstraintEdge(temp);
            if (e2.getStartPoint().equals(e2.getPointLeft())) {
              e2.setStartPoint(currentEvent);
            }
 else {
              e2.setEndPoint(currentEvent);
            }
          }
          if (e2.getPointRight().equals(currentEvent)) {
            edgeBuffer.remove(edgeBuffer.size() - 1);
            addConstraintEdge(e2);
          }
        }
      }
    }
 else     if (edgeBuffer.size() == 1) {
      DEdge e0=edgeBuffer.get(0);
      if (e0.contains(currentEvent) && !e0.isExtremity(currentEvent)) {
        DEdge temp=new DEdge(e0.getPointLeft(),currentEvent);
        temp.setLocked(e0.isLocked());
        temp.setProperty(e0.getProperty());
        addConstraintEdge(temp);
        if (e0.getStartPoint().equals(e0.getPointLeft())) {
          e0.setStartPoint(currentEvent);
        }
 else {
          e0.setEndPoint(currentEvent);
        }
      }
 else       if (e0.getPointRight().equals2D(currentEvent)) {
        addConstraintEdge(edgeBuffer.get(0));
        edgeBuffer.remove(0);
      }
    }
    i++;
  }
}