summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/solve.c92
1 files changed, 27 insertions, 65 deletions
diff --git a/src/solve.c b/src/solve.c
index 67a7bff..7f3df82 100644
--- a/src/solve.c
+++ b/src/solve.c
@@ -187,39 +187,6 @@ static bool try_fix_component(struct constraints *constraints_in, struct compone
// No way to fix this component was found
if(*not_angle == NULL) return false;
- if(c->ein != NULL) {
- // Find a second non-angle constraint for something in our assembly
- for(size_t i = 0; i < constraints_num; i++) {
- if(constraints[i].used) continue;
- if(constraints[i].type == CT_LINE_LINE_ANGLE) continue;
-
- // We already selected this one, we can't use it again
- if(&constraints[i] == *not_angle) continue;
-
- // Find the side that's fixed
- bool f;
- struct component *dest;
- if(constraints[i].c1->fixed) {
- dest = constraints[i].c2;
- f = true;
- } else if(constraints[i].c2->fixed) {
- dest = constraints[i].c1;
- f = false;
- } else {
- continue;
- }
-
- // It has to relate to something on the same assembly as c
- if(dest->ein != c->ein) continue;
-
- *second_not_angle = &constraints[i];
- *f3 = f;
- break;
- }
-
- if(*second_not_angle == NULL) return false;
- }
-
// Look for another distance constraint
for(size_t i = 0; i < constraints_num; i++) {
if(constraints[i].used) continue;
@@ -227,7 +194,6 @@ static bool try_fix_component(struct constraints *constraints_in, struct compone
// We already selected this one, we can't use it again
if(&constraints[i] == *not_angle) continue;
- if(c->ein != NULL && &constraints[i] == *second_not_angle) continue;
bool f;
struct component *oppo;
@@ -257,7 +223,6 @@ static bool try_fix_component(struct constraints *constraints_in, struct compone
// We already selected this one, we can't use it again
if(&constraints[i] == *not_angle) continue;
- if(c->ein != NULL && &constraints[i] == *second_not_angle) continue;
// @CLEANUP Look into removing this "angle walking". I don't think
// we need it if we have proper subassembly inclusion
@@ -309,7 +274,7 @@ static bool try_fix_component(struct constraints *constraints_in, struct compone
return true;
}
-static size_t build_triangles(struct constraints *constraints_in, struct component **components, size_t component_num, size_t origin, uint8_t useid, struct subassembly *assembly) {
+static size_t build_triangles(struct constraints *constraints_in, struct component **components, size_t component_num, size_t origin, uint8_t assemblyid, struct subassembly *assembly) {
struct constraint *constraints = constraints_in->elements;
size_t constraints_num = constraints_in->length;
@@ -327,7 +292,7 @@ static size_t build_triangles(struct constraints *constraints_in, struct compone
constraints[i].forward = true;
}
- constraints[origin].used = useid;
+ constraints[origin].used = assemblyid;
constraints[origin].order = order++;
// You can't fix a subcomponent, as it has too much freedom
@@ -347,7 +312,7 @@ static size_t build_triangles(struct constraints *constraints_in, struct compone
while(true) {
// 0 distance PP_DISTANCE fixes the point without anything else
- // @INVEST: Is this really required anymore? I thought we had solved
+ // @CLEANUP Is this really required anymore? I thought we had solved
// this with the alias system?
// @HACK Really all of this should go in try_fix_component since we
// need an additional constraint to fix rotation of assemblies
@@ -377,7 +342,7 @@ static size_t build_triangles(struct constraints *constraints_in, struct compone
oppo->in = assembly;
oppo->ein = assembly;
constraints[i].order = 0;
- constraints[i].used = useid;
+ constraints[i].used = assemblyid;
steps[steps_i].assembly = NULL;
steps[steps_i].i = i;
@@ -396,39 +361,30 @@ static size_t build_triangles(struct constraints *constraints_in, struct compone
struct constraint *possibly_angle = NULL;
bool f2;
+ // @CLEANUP Not used anymore
struct constraint *second_not_angle = NULL;
bool f3;
if(try_fix_component(constraints_in, components[i], &not_angle, &f1, &possibly_angle, &f2, &second_not_angle, &f3)) {
- struct subassembly *sub = components[i]->ein;
- if(sub == NULL) {
- add_frontier(components[i]);
- assert(components[i]->in == NULL);
- components[i]->in = assembly;
- components[i]->ein = assembly;
- } else {
- // We've fixed the subcomponent, so we have to fix the whole thing
- for(size_t j = 0; j < component_num; j++) {
- if(components[j]->ein != sub) continue;
+ assert(second_not_angle == NULL && f3 == false);
+ add_frontier(components[i]);
+ assert(components[i]->in == NULL);
+ components[i]->in = assembly;
+ components[i]->ein = assembly;
- add_frontier(components[j]);
- components[j]->ein = assembly;
- }
- }
-
- not_angle->used = useid;
+ not_angle->used = assemblyid;
not_angle->order = order++;
- possibly_angle->used = useid;
+ possibly_angle->used = assemblyid;
possibly_angle->order = order++;
- steps[steps_i].assembly = second_not_angle == NULL ? NULL : sub;
+ steps[steps_i].assembly = NULL;
steps[steps_i].i = not_angle - constraints;
steps[steps_i].j = possibly_angle - constraints;
steps[steps_i].i_forward = f1;
steps[steps_i].j_forward = f2;
if(second_not_angle != NULL) {
- second_not_angle->used = useid;
+ second_not_angle->used = assemblyid;
second_not_angle->order = order++;
steps[steps_i].k = second_not_angle - constraints;
steps[steps_i].k_forward = f3;
@@ -566,18 +522,18 @@ static size_t build_triangles(struct constraints *constraints_in, struct compone
}
// There's a total of 6 different constraints involved here
- not_angle_a->used = useid;
+ not_angle_a->used = assemblyid;
not_angle_a->order = order++;
- not_angle_b->used = useid;
+ not_angle_b->used = assemblyid;
not_angle_b->order = order++;
- not_angle_c->used = useid;
+ not_angle_c->used = assemblyid;
not_angle_c->order = order++;
- possibly_angle_a->used = useid;
+ possibly_angle_a->used = assemblyid;
possibly_angle_a->order = order++;
- possibly_angle_b->used = useid;
+ possibly_angle_b->used = assemblyid;
possibly_angle_b->order = order++;
- possibly_angle_c->used = useid;
+ possibly_angle_c->used = assemblyid;
possibly_angle_c->order = order++;
steps[steps_i].assembly = ein_a;
@@ -617,7 +573,7 @@ candidate_found:
// world)
for(size_t i = 0; i < constraints_num; i++) {
- if(constraints[i].used == useid) continue;
+ if(constraints[i].used == assemblyid) continue;
if(frontier_scan(constraints[i].c1)) {
for(size_t j = 0; j < assembly->articulation_num; j++) {
@@ -1277,6 +1233,12 @@ bool solve_constraints(struct constraints *constraints, struct drawing *drawing,
draw_solution(constraints->elements, fix, assemblies[*assemblies_num].steps, assemblies[*assemblies_num].steps_num, drawing, &assemblies[*assemblies_num]);
for(size_t i = 0; i < assemblies[*assemblies_num].articulation_num; i++) {
assemblies[*assemblies_num].articulation_position[i] = assemblies[*assemblies_num].articulation[i]->e;
+
+ // Release all the articulations for other constructions. We'll put
+ // this back together later
+ assemblies[*assemblies_num].articulation[i]->fixed = false;
+ assemblies[*assemblies_num].articulation[i]->ein = NULL;
+ assemblies[*assemblies_num].articulation[i]->in = NULL;
}
(*assemblies_num)++;
assert(*assemblies_num <= 16);