diff options
| author | Jesper Jensen <jesper@jnsn.dev> | 2026-09-08 23:35:45 +0200 |
|---|---|---|
| committer | Jesper Jensen <jesper@jnsn.dev> | 2026-09-08 23:35:45 +0200 |
| commit | 754a18240de72cec691389825ffa3487f7052ca7 (patch) | |
| tree | cca42feea0c56261de5f077363200c05370c2215 /src/solve.c | |
| parent | 93427194d9df65e06751c9442cc95661bdbc354e (diff) | |
| download | constraint-754a18240de72cec691389825ffa3487f7052ca7.tar.gz constraint-754a18240de72cec691389825ffa3487f7052ca7.zip | |
I think we actually have the examples working
At the same time, for the first time
Diffstat (limited to 'src/solve.c')
| -rw-r--r-- | src/solve.c | 211 |
1 files changed, 110 insertions, 101 deletions
diff --git a/src/solve.c b/src/solve.c index 73f1f87..f62604c 100644 --- a/src/solve.c +++ b/src/solve.c @@ -443,7 +443,7 @@ static size_t build_triangles(struct constraints *constraints_in, struct compone } for(size_t k = 0; k < assemblies[i].articulation_num; k++) { - if(assemblies[i].articulation[k] == oppo) continue; + if(assemblies[i].articulation[k] != oppo) continue; goto constrained_to_assembly; } @@ -486,6 +486,7 @@ constrained_to_assembly: steps[steps_i].fix = fixpoint; steps_i++; + goto candidate_found; } // Look for a triangle of assemblies @@ -507,7 +508,6 @@ constrained_to_assembly: } if(f1 == NULL) continue; - fprintf(stderr, "First leg %ld\n", i); // Then the side that shares an articulation with the first side, and also has one fixed for(size_t j = i+1; j < assemblyid-1; j++) { @@ -526,12 +526,10 @@ constrained_to_assembly: } if(f2 == NULL) continue; - fprintf(stderr, "Potential second leg %ld\n", j); struct component *f3 = NULL; for(size_t k = 0; k < assemblies[j].articulation_num; k++) { for(size_t x = 0; x < assemblies[i].articulation_num; x++) { - fprintf(stderr, "Potential check %p %p\n", assemblies[j].articulation[k], assemblies[i].articulation[x]); if(assemblies[j].articulation[k] != assemblies[i].articulation[x]) continue; goto shared_articulation_found; @@ -549,8 +547,6 @@ shared_articulation_found: if(f3 == NULL) continue; - fprintf(stderr, " Found match %ld %ld\n", i, j); - // No new constraints were used for this, we are just situating // 2 subassemblies by two relative to us. assemblies[i].folded_into = assembly; @@ -575,6 +571,7 @@ shared_articulation_found: steps[steps_i].fix3 = f3; steps_i++; + goto candidate_found; } } @@ -707,62 +704,19 @@ static void draw_for_subassembly(struct constraint *constraints, size_t fix, str oppo_j = constraints[step->j].c1; } + struct element *attachl = NULL; + for(size_t i = 0; i < step->assembly->articulation_num; i++) { + if(step->assembly->articulation[i] != oppo_j) continue; + + attachl = step->assembly->articulation_position[i]; + break; + } + assert(attachl != NULL); + struct element *attachp = NULL; struct element *p = NULL; if(step->fix == NULL) { - struct component *local_i; - struct component *oppo_i; - if(step->i_forward) { - local_i = constraints[step->i].c1; - oppo_i = constraints[step->i].c2; - } else { - local_i = constraints[step->i].c2; - oppo_i = constraints[step->i].c1; - } - attachp = oppo_i->e; - - struct component *local_k; - struct component *oppo_k; - if(step->k_forward) { - local_k = constraints[step->k].c1; - oppo_k = constraints[step->k].c2; - } else { - local_k = constraints[step->k].c2; - oppo_k = constraints[step->k].c1; - } - - // The local_ side is the "outer" (more leaf) component - // By the construction we know that i and k are never angle constraints. - - // @HACK for now just solve the simple case where oppo_i and oppo_k are the - // same component. Technically I think we should be able to solve other - // cases as well, I just don't want to do the math. - assert(oppo_i == oppo_k); - - if(constraints[step->i].type == CT_POINT_POINT_DISTANCE - && local_i->type == COM_POINT - && constraints[step->k].type == CT_POINT_POINT_DISTANCE - && local_k->type == COM_POINT) { - - draw_point_from_2_distance(drawing, constraints, step->i, step->k, local_i, local_k, &p, false); - assert(p != NULL); - } else if(constraints[step->i].type == CT_POINT_LINE_DISTANCE - && local_i->type == COM_LINE - && constraints[step->k].type == CT_POINT_POINT_DISTANCE - && local_k->type == COM_POINT) { - assert(oppo_i->type == COM_POINT); - - point_from_line_and_distance(drawing, constraints, step->i, step->k, local_i->e, local_k->e, constraints[step->k].c2 == local_k, &p); - } else if(constraints[step->i].type == CT_POINT_POINT_DISTANCE - && local_i->type == COM_POINT - && constraints[step->k].type == CT_POINT_LINE_DISTANCE - && local_k->type == COM_LINE) { - assert(oppo_i->type == COM_POINT); - - point_from_line_and_distance(drawing, constraints, step->k, step->i, local_k->e, local_i->e, constraints[step->i].c2 == local_i, &p); - } else { - abort(); - } + abort(); } else { p = step->fix->e; @@ -805,7 +759,7 @@ static void draw_for_subassembly(struct constraint *constraints, size_t fix, str .arg2 = l, .d = step->assembly, .attachp = attachp, - .attachl = oppo_j->e, + .attachl = attachl, }); } @@ -832,11 +786,6 @@ static void draw_for_double_subassembly(struct constraint *constraints, size_t f assert(step->fix2 != NULL); assert(step->fix3 != NULL); - // Lets solve for a pretty static case first - assert(step->fix->type == COM_LINE); - assert(step->fix2->type == COM_POINT); - assert(step->fix3->type == COM_LINE); - struct element *ax_oppo_locally = step->fix2->e; struct element *bx_oppo_locally = step->fix->e; @@ -877,6 +826,10 @@ static void draw_for_double_subassembly(struct constraint *constraints, size_t f assert(fix3_in_ax != NULL); assert(fix3_in_bx != NULL); + // Lets solve for a pretty static case first + assert(step->fix2->type == COM_POINT); + assert(step->fix3->type == COM_LINE); + //cx's naming is strange, the two local points are in bx and the opposing //point is in ax. We know that since ax was built before bx and had the two //local elements been in ax, we would have included the point as well. @@ -888,46 +841,46 @@ static void draw_for_double_subassembly(struct constraint *constraints, size_t f .arg2 = fix3_in_ax, }); - struct element *assembly2_angle = insert_cmd(drawing, (struct command){ - .op = CMD_MEASURE_LINE_LINE_ANGLE, - .hidden = true, - .result.type = ETYPE_VALUE, - .arg1 = fix_in_bx, - .arg2 = fix3_in_bx, - }); - - struct element* cx_oppo_direction_locally; - { - struct element* l = insert_cmd(drawing, (struct command){ - .op = CMD_LINE_POINT_LINE_ANGLE, - .hidden = false, - .result.type = ETYPE_LINE, - .arg1 = ax_oppo_locally, - .arg2 = bx_oppo_locally, - .arg3 = assembly2_angle, + if(step->fix->type == COM_LINE) { + struct element *assembly2_angle = insert_cmd(drawing, (struct command){ + .op = CMD_MEASURE_LINE_LINE_ANGLE, + .hidden = true, + .result.type = ETYPE_VALUE, + .arg1 = fix_in_bx, + .arg2 = fix3_in_bx, }); - cx_oppo_direction_locally = insert_cmd(drawing, (struct command){ - .op = CMD_LINE_LINE_DISTANCE_PARALLEL, - .hidden = false, - .result.type = ETYPE_LINE, - .root = 1, - .arg1 = l, - .arg2 = assembly1_distance, - }); - } - cx_oppo_direction_locally = cx_oppo_direction_locally; + struct element* cx_oppo_direction_locally; + { + struct element* l = insert_cmd(drawing, (struct command){ + .op = CMD_LINE_POINT_LINE_ANGLE, + .hidden = false, + .result.type = ETYPE_LINE, + .arg1 = ax_oppo_locally, + .arg2 = bx_oppo_locally, + .arg3 = assembly2_angle, + }); - insert_cmd(drawing, (struct command){ - .op = CMD_IMPORT_POINT_LINE, - .arg1 = ax_oppo_locally, - .arg2 = cx_oppo_direction_locally, - .d = step->assembly2, - .attachp = fix2_in_ax, - .attachl = fix3_in_ax, - }); + cx_oppo_direction_locally = insert_cmd(drawing, (struct command){ + .op = CMD_LINE_LINE_DISTANCE_PARALLEL, + .hidden = false, + .result.type = ETYPE_LINE, + .root = 1, + .arg1 = l, + .arg2 = assembly1_distance, + }); + } + + assert(fix3_in_ax != NULL); + insert_cmd(drawing, (struct command){ + .op = CMD_IMPORT_POINT_LINE, + .arg1 = ax_oppo_locally, + .arg2 = cx_oppo_direction_locally, + .d = step->assembly2, + .attachp = fix2_in_ax, + .attachl = fix3_in_ax, + }); - { struct element *local_intersection = insert_cmd(drawing, (struct command){ .op = CMD_POINT_LINE_LINE, .hidden = true, @@ -943,6 +896,7 @@ static void draw_for_double_subassembly(struct constraint *constraints, size_t f .arg1 = fix_in_bx, .arg2 = fix3_in_bx, }); + assert(fix_in_bx != NULL); insert_cmd(drawing, (struct command){ .op = CMD_IMPORT_POINT_LINE, @@ -952,6 +906,61 @@ static void draw_for_double_subassembly(struct constraint *constraints, size_t f .attachp = subassembly2_intersection, .attachl = fix_in_bx, }); + } else { + assert(step->fix->type == COM_POINT); + + struct element *assembly2_distance = insert_cmd(drawing, (struct command){ + .op = CMD_MEASURE_POINT_LINE_DISTANCE, + .hidden = true, + .result.type = ETYPE_VALUE, + .arg1 = fix_in_bx, + .arg2 = fix3_in_bx, + }); + + struct element *c1 = insert_cmd(drawing, (struct command){ + .op = CMD_CIRCLE_CENTER_RADIUS, + .hidden = true, + .result.type = ETYPE_CIRCLE, + .arg1 = ax_oppo_locally, + .arg2 = assembly1_distance, + }); + + struct element *c2 = insert_cmd(drawing, (struct command){ + .op = CMD_CIRCLE_CENTER_RADIUS, + .hidden = true, + .result.type = ETYPE_CIRCLE, + .arg1 = bx_oppo_locally, + .arg2 = assembly2_distance, + }); + + struct element* cx_oppo_direction_locally = insert_cmd(drawing, (struct command){ + .op = CMD_LINE_CIRCLE_CIRCLE_TANGENT, + .hidden = false, + .result.type = ETYPE_LINE, + .arg1 = c1, + .arg2 = c2, + }); + + assert(fix3_in_ax != NULL); + assert(fix3_in_bx != NULL); + + insert_cmd(drawing, (struct command){ + .op = CMD_IMPORT_POINT_LINE, + .arg1 = ax_oppo_locally, + .arg2 = cx_oppo_direction_locally, + .d = step->assembly2, + .attachp = fix2_in_ax, + .attachl = fix3_in_ax, + }); + + insert_cmd(drawing, (struct command){ + .op = CMD_IMPORT_POINT_LINE, + .arg1 = bx_oppo_locally, + .arg2 = cx_oppo_direction_locally, + .d = step->assembly, + .attachp = fix_in_bx, + .attachl = fix3_in_bx, + }); } } |
