Program: 43063
Project: 43063
Buggy source:
/** 
 * Execute an operation on a grid.  If the operation changes the grid dimensions then a new one will be returned from the call.
 * @param grid The grid to use for grid A.
 * @return The new grid
 */
public Grid execute(Grid grid){
  gridOp=grid;
  result=grid.createEmpty(grid.getWidth(),grid.getHeight(),grid.getDepth(),grid.getVoxelSize(),grid.getSliceHeight());
  result=new RangeCheckWrapper(result);
  if (needTransform) {
    float[] coords=new float[geom.coordinates.length];
    Matrix4d mat=MatrixUtil.createMatrix(new double[]{0,0,0},new double[]{1,1,1},new double[]{rx,ry,rz,rangle},new double[]{x,y,z},new double[]{0,0,1,0});
    Point3d v=new Point3d();
    if (geom.geometryType == GeometryData.TRIANGLES) {
      int len=geom.vertexCount;
      int idx=0;
      for (int i=0; i < len; i++) {
        v.x=geom.coordinates[idx];
        v.y=geom.coordinates[idx + 1];
        v.z=geom.coordinates[idx + 2];
        mat.transform(v);
        coords[idx++]=(float)v.x;
        coords[idx++]=(float)v.y;
        coords[idx++]=(float)v.z;
      }
      GeometryData new_geom=new GeometryData();
      new_geom.geometryType=GeometryData.TRIANGLES;
      new_geom.coordinates=coords;
      new_geom.vertexCount=geom.vertexCount;
      geom=new_geom;
    }
 else     if (geom.geometryType == GeometryData.INDEXED_TRIANGLES) {
      int len=geom.indexesCount;
      int idx=0;
      int loc=0;
      for (int i=0; i < len; i++) {
        loc=geom.indexes[idx++] * 3;
        v.x=geom.coordinates[loc];
        v.y=geom.coordinates[loc + 1];
        v.z=geom.coordinates[loc + 2];
        mat.transform(v);
        coords[loc]=(float)v.x;
        coords[loc + 1]=(float)v.y;
        coords[loc + 2]=(float)v.z;
      }
      GeometryData new_geom=new GeometryData();
      new_geom.geometryType=GeometryData.INDEXED_TRIANGLES;
      new_geom.coordinates=coords;
      new_geom.vertexCount=geom.vertexCount;
      new_geom.indexes=geom.indexes.clone();
      new_geom.indexesCount=geom.indexesCount;
      geom=new_geom;
    }
    Point3d min=new Point3d(bounds[0],bounds[2],bounds[4]);
    Point3d max=new Point3d(bounds[1],bounds[3],bounds[5]);
    mat.transform(min);
    mat.transform(max);
    bounds[0]=(float)min.x;
    bounds[2]=(float)min.y;
    bounds[4]=(float)min.z;
    bounds[1]=(float)max.x;
    bounds[3]=(float)max.y;
    bounds[5]=(float)max.z;
  }
  int[] min=new int[3];
  int[] max=new int[3];
  grid.getGridCoords(bounds[0],bounds[2],bounds[4],min);
  grid.getGridCoords(bounds[1],bounds[3],bounds[5],max);
  spatial=initSpatial(grid,geom,grid.getVoxelSize());
  int[] spat_min=new int[3];
  int[] spat_max=new int[3];
  spatial.findGridCoordsFromWorldCoords(new float[]{bounds[0],bounds[2],bounds[4]},spat_min);
  spatial.findGridCoordsFromWorldCoords(new float[]{bounds[1],bounds[3],bounds[5]},spat_max);
  double[] pos=new double[3];
  int[] tris=null;
  min[0]=0;
  min[1]=0;
  min[2]=0;
  max[0]=grid.getWidth();
  max[1]=grid.getHeight();
  max[2]=grid.getDepth();
  int sloca=spatial.findGridCoordsFromWorldCoords(0);
  int slocb=spatial.findGridCoordsFromWorldCoords(0);
  for (int y=min[1]; y < max[1]; y++) {
    for (int x=min[0]; x < max[0]; x++) {
      grid.getWorldCoords(x,y,0,pos);
      pos[0]-=grid.getVoxelSize() / 2.0;
      pos[1]-=grid.getSliceHeight() / 2.0;
      pos[2]=grid.getDepth() + grid.getVoxelSize();
      if (SPATIAL_ACCEL) {
        int sloc1=spatial.findGridCoordsFromWorldCoords((float)pos[0]);
        int sloc2=spatial.findGridCoordsFromWorldCoords((float)pos[1]);
        TunnelRegion region=new TunnelRegion(TunnelRegion.Axis.Z,sloc1,sloc2,0);
        tris=spatial.getObjects(region);
      }
 else {
        tris=spatial.getObjects(new AllRegion());
      }
      if (tris == null) {
        continue;
      }
      findInterior(TunnelRegion.Axis.Z,pos[0],pos[1],pos[2],tris,grid);
    }
  }
  for (int x=min[0]; x < max[0]; x++) {
    for (int z=min[2]; z < max[2]; z++) {
      grid.getWorldCoords(x,0,z,pos);
      pos[0]-=grid.getVoxelSize() / 2.0;
      pos[2]-=grid.getVoxelSize() / 2.0;
      pos[1]=grid.getHeight() + grid.getSliceHeight();
      if (SPATIAL_ACCEL) {
        int sloc1=spatial.findGridCoordsFromWorldCoords((float)pos[0]);
        int sloc2=spatial.findGridCoordsFromWorldCoords((float)pos[2]);
        TunnelRegion region=new TunnelRegion(TunnelRegion.Axis.Y,sloc1,sloc2,0);
        tris=spatial.getObjects(region);
      }
 else {
        tris=spatial.getObjects(new AllRegion());
      }
      if (tris == null) {
        continue;
      }
      findInterior(TunnelRegion.Axis.Y,pos[0],pos[1],pos[2],tris,grid);
    }
  }
  for (int y=min[1]; y < max[1]; y++) {
    for (int z=min[2]; z < max[2]; z++) {
      grid.getWorldCoords(0,y,z,pos);
      pos[1]-=grid.getSliceHeight() / 2.0;
      pos[2]-=grid.getVoxelSize() / 2.0;
      pos[0]=grid.getWidth() + grid.getVoxelSize();
      if (SPATIAL_ACCEL) {
        int sloc1=spatial.findGridCoordsFromWorldCoords((float)pos[1]);
        int sloc2=spatial.findGridCoordsFromWorldCoords((float)pos[2]);
        TunnelRegion region=new TunnelRegion(TunnelRegion.Axis.X,sloc1,sloc2,0);
        tris=spatial.getObjects(region);
      }
 else {
        tris=spatial.getObjects(new AllRegion());
      }
      if (tris == null) {
        continue;
      }
      findInterior(TunnelRegion.Axis.X,pos[0],pos[1],pos[2],tris,grid);
    }
  }
  result.find(3,this);
  gridOp=null;
  result=null;
  return grid;
}

Fixed version (ground truth):
/** 
 * Execute an operation on a grid.  If the operation changes the grid dimensions then a new one will be returned from the call.
 * @param grid The grid to use for grid A.
 * @return The new grid
 */
public Grid execute(Grid grid){
  gridOp=grid;
  result=grid.createEmpty(grid.getWidth(),grid.getHeight(),grid.getDepth(),grid.getVoxelSize(),grid.getSliceHeight());
  if (needTransform) {
    float[] coords=new float[geom.coordinates.length];
    Matrix4d mat=MatrixUtil.createMatrix(new double[]{0,0,0},new double[]{1,1,1},new double[]{rx,ry,rz,rangle},new double[]{x,y,z},new double[]{0,0,1,0});
    Point3d v=new Point3d();
    if (geom.geometryType == GeometryData.TRIANGLES) {
      int len=geom.vertexCount;
      int idx=0;
      for (int i=0; i < len; i++) {
        v.x=geom.coordinates[idx];
        v.y=geom.coordinates[idx + 1];
        v.z=geom.coordinates[idx + 2];
        mat.transform(v);
        coords[idx++]=(float)v.x;
        coords[idx++]=(float)v.y;
        coords[idx++]=(float)v.z;
      }
      GeometryData new_geom=new GeometryData();
      new_geom.geometryType=GeometryData.TRIANGLES;
      new_geom.coordinates=coords;
      new_geom.vertexCount=geom.vertexCount;
      geom=new_geom;
    }
 else     if (geom.geometryType == GeometryData.INDEXED_TRIANGLES) {
      int len=geom.indexesCount;
      int idx=0;
      int loc=0;
      for (int i=0; i < len; i++) {
        loc=geom.indexes[idx++] * 3;
        v.x=geom.coordinates[loc];
        v.y=geom.coordinates[loc + 1];
        v.z=geom.coordinates[loc + 2];
        mat.transform(v);
        coords[loc]=(float)v.x;
        coords[loc + 1]=(float)v.y;
        coords[loc + 2]=(float)v.z;
      }
      GeometryData new_geom=new GeometryData();
      new_geom.geometryType=GeometryData.INDEXED_TRIANGLES;
      new_geom.coordinates=coords;
      new_geom.vertexCount=geom.vertexCount;
      new_geom.indexes=geom.indexes.clone();
      new_geom.indexesCount=geom.indexesCount;
      geom=new_geom;
    }
    Point3d min=new Point3d(bounds[0],bounds[2],bounds[4]);
    Point3d max=new Point3d(bounds[1],bounds[3],bounds[5]);
    mat.transform(min);
    mat.transform(max);
    bounds[0]=(float)min.x;
    bounds[2]=(float)min.y;
    bounds[4]=(float)min.z;
    bounds[1]=(float)max.x;
    bounds[3]=(float)max.y;
    bounds[5]=(float)max.z;
  }
  int[] min=new int[3];
  int[] max=new int[3];
  grid.getGridCoords(bounds[0],bounds[2],bounds[4],min);
  grid.getGridCoords(bounds[1],bounds[3],bounds[5],max);
  spatial=initSpatial(grid,geom,grid.getVoxelSize());
  double[] pos=new double[3];
  int[] tris=null;
  for (int y=min[1]; y < max[1]; y++) {
    for (int x=min[0]; x < max[0]; x++) {
      grid.getWorldCoords(x,y,0,pos);
      pos[2]=grid.getDepth() + grid.getVoxelSize();
      if (SPATIAL_ACCEL) {
        int sloc1=spatial.findGridCoordsFromWorldCoords((float)pos[0]);
        int sloc2=spatial.findGridCoordsFromWorldCoords((float)pos[1]);
        TunnelRegion region=new TunnelRegion(TunnelRegion.Axis.Z,sloc1,sloc2,0);
        tris=spatial.getObjects(region);
      }
 else {
        tris=spatial.getObjects(new AllRegion());
      }
      if (tris == null) {
        continue;
      }
      findInterior(TunnelRegion.Axis.Z,pos[0],pos[1],pos[2],tris,grid);
    }
  }
  for (int x=min[0]; x < max[0]; x++) {
    for (int z=min[2]; z < max[2]; z++) {
      grid.getWorldCoords(x,0,z,pos);
      pos[1]=grid.getHeight() + grid.getSliceHeight();
      if (SPATIAL_ACCEL) {
        int sloc1=spatial.findGridCoordsFromWorldCoords((float)pos[0]);
        int sloc2=spatial.findGridCoordsFromWorldCoords((float)pos[2]);
        TunnelRegion region=new TunnelRegion(TunnelRegion.Axis.Y,sloc1,sloc2,0);
        tris=spatial.getObjects(region);
      }
 else {
        tris=spatial.getObjects(new AllRegion());
      }
      if (tris == null) {
        continue;
      }
      findInterior(TunnelRegion.Axis.Y,pos[0],pos[1],pos[2],tris,grid);
    }
  }
  for (int y=min[1]; y < max[1]; y++) {
    for (int z=min[2]; z < max[2]; z++) {
      grid.getWorldCoords(0,y,z,pos);
      pos[0]=grid.getWidth() + grid.getVoxelSize();
      if (SPATIAL_ACCEL) {
        int sloc1=spatial.findGridCoordsFromWorldCoords((float)pos[1]);
        int sloc2=spatial.findGridCoordsFromWorldCoords((float)pos[2]);
        TunnelRegion region=new TunnelRegion(TunnelRegion.Axis.X,sloc1,sloc2,0);
        tris=spatial.getObjects(region);
      }
 else {
        tris=spatial.getObjects(new AllRegion());
      }
      if (tris == null) {
        continue;
      }
      findInterior(TunnelRegion.Axis.X,pos[0],pos[1],pos[2],tris,grid);
    }
  }
  result.find(3,this);
  gridOp=null;
  result=null;
  return grid;
}