Program: 11054
Project: 11054
Buggy source:
/** 
 * Recalculate any surfaces that require recalculation. This includes regenerating textures when the user has dragged a surface to a different slice.
 */
protected void recalculateSurfaces(){
  if (!dataAvailable) {
    return;
  }
  minLonOffset=Util.clamp(minLonOffset,0,dataProvider.getXSize() - 1);
  maxLonOffset=Util.clamp(maxLonOffset,0,dataProvider.getXSize() - 1 - minLonOffset);
  minLatOffset=Util.clamp(minLatOffset,0,dataProvider.getYSize() - 1);
  maxLatOffset=Util.clamp(maxLatOffset,0,dataProvider.getYSize() - 1 - minLatOffset);
  topOffset=Util.clamp(topOffset,0,dataProvider.getZSize() - 1);
  bottomOffset=Util.clamp(bottomOffset,0,dataProvider.getZSize() - 1 - topOffset);
  int maxLonSlice=dataProvider.getXSize() - 1 - maxLonOffset;
  int maxLatSlice=dataProvider.getYSize() - 1 - maxLatOffset;
  int bottomSlice=dataProvider.getZSize() - 1 - bottomOffset;
  boolean recalculateMinLon=lastMinLonOffset != minLonOffset;
  boolean recalculateMaxLon=lastMaxLonOffset != maxLonOffset;
  boolean recalculateMinLat=lastMinLatOffset != minLatOffset;
  boolean recalculateMaxLat=lastMaxLatOffset != maxLatOffset;
  boolean recalculateTop=lastTopOffset != topOffset;
  boolean recalculateBottom=lastBottomOffset != bottomOffset;
  Rectangle lonRectangle=new Rectangle(0,0,dataProvider.getYSize(),dataProvider.getZSize());
  Rectangle latRectangle=new Rectangle(0,0,dataProvider.getXSize(),dataProvider.getZSize());
  Rectangle elevationRectangle=new Rectangle(0,0,dataProvider.getXSize(),dataProvider.getYSize());
  double topPercent=topOffset / (double)Math.max(dataProvider.getZSize() - 1,1);
  double bottomPercent=bottomSlice / (double)Math.max(dataProvider.getZSize() - 1,1);
  if (recalculateMinLon) {
    minLonClipDirty=true;
    TopBottomFastShape newMinLonCurtain=dataProvider.createLongitudeCurtain(minLonOffset);
    minLonCurtain.setPositions(newMinLonCurtain.getPositions());
    updateTexture(generateTexture(0,minLonOffset,lonRectangle),minLonTexture,minLonCurtain);
    lastMinLonOffset=minLonOffset;
  }
  if (recalculateMaxLon) {
    maxLonClipDirty=true;
    TopBottomFastShape newMaxLonCurtain=dataProvider.createLongitudeCurtain(dataProvider.getXSize() - 1 - maxLonOffset);
    maxLonCurtain.setPositions(newMaxLonCurtain.getPositions());
    updateTexture(generateTexture(0,maxLonSlice,lonRectangle),maxLonTexture,maxLonCurtain);
    lastMaxLonOffset=maxLonOffset;
  }
  if (recalculateMinLat) {
    minLatClipDirty=true;
    TopBottomFastShape newMinLatCurtain=dataProvider.createLatitudeCurtain(minLatOffset);
    minLatCurtain.setPositions(newMinLatCurtain.getPositions());
    updateTexture(generateTexture(1,minLatOffset,latRectangle),minLatTexture,minLatCurtain);
    lastMinLatOffset=minLatOffset;
  }
  if (recalculateMaxLat) {
    maxLatClipDirty=true;
    TopBottomFastShape newMaxLatCurtain=dataProvider.createLatitudeCurtain(dataProvider.getYSize() - 1 - maxLatOffset);
    maxLatCurtain.setPositions(newMaxLatCurtain.getPositions());
    updateTexture(generateTexture(1,maxLatSlice,latRectangle),maxLatTexture,maxLatCurtain);
    lastMaxLatOffset=maxLatOffset;
  }
  if (recalculateTop) {
    topClipDirty=true;
    double elevation=-dataProvider.getDepth() * topPercent;
    updateTexture(generateTexture(2,topOffset,elevationRectangle),topTexture,topSurface);
    lastTopOffset=topOffset;
    topSurface.setElevation(elevation);
    minLonCurtain.setTopElevationOffset(elevation);
    maxLonCurtain.setTopElevationOffset(elevation);
    minLatCurtain.setTopElevationOffset(elevation);
    maxLatCurtain.setTopElevationOffset(elevation);
    recalculateTextureMatrix(topPercent,bottomPercent);
  }
  if (recalculateBottom) {
    bottomClipDirty=true;
    double elevation=-dataProvider.getDepth() * bottomPercent;
    updateTexture(generateTexture(2,bottomSlice,elevationRectangle),bottomTexture,bottomSurface);
    lastBottomOffset=bottomOffset;
    bottomSurface.setElevation(elevation);
    minLonCurtain.setBottomElevationOffset(elevation);
    maxLonCurtain.setBottomElevationOffset(elevation);
    minLatCurtain.setBottomElevationOffset(elevation);
    maxLatCurtain.setBottomElevationOffset(elevation);
    recalculateTextureMatrix(topPercent,bottomPercent);
  }
}

Fixed version (ground truth):
/** 
 * Recalculate any surfaces that require recalculation. This includes regenerating textures when the user has dragged a surface to a different slice.
 */
protected void recalculateSurfaces(){
  if (!dataAvailable) {
    return;
  }
  int xSize=dataProvider.getXSize();
  int ySize=dataProvider.getYSize();
  int zSize=dataProvider.getZSize();
  minLonOffset=Util.clamp(minLonOffset,0,xSize - 1);
  maxLonOffset=Util.clamp(maxLonOffset,0,xSize - 1 - minLonOffset);
  minLatOffset=Util.clamp(minLatOffset,0,ySize - 1);
  maxLatOffset=Util.clamp(maxLatOffset,0,ySize - 1 - minLatOffset);
  topOffset=Util.clamp(topOffset,0,zSize - 1);
  bottomOffset=Util.clamp(bottomOffset,0,zSize - 1 - topOffset);
  int maxLonSlice=xSize - 1 - maxLonOffset;
  int maxLatSlice=ySize - 1 - maxLatOffset;
  int bottomSlice=zSize - 1 - bottomOffset;
  boolean recalculateMinLon=lastMinLonOffset != minLonOffset;
  boolean recalculateMaxLon=lastMaxLonOffset != maxLonOffset;
  boolean recalculateMinLat=lastMinLatOffset != minLatOffset;
  boolean recalculateMaxLat=lastMaxLatOffset != maxLatOffset;
  boolean recalculateTop=lastTopOffset != topOffset;
  boolean recalculateBottom=lastBottomOffset != bottomOffset;
  Rectangle lonRectangle=new Rectangle(0,0,ySize,zSize);
  Rectangle latRectangle=new Rectangle(0,0,xSize,zSize);
  Rectangle elevationRectangle=new Rectangle(0,0,xSize,ySize);
  double topPercent=topOffset / (double)Math.max(zSize - 1,1);
  double bottomPercent=bottomSlice / (double)Math.max(zSize - 1,1);
  if (recalculateMinLon) {
    minLonClipDirty=true;
    TopBottomFastShape newMinLonCurtain=dataProvider.createLongitudeCurtain(minLonOffset);
    minLonCurtain.setPositions(newMinLonCurtain.getPositions());
    updateTexture(generateTexture(0,minLonOffset,lonRectangle),minLonTexture,minLonCurtain);
    lastMinLonOffset=minLonOffset;
  }
  if (recalculateMaxLon) {
    maxLonClipDirty=true;
    TopBottomFastShape newMaxLonCurtain=dataProvider.createLongitudeCurtain(xSize - 1 - maxLonOffset);
    maxLonCurtain.setPositions(newMaxLonCurtain.getPositions());
    updateTexture(generateTexture(0,maxLonSlice,lonRectangle),maxLonTexture,maxLonCurtain);
    lastMaxLonOffset=maxLonOffset;
  }
  if (recalculateMinLat) {
    minLatClipDirty=true;
    TopBottomFastShape newMinLatCurtain=dataProvider.createLatitudeCurtain(minLatOffset);
    minLatCurtain.setPositions(newMinLatCurtain.getPositions());
    updateTexture(generateTexture(1,minLatOffset,latRectangle),minLatTexture,minLatCurtain);
    lastMinLatOffset=minLatOffset;
  }
  if (recalculateMaxLat) {
    maxLatClipDirty=true;
    TopBottomFastShape newMaxLatCurtain=dataProvider.createLatitudeCurtain(ySize - 1 - maxLatOffset);
    maxLatCurtain.setPositions(newMaxLatCurtain.getPositions());
    updateTexture(generateTexture(1,maxLatSlice,latRectangle),maxLatTexture,maxLatCurtain);
    lastMaxLatOffset=maxLatOffset;
  }
  if (recalculateTop) {
    topClipDirty=true;
    double elevation=-dataProvider.getDepth() * topPercent;
    updateTexture(generateTexture(2,topOffset,elevationRectangle),topTexture,topSurface);
    lastTopOffset=topOffset;
    topSurface.setElevation(elevation);
    minLonCurtain.setTopElevationOffset(elevation);
    maxLonCurtain.setTopElevationOffset(elevation);
    minLatCurtain.setTopElevationOffset(elevation);
    maxLatCurtain.setTopElevationOffset(elevation);
    recalculateTextureMatrix(topPercent,bottomPercent);
  }
  if (recalculateBottom) {
    bottomClipDirty=true;
    double elevation=-dataProvider.getDepth() * bottomPercent;
    updateTexture(generateTexture(2,bottomSlice,elevationRectangle),bottomTexture,bottomSurface);
    lastBottomOffset=bottomOffset;
    bottomSurface.setElevation(elevation);
    minLonCurtain.setBottomElevationOffset(elevation);
    maxLonCurtain.setBottomElevationOffset(elevation);
    minLatCurtain.setBottomElevationOffset(elevation);
    maxLatCurtain.setBottomElevationOffset(elevation);
    recalculateTextureMatrix(topPercent,bottomPercent);
  }
}