Program: 186303
Project: 186303
Buggy source:
/** 
 * distributes points along a 3D line segment sequence. This can be used for many different features, such as steps along a way, street lights along a road or posts along a fence.
 * @param preferredDistance  ideal distance between resulting points;this method will try to keep the actual distance as close to this as possible
 * @param pointsAtStartAndEnd  if true, there will be a point at lineStartand lineEnd each; if false, the closest points will be half the usual distance away from these
 */
public static List<VectorXYZ> equallyDistributePointsAlong(double preferredDistance,boolean pointsAtStartAndEnd,List<VectorXYZ> points){
  double length=0;
  for (int i=0; i + 1 < points.size(); i++) {
    length+=points.get(i).distanceToXZ(points.get(i + 1));
  }
  int numSegments=(int)Math.round(length / preferredDistance);
  if (numSegments == 0) {
    return emptyList();
  }
  double pointDistance=length / numSegments;
  int numPoints=pointsAtStartAndEnd ? numSegments + 1 : numSegments;
  List<VectorXYZ> result=new ArrayList<VectorXYZ>(numPoints);
  double currentDistanceFromStart=pointsAtStartAndEnd ? 0 : pointDistance / 2;
  int currentInputPoint=0;
  double offsetCurrentInputPoint=0;
  double offsetNextInputPoint=points.get(0).distanceToXZ(points.get(1));
  for (int i=0; i < numPoints; i++) {
    while (currentDistanceFromStart > offsetNextInputPoint) {
      currentInputPoint+=1;
      offsetCurrentInputPoint=offsetNextInputPoint;
      offsetNextInputPoint=offsetCurrentInputPoint + points.get(currentInputPoint).distanceToXZ(points.get(currentInputPoint + 1));
    }
    VectorXYZ p=interpolateBetween(points.get(currentInputPoint),points.get(currentInputPoint + 1),(currentDistanceFromStart - offsetCurrentInputPoint) / (offsetNextInputPoint - offsetCurrentInputPoint));
    result.add(p);
    currentDistanceFromStart+=pointDistance;
  }
  return result;
}

Fixed version (ground truth):
/** 
 * distributes points along a 3D line segment sequence. This can be used for many different features, such as steps along a way, street lights along a road or posts along a fence.
 * @param preferredDistance  ideal distance between resulting points;this method will try to keep the actual distance as close to this as possible
 * @param pointsAtStartAndEnd  if true, there will be a point at lineStartand lineEnd each; if false, the closest points will be half the usual distance away from these
 */
public static List<VectorXYZ> equallyDistributePointsAlong(double preferredDistance,boolean pointsAtStartAndEnd,List<VectorXYZ> points){
  double length=0;
  for (int i=0; i + 1 < points.size(); i++) {
    length+=points.get(i).distanceToXZ(points.get(i + 1));
  }
  int numSegments=(int)Math.round(length / preferredDistance);
  if (numSegments == 0) {
    return emptyList();
  }
  double pointDistance=length / numSegments;
  int numPoints=pointsAtStartAndEnd ? numSegments + 1 : numSegments;
  List<VectorXYZ> result=new ArrayList<VectorXYZ>(numPoints);
  double currentDistanceFromStart=pointsAtStartAndEnd ? 0 : pointDistance / 2;
  int currentInputPoint=0;
  double offsetCurrentInputPoint=0;
  double offsetNextInputPoint=points.get(0).distanceToXZ(points.get(1));
  for (int i=0; i < numPoints; i++) {
    if (pointsAtStartAndEnd && i == numPoints - 1) {
      result.add(points.get(points.size() - 1));
      break;
    }
    while (currentDistanceFromStart > offsetNextInputPoint) {
      currentInputPoint+=1;
      offsetCurrentInputPoint=offsetNextInputPoint;
      offsetNextInputPoint=offsetCurrentInputPoint + points.get(currentInputPoint).distanceToXZ(points.get(currentInputPoint + 1));
    }
    VectorXYZ p=interpolateBetween(points.get(currentInputPoint),points.get(currentInputPoint + 1),(currentDistanceFromStart - offsetCurrentInputPoint) / (offsetNextInputPoint - offsetCurrentInputPoint));
    result.add(p);
    currentDistanceFromStart+=pointDistance;
  }
  return result;
}