summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesper Jensen <jesper@jnsn.dev>2025-11-23 12:40:14 +0100
committerJesper Jensen <jesper@jnsn.dev>2025-11-23 12:40:14 +0100
commit9c0110122693400366bd52a49b7d4645eae3de57 (patch)
treeadf879efa78fdb34d605b8d636a02ade1f50f672
parente63c2a09a54c28dbcaaee48de2008fd5c3a7bf81 (diff)
Explicitly state the parameter index
-rw-r--r--inc/cad/construction.h1
-rw-r--r--src/construction.c3
-rw-r--r--src/solve.c18
3 files changed, 15 insertions, 7 deletions
diff --git a/inc/cad/construction.h b/inc/cad/construction.h
index eee5fa3..9f4b9ca 100644
--- a/inc/cad/construction.h
+++ b/inc/cad/construction.h
@@ -56,6 +56,7 @@ struct command {
uint8_t root;
bool hidden;
+ size_t index;
struct element *arg1;
struct element *arg2;
struct element *arg3;
diff --git a/src/construction.c b/src/construction.c
index 6e3cd6e..b73ee69 100644
--- a/src/construction.c
+++ b/src/construction.c
@@ -68,12 +68,11 @@ struct element* insert_cmd(struct drawing *drawing, struct command cmd) {
void execute_drawing(struct drawing *drawing, double inputs[]) {
- size_t input_i = 0;
for(struct command *current = drawing->root; current != NULL; current = current->next) {
switch(current->op) {
case CMD_VALUE_INPUT: {
assert(current->result.type == ETYPE_VALUE);
- current->result.value = inputs[input_i++];
+ current->result.value = inputs[current->index];
}break;
case CMD_ORIGIN: {
assert(current->result.type == ETYPE_POINT);
diff --git a/src/solve.c b/src/solve.c
index 5c0016c..9a629f4 100644
--- a/src/solve.c
+++ b/src/solve.c
@@ -60,23 +60,23 @@ static void add_frontier(struct frontier *frontier, struct component *component)
frontier->elems[frontier->n++] = component;
}
-static void build_angle_point_line(struct drawing *drawing, struct component *local_i, struct component *local_j, struct component *oppo_i, bool swap) {
+static void build_angle_point_line(struct drawing *drawing, struct constraint *i, struct constraint *j, struct component *local_i, struct component *local_j, struct component *oppo_i) {
assert(local_i->e != NULL);
assert(local_j->e != NULL);
assert(local_i->type == COM_LINE);
assert(local_j->type == COM_POINT);
struct element *theta = insert_cmd(drawing, (struct command){
.op = CMD_VALUE_INPUT,
+ .index = i->order-1,
.result.type = ETYPE_VALUE,
});
struct element *d = insert_cmd(drawing, (struct command){
.op = CMD_VALUE_INPUT,
+ .index = j->order-1,
.result.type = ETYPE_VALUE,
});
- if(swap) SWAP(theta, d);
-
struct element* l = insert_cmd(drawing, (struct command){
.op = CMD_LINE_POINT_LINE_ANGLE,
.hidden = !oppo_i->show_when_placed,
@@ -394,11 +394,13 @@ static void draw_solution(struct constraint *constraints, size_t fix, struct sol
} else {
struct element *d1 = insert_cmd(drawing, (struct command){
.op = CMD_VALUE_INPUT,
+ .index = constraints[step->i].order-1,
.result.type = ETYPE_VALUE,
});
struct element *d2 = insert_cmd(drawing, (struct command){
.op = CMD_VALUE_INPUT,
+ .index = constraints[step->j].order-1,
.result.type = ETYPE_VALUE,
});
@@ -434,10 +436,12 @@ static void draw_solution(struct constraint *constraints, size_t fix, struct sol
struct element *d1 = insert_cmd(drawing, (struct command){
.op = CMD_VALUE_INPUT,
+ .index = constraints[step->i].order-1,
.result.type = ETYPE_VALUE,
});
struct element *d2 = insert_cmd(drawing, (struct command){
.op = CMD_VALUE_INPUT,
+ .index = constraints[step->j].order-1,
.result.type = ETYPE_VALUE,
});
@@ -472,10 +476,12 @@ static void draw_solution(struct constraint *constraints, size_t fix, struct sol
struct element *d1 = insert_cmd(drawing, (struct command){
.op = CMD_VALUE_INPUT,
+ .index = constraints[step->i].order-1,
.result.type = ETYPE_VALUE,
});
struct element *d2 = insert_cmd(drawing, (struct command){
.op = CMD_VALUE_INPUT,
+ .index = constraints[step->j].order-1,
.result.type = ETYPE_VALUE,
});
@@ -511,7 +517,7 @@ static void draw_solution(struct constraint *constraints, size_t fix, struct sol
constraints[step->i].forward = step->i_forward;
constraints[step->j].forward = step->j_forward;
- build_angle_point_line(drawing, local_i, local_j, oppo_i, false);
+ build_angle_point_line(drawing, &constraints[step->i], &constraints[step->j], local_i, local_j, oppo_i);
} else if(constraints[step->i].type == CT_POINT_LINE_DISTANCE
&& local_i->type == COM_POINT
&& constraints[step->j].type == CT_LINE_LINE_ANGLE
@@ -521,7 +527,7 @@ static void draw_solution(struct constraint *constraints, size_t fix, struct sol
constraints[step->i].forward = step->i_forward;
constraints[step->j].forward = step->j_forward;
- build_angle_point_line(drawing, local_j, local_i, oppo_i, true);
+ build_angle_point_line(drawing, &constraints[step->j], &constraints[step->i], local_j, local_i, oppo_i);
} else if(constraints[step->i].type == CT_POINT_LINE_DISTANCE
&& local_i->type == COM_LINE
&& constraints[step->j].type == CT_POINT_POINT_DISTANCE
@@ -530,10 +536,12 @@ static void draw_solution(struct constraint *constraints, size_t fix, struct sol
struct element *d1 = insert_cmd(drawing, (struct command){
.op = CMD_VALUE_INPUT,
+ .index = constraints[step->i].order-1,
.result.type = ETYPE_VALUE,
});
struct element *d2 = insert_cmd(drawing, (struct command){
.op = CMD_VALUE_INPUT,
+ .index = constraints[step->j].order-1,
.result.type = ETYPE_VALUE,
});