我已经广泛搜索了论坛,没有什么能完全涵盖这一点。我正在寻找对枚举类型的数组进行本质上称为 3D Flood Fill 算法的操作。我不想更改数组元素的“颜色”,而是更改其中的枚举类型。这就是我到目前为止所拥有的,如果你认为这会奏效或者你有什么建议,你们能告诉我吗?
/*
* CellType is my enum type. BOUNDRY_BOX enum type is type that I line the whole 3D array with. So the
* whole inside surface of the 3D box is filled with CellType.BOUNDRY_BOX.
**/
public void fillAllVoidCells(CellType[][][] grid, CellType targetType, CellType replacementType, int x, int y, int z)
{
if ((grid[x][y][z] != targetType) && grid[x][y][z] != CellType.BOUNDRY_BOX)
{
break;
}
else
{
grid[x][y][z] = replacementType;
fillAllVoidCells(grid, targetType, replacementType, x + 1, y, z); // right
fillAllVoidCells(grid, targetType, replacementType, x - 1, y, z); // left
fillAllVoidCells(grid, targetType, replacementType, x, y + 1, z); // in front
fillAllVoidCells(grid, targetType, replacementType, x, y - 1, z); // behind
fillAllVoidCells(grid, targetType, replacementType, x, y, z + 1); // above
fillAllVoidCells(grid, targetType, replacementType, x, y, z - 1); // below
}
}