/** Test basic operation */ public void testBasic() { int size = 10; AttributeGrid grid = new ArrayAttributeGridByte(size, size, size, 0.001, 0.001); for (int y = 2; y < 8; y++) { for (int z = 2; z < 8; z++) { setX(grid, y, z, Grid.INSIDE, 1, 2, 7); } } int erosionDistance = 1; ErosionCube ec = new ErosionCube(erosionDistance); Grid erodedGrid = ec.execute(grid); int width = erodedGrid.getWidth(); int height = erodedGrid.getHeight(); int depth = erodedGrid.getDepth(); for (int y = 0; y < height; y++) { for (int z = 0; z < depth; z++) { for (int x = 0; x < width; x++) { byte state = erodedGrid.getState(x, y, z); // System.out.println(x + ", " + y + ", " + z + ": " + state); if (y >= 2 && y < 6) { if (z >= 2 && z < 6) { if (x >= 2 && x < 6) { assertEquals( "State of (" + x + " " + y + " " + z + " is not interior", Grid.INSIDE, state); } else { assertEquals( "State of (" + x + " " + y + " " + z + " is not outside", Grid.OUTSIDE, state); } } else { assertEquals( "State of (" + x + " " + y + " " + z + " is not outside", Grid.OUTSIDE, state); } } else { assertEquals( "State of (" + x + " " + y + " " + z + " is not outside", Grid.OUTSIDE, state); } } } } /* erosionDistance = 2; ec = new ErosionCube(erosionDistance); erodedGrid = ec.execute(grid); width = erodedGrid.getWidth(); height = erodedGrid.getHeight(); depth = erodedGrid.getDepth(); for (int y=0; y<height; y++) { for (int z=0; z<depth; z++) { for (int x=0; x<width; x++) { System.out.println(x + ", " + y + ", " + z + ": " + erodedGrid.getState(x, y, z)); } } } */ }
private Grid erode(Grid grid, int distance) { ErosionCube ec = new ErosionCube(distance); grid = ec.execute(grid); return grid; }