Program: 171525
Project: 171525
Buggy source:
public static Vec3d followCurve(RailInfo info,float delta,RailFunc fn){
  float radius=info.length;
  float startAngle=90 - info.quarter / 4f * 90;
  float endAngle=startAngle - info.quarters / 4f * 90;
  if (info.direction == TrackDirection.RIGHT) {
    startAngle=180 + 90 + info.quarter / 4f * 90;
    endAngle=startAngle + info.quarters / 4f * 90;
  }
  float realStartAngle=startAngle;
  float angleDelta=(90 / ((float)Math.PI * (radius) / 2)) * (float)info.gauge.scale() * delta;
  if (info.direction == TrackDirection.RIGHT) {
    float tmp=startAngle;
    startAngle=endAngle - angleDelta;
    endAngle=tmp;
  }
  float hack=(float)((1 - 1 / info.gauge.scale()) * angleDelta) / 2;
  if (info.direction == TrackDirection.LEFT) {
    startAngle-=hack;
    endAngle+=hack;
  }
 else {
    startAngle+=hack;
    endAngle+=hack;
  }
  radius-=1;
  double xPos=Math.sin(Math.toRadians(realStartAngle)) * (radius);
  double zPos=Math.cos(Math.toRadians(realStartAngle)) * (radius);
  if (fn != null) {
    int counter=0;
    for (float angle=startAngle; angle >= endAngle + (startAngle - endAngle) / 2; angle-=angleDelta) {
      double gagX=Math.sin(Math.toRadians(angle)) * radius - xPos;
      double gagZ=Math.cos(Math.toRadians(angle)) * radius - zPos;
      fn.accept(gagX,gagZ,angle,angleDelta,++counter,startAngle,endAngle);
    }
    for (float angle=endAngle; angle <= endAngle + (startAngle - endAngle) / 2 + angleDelta; angle+=angleDelta) {
      double gagX=Math.sin(Math.toRadians(angle)) * radius - xPos;
      double gagZ=Math.cos(Math.toRadians(angle)) * radius - zPos;
      fn.accept(gagX,gagZ,angle,angleDelta,++counter,startAngle,endAngle);
    }
  }
  return new Vec3d(xPos,0,zPos);
}

Fixed version (ground truth):
public static Vec3d followCurve(RailInfo info,float delta,RailFunc fn){
  float radius=info.length;
  float startAngle=90 - info.quarter / 4f * 90;
  float endAngle=startAngle - info.quarters / 4f * 90;
  if (info.direction == TrackDirection.RIGHT) {
    startAngle=180 + 90 + info.quarter / 4f * 90;
    endAngle=startAngle + info.quarters / 4f * 90;
  }
  float realStartAngle=startAngle;
  float angleDelta=(90 / ((float)Math.PI * (radius) / 2)) * (float)info.gauge.scale() * delta;
  if (info.direction == TrackDirection.RIGHT) {
    float tmp=startAngle;
    startAngle=endAngle;
    endAngle=tmp;
  }
  float hack=(float)((1 - 1 / info.gauge.scale()) * angleDelta) / 2;
  if (info.direction == TrackDirection.LEFT) {
    startAngle-=hack;
    endAngle+=hack;
  }
 else {
    startAngle-=hack;
    endAngle+=hack;
  }
  radius-=1;
  double xPos=Math.sin(Math.toRadians(realStartAngle)) * (radius);
  double zPos=Math.cos(Math.toRadians(realStartAngle)) * (radius);
  if (fn != null) {
    int counter=0;
    for (float angle=startAngle; angle >= endAngle + (startAngle - endAngle) / 2; angle-=angleDelta) {
      double gagX=Math.sin(Math.toRadians(angle)) * radius - xPos;
      double gagZ=Math.cos(Math.toRadians(angle)) * radius - zPos;
      fn.accept(gagX,gagZ,angle,angleDelta,++counter,startAngle,endAngle);
    }
    for (float angle=endAngle; angle <= endAngle + (startAngle - endAngle) / 2 + angleDelta; angle+=angleDelta) {
      double gagX=Math.sin(Math.toRadians(angle)) * radius - xPos;
      double gagZ=Math.cos(Math.toRadians(angle)) * radius - zPos;
      fn.accept(gagX,gagZ,angle,angleDelta,++counter,startAngle,endAngle);
    }
  }
  return new Vec3d(xPos,0,zPos);
}