This commit is contained in:
Daniel Ledda
2025-11-14 11:58:26 +01:00
parent 7ec69b3067
commit 737ff6ff3a

View File

@@ -2,6 +2,7 @@
#include "VoxelSpace.h"
#include "SomaSolve.h"
#include "math.h"
#include <stdlib.h>
/*
void get_dims_input(int dims[3]) {
@@ -130,7 +131,7 @@ void backtrackSolve(Arena *arena, Solver *solver, uint64 working_solution, size_
SomaSolutionList *solutions = solver->solutions;
size_t start = offsets->data[curr_piece];
size_t end = offsets->data[curr_piece + 1];
size_t num_pieces = offsets->length - 1;
size_t num_pieces = offsets->length;
for (size_t i = start; i < end; i++) {
bool successful_fuse = !collides(working_solution, input->data[i]);
if (successful_fuse) {
@@ -139,9 +140,8 @@ void backtrackSolve(Arena *arena, Solver *solver, uint64 working_solution, size_
if (curr_piece == num_pieces - 1) {
VoxelSpaceReprList last_soln = solutions->data[solutions->length - 1];
VoxelSpaceReprList last_soln_copy = PushList(arena, VoxelSpaceReprList, last_soln.length);
last_soln_copy.capacity = last_soln.length;
last_soln_copy.length = last_soln.length;
memcpy(last_soln_copy.data, last_soln.data, last_soln.length * sizeof(uint64));
memcpy(last_soln_copy.data, last_soln.data, last_soln.length * ListElementSize(VoxelSpaceReprList));
AppendList(solutions, last_soln_copy);
return;
} else {
@@ -209,7 +209,7 @@ SomaSolutionList filterUnique(Arena *arena, SomaSolutionList *solutions, int dim
SomaSolution solutionCopy = PushList(arena, SomaSolution, solution.length);
solutionCopy.capacity = solution.length;
solutionCopy.length = solution.length;
memcpy(solutionCopy.data, solution.data, solution.length * sizeof(SomaSolutionList_underlying));
memcpy(solutionCopy.data, solution.data, ListElementSize(SomaSolutionList) * solution.length);
AppendList(&uniqueSolns, solutionCopy);
}
}
@@ -230,7 +230,7 @@ SomaSolutionList solve(uint64 *reprs_in, uint32 reprs_in_count, int dims[3]) {
OffsetList offsets = PushList(arena, OffsetList, reprs_in_count + 1);
VoxelSpaceReprList polycubes = PushList(arena, VoxelSpaceReprList, 0);
VoxelSpaceReprList polycubes = EmptyList();
Space empty_voxel_space = {
0,
@@ -244,16 +244,16 @@ SomaSolutionList solve(uint64 *reprs_in, uint32 reprs_in_count, int dims[3]) {
uint64 possibleCombos = 0;
{
VoxelSpaceReprList positions = {};
Space space = empty_voxel_space;
space.space = reprs_in[0];
cullEmptySpace(&space);
positions = getAllPositionsInPrism(permsArena, &space, dims);
VoxelSpaceReprList positions = getAllPositionsInPrism(permsArena, &space, dims);
possibleCombos += positions.length;
VoxelSpaceReprList_underlying *insertion = PushArray(arena, uint64, positions.capacity);
polycubes.data = insertion;
polycubes.capacity += positions.capacity;
polycubes.length += positions.length;
memcpy(insertion, positions.data, positions.capacity * sizeof(VoxelSpaceReprList_underlying));
memcpy(insertion, positions.data, positions.capacity * ListElementSize(VoxelSpaceReprList));
};
for (size_t i = 1; i < reprs_in_count; i++) {
@@ -263,10 +263,10 @@ SomaSolutionList solve(uint64 *reprs_in, uint32 reprs_in_count, int dims[3]) {
cullEmptySpace(&space);
VoxelSpaceReprList perms = getAllPermutationsInPrism(permsArena, &space, dims);
possibleCombos *= perms.length;
VoxelSpaceReprList_underlying *insertion = PushArray(arena, uint64, perms.capacity);
VoxelSpaceReprList_underlying *insertion = PushArray(arena, VoxelSpaceReprList_underlying, perms.capacity);
polycubes.capacity += perms.capacity;
polycubes.length += perms.length;
memcpy(insertion, perms.data, perms.capacity * sizeof(VoxelSpaceReprList_underlying));
memcpy(insertion, perms.data, perms.capacity * ListElementSize(VoxelSpaceReprList));
}
AppendList(&offsets, polycubes.length);