Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static List<Box> listBox(boolean[][][] immutableBlocks, int width, int height, int depth)
- {
- List<Box> list = Lists.newArrayList();
- boolean[][][] clone = immutableBlocks.clone();
- int i = 0;
- Box next;
- while ((next = nextBox(clone, width, height, depth)) != null)
- {
- list.add(next);
- i ++;
- if (1024 <= i) throw new RuntimeException("Over capacity: Detected too many boxes. May be bug?");
- }
- return list;
- }
- public static Box nextBox(boolean[][][] mutableBlocks, int width, int height, int depth)
- {
- for (int x=0; x<width; x++)
- {
- for (int y=0; y<height; y++)
- {
- for (int z=0; z<depth; z++)
- {
- if (mutableBlocks[x][y][z])
- {
- Box box = nextBoxAt(mutableBlocks, x, y, z, width, height, depth);
- int edge = box.width();
- for (int dx=0; dx<edge; dx++)
- for (int dy=0; dy<edge; dy++)
- for (int dz=0; dz<edge; dz++)
- mutableBlocks[x +dx][y +dy][z +dz] = false; // TODO: Edge Decisionに統合する余地あり
- return box;
- }
- }
- }
- }
- return null;
- }
- public static Box nextBoxAt(boolean[][][] immutableBlocks, int x, int y, int z, int width, int height, int depth) // 現在立方体 直方体にしよう
- {
- // 座標 0,0,0 はtrueでなければなりません
- if (! immutableBlocks[x][y][z]) throw new IllegalArgumentException("始点座標 x,y,z はfalseにできません");
- int maxEdge = Math.min(Math.min(width -x, height -y), depth -z);
- // ここでは、最も外側の薄皮にブロックが満たされているか検査しています
- int edge;
- edge: for (edge=0; edge<maxEdge;)
- {
- edge ++;
- // XZ_Check 内外のXZ平面を検査
- for (int ex=0; ex<edge; ex++)
- for (int ez=0; ez<edge; ez++)
- {
- if (! immutableBlocks[x +ex][y][z +ez]) // TODO: 検査箇所が重複するので非効率 原点方向については最適化の余地あり
- break edge;
- if (! immutableBlocks[x +ex][y +edge -1][z +ez])
- break edge;
- }
- // XY_Check 内外のXY平面を検査
- for (int ex=0; ex<edge; ex++)
- for (int ey=0; ey<edge; ey++)
- {
- if (! immutableBlocks[x +ex][y +ey][z])
- break edge;
- if (! immutableBlocks[x +ex][y +ey][z +edge -1])
- break edge;
- }
- // YZ_Check 内外のYZ平面を検査
- for (int ey=0; ey<edge; ey++)
- for (int ez=0; ez<edge; ez++)
- {
- if (! immutableBlocks[x][y +ey][z +ez])
- break edge;
- if (! immutableBlocks[x +edge -1][y +ey][z +ez])
- break edge;
- }
- } // End of Edge Decision Block
- System.out.println("Edge len: " + edge);
- return new Box(x, y, z, x +edge-1, y +edge-1, z +edge-1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement