summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/construction.c9
-rw-r--r--src/main.c21
-rw-r--r--src/solve.c28
3 files changed, 36 insertions, 22 deletions
diff --git a/src/construction.c b/src/construction.c
index b73ee69..209b167 100644
--- a/src/construction.c
+++ b/src/construction.c
@@ -66,13 +66,20 @@ struct element* insert_cmd(struct drawing *drawing, struct command cmd) {
return &new->result;
}
+#define SETSIGN(b, v) ((v) * ((2 * (b)) - 1))
void execute_drawing(struct drawing *drawing, double inputs[]) {
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[current->index];
+ current->result.value = SETSIGN(current->dir, inputs[current->index]);
+ }break;
+ case CMD_OFFSET_INPUT: {
+ assert(current->arg1->type == ETYPE_VALUE);
+ assert(current->result.type == ETYPE_VALUE);
+ current->result.value = current->arg1->value + SETSIGN(current->dir, inputs[current->index]);
+ current->result.value -= (M_PI*2.0) * floor(current->result.value / (M_PI*2.0));
}break;
case CMD_ORIGIN: {
assert(current->result.type == ETYPE_POINT);
diff --git a/src/main.c b/src/main.c
index 7f3ec26..964c5c0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -321,26 +321,11 @@ int main(int argc, char *argv[]) {
struct drawing drawing = {};
solve_constraints(&constraints, &drawing);
+ // Copy over all the parameter values to a new array
+ // @PERF: Maybe we should just store them in a separate array to start with
double *params = malloc(sizeof(double) * (constraints.length));
for(size_t i = 0; i < constraints.length; i++) {
- if(!constraints.elements[i].used) continue;
- if(constraints.elements[i].order == 0) continue;
-
- params[i] = SETSIGN(constraints.elements[i].forward, constraints.elements[i].v);
-
- // We need to offset angles based on the path we took to use this
- // constraint
- if(constraints.elements[i].path[0].i != -1) {
- // printf("PATH %ld order %llu\n", i, constraints[i].order-1);
- for(struct path_step *p = constraints.elements[i].path; p <= constraints.elements[i].path+SEARCH_DEPTH && p->i != -1; p++) {
- params[i] += SETSIGN(p->direction, constraints.elements[p->i].v);
- // printf("%llu [%d:%f] [%f] -> ", p->i, p->direction, constraints[p->i].v, params[constraints[i].order-1]);
- }
- // printf("\n");
- params[i] -= (M_PI*2.0) * floor(params[i] / (M_PI*2.0));
- // printf("Final Angle is %f\n", params[constraints[i].order-1]);
- }
-
+ params[i] = constraints.elements[i].v;
}
execute_drawing(&drawing, params);
diff --git a/src/solve.c b/src/solve.c
index be16663..2a4fa57 100644
--- a/src/solve.c
+++ b/src/solve.c
@@ -60,7 +60,7 @@ static void add_frontier(struct frontier *frontier, struct component *component)
frontier->elems[frontier->n++] = component;
}
-static void build_angle_point_line(struct drawing *drawing, size_t index_i, size_t index_j, struct component *local_i, struct component *local_j, struct component *oppo_i) {
+static void build_angle_point_line(struct drawing *drawing, struct constraint *constraints, size_t index_i, size_t index_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);
@@ -68,12 +68,24 @@ static void build_angle_point_line(struct drawing *drawing, size_t index_i, size
struct element *theta = insert_cmd(drawing, (struct command){
.op = CMD_VALUE_INPUT,
.index = index_i,
+ .dir = constraints[index_i].forward,
.result.type = ETYPE_VALUE,
});
+ for(struct path_step *p = constraints[index_i].path; p <= constraints[index_i].path+SEARCH_DEPTH && p->i != -1; p++) {
+ theta = insert_cmd(drawing, (struct command){
+ .op = CMD_OFFSET_INPUT,
+ .arg1 = theta,
+ .index = p->i,
+ .dir = p->direction,
+ .result.type = ETYPE_VALUE,
+ });
+ }
+
struct element *d = insert_cmd(drawing, (struct command){
.op = CMD_VALUE_INPUT,
.index = index_j,
+ .dir = constraints[index_i].forward,
.result.type = ETYPE_VALUE,
});
@@ -325,6 +337,8 @@ static void draw_solution(struct constraint *constraints, size_t fix, struct sol
struct element *distance = insert_cmd(drawing, (struct command){
.op = CMD_VALUE_INPUT,
+ .index = 0,
+ .dir = constraints[fix].forward,
.result.type = ETYPE_VALUE,
});
@@ -395,12 +409,14 @@ 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 = step->i,
+ .dir = constraints[step->i].forward,
.result.type = ETYPE_VALUE,
});
struct element *d2 = insert_cmd(drawing, (struct command){
.op = CMD_VALUE_INPUT,
.index = step->j,
+ .dir = constraints[step->j].forward,
.result.type = ETYPE_VALUE,
});
@@ -437,11 +453,13 @@ 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 = step->i,
+ .dir = constraints[step->i].forward,
.result.type = ETYPE_VALUE,
});
struct element *d2 = insert_cmd(drawing, (struct command){
.op = CMD_VALUE_INPUT,
.index = step->j,
+ .dir = constraints[step->j].forward,
.result.type = ETYPE_VALUE,
});
@@ -477,11 +495,13 @@ 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 = step->i,
+ .dir = constraints[step->i].forward,
.result.type = ETYPE_VALUE,
});
struct element *d2 = insert_cmd(drawing, (struct command){
.op = CMD_VALUE_INPUT,
.index = step->j,
+ .dir = constraints[step->j].forward,
.result.type = ETYPE_VALUE,
});
@@ -517,7 +537,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, step->i, step->j, local_i, local_j, oppo_i);
+ build_angle_point_line(drawing, constraints, step->i, 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
@@ -527,7 +547,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, step->j, step->i, local_j, local_i, oppo_i);
+ build_angle_point_line(drawing, constraints, step->j, 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
@@ -537,11 +557,13 @@ 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 = step->i,
+ .dir = constraints[step->i].forward,
.result.type = ETYPE_VALUE,
});
struct element *d2 = insert_cmd(drawing, (struct command){
.op = CMD_VALUE_INPUT,
.index = step->j,
+ .dir = constraints[step->j].forward,
.result.type = ETYPE_VALUE,
});