summaryrefslogtreecommitdiffstats
path: root/src/solve.c
diff options
context:
space:
mode:
authorJesper Jensen <jesper@jnsn.dev>2026-09-27 23:39:11 +0200
committerJesper Jensen <jesper@jnsn.dev>2026-09-27 23:39:11 +0200
commitbfbecd4a3639fb4b8c85f0637c612bb65ef7ec99 (patch)
tree15d382a58012caacd84c4da9ebfb3f81dabce9c7 /src/solve.c
parentf16fc18221cd8d1a8cb1bf9e40790f3b482fb199 (diff)
downloadconstraint-bfbecd4a3639fb4b8c85f0637c612bb65ef7ec99.tar.gz
constraint-bfbecd4a3639fb4b8c85f0637c612bb65ef7ec99.zip
Closer to drawing the box and linesborrow-component
We're stilling missing the lines somehow
Diffstat (limited to 'src/solve.c')
-rw-r--r--src/solve.c187
1 files changed, 132 insertions, 55 deletions
diff --git a/src/solve.c b/src/solve.c
index b70ef54..409e088 100644
--- a/src/solve.c
+++ b/src/solve.c
@@ -517,6 +517,8 @@ constrained_to_assembly:
for(size_t k = 0; k < assemblies[j].articulation_num; k++) {
if(!assemblies[j].articulation[k]->fixed) continue;
+ if(assemblies[j].articulation[k] == f1) continue;
+
// @HACK The logic here also holds for lines, but I don't care
// to do the match right now
if(assemblies[j].articulation[k]->type != COM_POINT) continue;
@@ -786,6 +788,9 @@ static void draw_for_double_subassembly(struct constraint *constraints, size_t f
assert(step->fix2 != NULL);
assert(step->fix3 != NULL);
+ assert(step->fix != step->fix2);
+ assert(step->fix2 != step->fix3);
+
struct element *ax_oppo_locally = step->fix2->e;
struct element *bx_oppo_locally = step->fix->e;
@@ -826,22 +831,36 @@ static void draw_for_double_subassembly(struct constraint *constraints, size_t f
assert(fix3_in_ax != NULL);
assert(fix3_in_bx != NULL);
+ assert(fix3_in_bx != fix_in_bx);
+ assert(fix3_in_ax != fix2_in_ax);
+
// 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.
- struct element *assembly1_distance = insert_cmd(drawing, (struct command){
- .op = CMD_MEASURE_POINT_LINE_DISTANCE,
- .hidden = true,
- .result.type = ETYPE_VALUE,
- .arg1 = fix2_in_ax,
- .arg2 = fix3_in_ax,
- });
+ struct element *assembly1_distance;
+ if(step->fix3->type == COM_LINE) {
+ assembly1_distance = insert_cmd(drawing, (struct command){
+ .op = CMD_MEASURE_POINT_LINE_DISTANCE,
+ .hidden = true,
+ .result.type = ETYPE_VALUE,
+ .arg1 = fix2_in_ax,
+ .arg2 = fix3_in_ax,
+ });
+ } else {
+ assembly1_distance = insert_cmd(drawing, (struct command){
+ .op = CMD_MEASURE_POINT_POINT_DISTANCE,
+ .hidden = true,
+ .result.type = ETYPE_VALUE,
+ .arg1 = fix2_in_ax,
+ .arg2 = fix3_in_ax,
+ });
+ }
if(step->fix->type == COM_LINE) {
+ assert(step->fix3->type == COM_LINE);
struct element *assembly2_angle = insert_cmd(drawing, (struct command){
.op = CMD_MEASURE_LINE_LINE_ANGLE,
.hidden = true,
@@ -909,58 +928,116 @@ static void draw_for_double_subassembly(struct constraint *constraints, size_t f
} 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,
- });
+ if(step->fix3->type == COM_LINE) {
- 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 *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 *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 *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* 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,
- });
+ 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,
+ });
- assert(fix3_in_ax != NULL);
- assert(fix3_in_bx != NULL);
+ 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,
+ });
- 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,
- });
+ assert(fix3_in_ax != NULL);
+ assert(fix3_in_bx != NULL);
- 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,
- });
+ 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,
+ });
+
+ } else {
+
+ struct element *assembly2_distance = insert_cmd(drawing, (struct command){
+ .op = CMD_MEASURE_POINT_POINT_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_locally = insert_cmd(drawing, (struct command){
+ .op = CMD_POINT_CIRCLE_CIRCLE,
+ .hidden = false,
+ .result.type = ETYPE_POINT,
+ .arg1 = c1,
+ .arg2 = c2,
+ });
+
+ assert(fix3_in_ax != NULL);
+ assert(fix3_in_bx != NULL);
+
+ insert_cmd(drawing, (struct command){
+ .op = CMD_IMPORT_POINT_POINT,
+ .arg1 = ax_oppo_locally,
+ .arg2 = cx_oppo_locally,
+ .d = step->assembly2,
+ .attachp = fix2_in_ax,
+ .attachl = fix3_in_ax,
+ });
+
+ insert_cmd(drawing, (struct command){
+ .op = CMD_IMPORT_POINT_POINT,
+ .arg1 = bx_oppo_locally,
+ .arg2 = cx_oppo_locally,
+ .d = step->assembly,
+ .attachp = fix_in_bx,
+ .attachl = fix3_in_bx,
+ });
+ }
}
}
@@ -1284,7 +1361,7 @@ bool solve_constraints(struct constraints *constraints, struct drawing *drawing,
assemblies[*assemblies_num].articulation[i]->in = NULL;
}
(*assemblies_num)++;
- assert(*assemblies_num <= 32);
+ assert(*assemblies_num <= 64);
}
// Fill out the aliased points out with the values from their targets