diff --git a/VoxelSpace.cpp b/VoxelSpace.cpp index 8206eca..fa404b8 100644 --- a/VoxelSpace.cpp +++ b/VoxelSpace.cpp @@ -47,6 +47,10 @@ namespace Voxel { return (a | b) != (a ^ b); } + inline auto collides(Space *a, Space *b) -> bool { + return (a->space | b->space) != (a->space ^ b->space); + } + inline auto filledAt(uint64_t space, int dims[3], int x, int y, int z) -> bool { auto mask = 1ull << (dims[1] * dims[2] * x + dims[2] * y + z); return (space & mask) != 0ull; @@ -173,6 +177,14 @@ namespace Voxel { } } + auto pushXAxisSpins(std::vector *existingSpaces, Space* spaceToSpin) -> void { + auto refSpace = *spaceToSpin; + for (int i = 0; i < 3; i++) { + rotate90X(&refSpace); + existingSpaces->push_back(refSpace); + } + } + auto getUniqueRotations(Space *space) -> std::vector { auto rotations = std::vector(); rotations.reserve(6*24); @@ -191,25 +203,23 @@ namespace Voxel { return rotations; } - /* - getAllRotations(): Space[] { - let rotations: Space[] = new Array(); - const refSpace = this.clone(); - rotations = rotations.concat(refSpace.getXAxisSpins()); - refSpace.rot90Y(); - rotations = rotations.concat(refSpace.getXAxisSpins()); - refSpace.rot90Y(); - rotations = rotations.concat(refSpace.getXAxisSpins()); - refSpace.rot90Y(); - rotations = rotations.concat(refSpace.getXAxisSpins()); - refSpace.rot90Z(); - rotations = rotations.concat(refSpace.getXAxisSpins()); - refSpace.rot90Z(); - refSpace.rot90Z(); - rotations = rotations.concat(refSpace.getXAxisSpins()); + auto getAllRotations(Space *space) -> std::vector { + auto rotations = std::vector(); + rotations.reserve(6*24); + auto dims = space->dims; + auto refSpace = *space; + pushXAxisSpins(&rotations, &refSpace); + rotate90Y(&refSpace); + pushXAxisSpins(&rotations, &refSpace); + rotate90Y(&refSpace); + pushXAxisSpins(&rotations, &refSpace); + rotate90Z(&refSpace); + pushXAxisSpins(&rotations, &refSpace); + rotate90Z(&refSpace); + rotate90Z(&refSpace); + pushXAxisSpins(&rotations, &refSpace); return rotations; } - */ auto getAllPositionsInPrism(uint64_t space, int space_dims[3], int prism_dims[3]) -> std::vector { auto cubePositions = std::vector(); diff --git a/VoxelSpace.h b/VoxelSpace.h index cb59459..be17eab 100644 --- a/VoxelSpace.h +++ b/VoxelSpace.h @@ -32,6 +32,7 @@ namespace Voxel { inline auto set(uint64_t space, int index, bool val) -> uint64_t; inline auto collides(Space *a, Space *b) -> bool; + inline auto collides(uint64_t a, uint64_t b) -> bool; inline auto add(Space *a, Space *b) -> Space; diff --git a/main.cpp b/main.cpp index c4bb4f9..a90ec22 100644 --- a/main.cpp +++ b/main.cpp @@ -59,7 +59,7 @@ auto backtrack_solve(std::vector *polycube_input, std::vector *of auto end = offsets->at(set + 1); std::cout << start << " " << end << "\n"; for (int i = start; i < end; i++) { - auto successful_fuse = (working_solution | polycube_input->at(i)) == (working_solution ^ polycube_input->at(i)); + auto successful_fuse = !Voxel::collides(working_solution, polycube_input->at(i)); if (successful_fuse) { working_solution = working_solution | polycube_input->at(i); if (set == offsets->size() - 2) {