Program: 171545
Project: 171545
Buggy source:
private void initHeightMap(){
  if (loadHeightMaps()) {
    return;
  }
  ImmersiveRailroading.info("String_Node_Str");
  double ratio=8;
  xRes=(int)Math.ceil((this.frontBounds + this.rearBounds) * ratio);
  zRes=(int)Math.ceil(this.widthBounds * ratio);
  int precision=(int)Math.ceil(this.heightBounds * 4);
  for (  List<RenderComponent> rcl : this.renderComponents.values()) {
    for (    RenderComponent rc : rcl) {
      double[][] heightMap=new double[xRes][zRes];
      for (      String group : rc.modelIDs) {
        List<Face> faces=model.groups.get(group);
        for (        Face face : faces) {
          Path2D path=new Path2D.Double();
          double fheight=0;
          boolean first=true;
          for (          int[] point : face.points) {
            Vec3d vert=model.vertices.get(point[0]);
            vert=vert.addVector(this.frontBounds,0,this.widthBounds / 2);
            if (first) {
              path.moveTo(vert.x,vert.z);
            }
 else {
              path.lineTo(vert.x,vert.z);
            }
            fheight+=vert.y / face.points.length;
            first=false;
          }
          Area a=new Area(path);
          Rectangle2D bounds=a.getBounds2D();
          for (int x=0; x < xRes; x++) {
            for (int z=1; z < zRes; z++) {
              double relX=((xRes - 1) - x) / ratio;
              double relZ=z / ratio;
              if (bounds.contains(relX,relZ) && a.contains(relX,relZ)) {
                double relHeight=fheight / heightBounds;
                relHeight=((int)Math.ceil(relHeight * precision)) / (double)precision;
                heightMap[x][z]=Math.max(heightMap[x][z],relHeight);
              }
            }
          }
        }
      }
      partMapCache.put(rc,heightMap);
    }
  }
  writeHeightMaps();
}

Fixed version (ground truth):
private void initHeightMap(){
  if (loadHeightMaps()) {
    return;
  }
  ImmersiveRailroading.info("String_Node_Str");
  double ratio=8;
  xRes=(int)Math.ceil((this.frontBounds + this.rearBounds) * ratio);
  zRes=(int)Math.ceil(this.widthBounds * ratio);
  int precision=(int)Math.ceil(this.heightBounds * 4);
  for (  List<RenderComponent> rcl : this.renderComponents.values()) {
    for (    RenderComponent rc : rcl) {
      double[][] heightMap=new double[xRes][zRes];
      for (      String group : rc.modelIDs) {
        List<Face> faces=model.groups.get(group);
        for (        Face face : faces) {
          Path2D path=new Path2D.Double();
          double fheight=0;
          boolean first=true;
          for (          int[] point : face.points) {
            Vec3d vert=model.vertices.get(point[0]);
            vert=vert.addVector(this.frontBounds,0,this.widthBounds / 2);
            if (first) {
              path.moveTo(vert.x,vert.z);
            }
 else {
              path.lineTo(vert.x,vert.z);
            }
            fheight+=vert.y / face.points.length;
            first=false;
          }
          Area a=new Area(path);
          Rectangle2D bounds=a.getBounds2D();
          for (int x=0; x < xRes; x++) {
            for (int z=0; z < zRes; z++) {
              double relX=((xRes - 1) - x) / ratio;
              double relZ=z / ratio;
              if (bounds.contains(relX,relZ) && a.contains(relX,relZ)) {
                double relHeight=fheight / heightBounds;
                relHeight=((int)Math.ceil(relHeight * precision)) / (double)precision;
                heightMap[x][z]=Math.max(heightMap[x][z],relHeight);
              }
            }
          }
        }
      }
      partMapCache.put(rc,heightMap);
    }
  }
  writeHeightMaps();
}