diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/construction.c | 22 | ||||
| -rw-r--r-- | src/debug.c | 4 | ||||
| -rw-r--r-- | src/main.c | 2 | ||||
| -rw-r--r-- | src/solve.c | 3 | ||||
| -rw-r--r-- | src/svg.c | 2 |
5 files changed, 19 insertions, 14 deletions
diff --git a/src/construction.c b/src/construction.c index 207dd0f..33f37ad 100644 --- a/src/construction.c +++ b/src/construction.c @@ -95,26 +95,25 @@ static void transform_part(struct command *cmd, const struct command *last_cmd, case CMD_LINE_LINE_DISTANCE_PARALLEL: // Find a point on the line, what point doesn't matter // since the whole line is moving - struct line line = cmd->result.line; + struct line *line = &cmd->result.line; vec2 p; glm_vec2_zero(p); - glm_vec2_muladds(line.norm, line.C, p); - double rec = glm_vec2_norm2(line.norm); - glm_vec2_divs(p, rec, p); + if(line->norm[0] > line->norm[1]) + glm_vec2_copy((vec2){-line->C / line->norm[0], 0}, p); + else + glm_vec2_copy((vec2){0, -line->C / line->norm[1]}, p); // Rotate the line to the new orientation - affine_transform_vec2(rotate, line.norm, line.norm); + affine_transform_vec2(rotate, line->norm, line->norm); // Transform the fixed point affine_transform_vec2(transform, p, p); // Calculate a C to follow the new point glm_vec2_negate(p); - line.C = glm_vec2_dot(line.norm, p); - - cmd->result.line = line; + line->C = glm_vec2_dot(line->norm, p); break; case CMD_CIRCLE_CENTER_RADIUS: case CMD_CIRCLE_CENTER_POINT: @@ -181,7 +180,9 @@ void place_points(struct drawing *drawing, double inputs[]) { // printf("Rotate %f\n", current->arg3->value); // printf("%f %f\n", current->arg2->line.norm[0], current->arg2->line.norm[1]); - glm_vec2_rotate(current->arg2->line.norm, current->arg3->value, current->result.line.norm); + double value = current->arg3->value; + value = current->root == 0 ? value : -value; + glm_vec2_rotate(current->arg2->line.norm, value, current->result.line.norm); // printf("%f %f\n", current->result.line.norm[0], current->result.line.norm[1]); vec2 offset = {-current->arg1->point.pos[0], -current->arg1->point.pos[1]}; @@ -275,6 +276,7 @@ void place_points(struct drawing *drawing, double inputs[]) { double theta; // Align the two lines theta = atan2(current->arg2->line.norm[1], current->arg2->line.norm[0]) - atan2(current->attachl->line.norm[1], current->attachl->line.norm[0]); + fprintf(stderr, "%f\n", theta / M_PI * 180.0); mat3 transform; glm_mat3_identity(transform); @@ -322,7 +324,7 @@ void place_points(struct drawing *drawing, double inputs[]) { } fprintf(stderr, "W %f %f\n", origin->result.point.pos[0], origin->result.point.pos[1]); - // transform_part(outer_object, NULL, transform); + transform_part(outer_object, NULL, transform); } } diff --git a/src/debug.c b/src/debug.c index 6027ed4..92540fc 100644 --- a/src/debug.c +++ b/src/debug.c @@ -30,11 +30,11 @@ void print_subassemblies(struct constraints *c, struct subassembly *assemblies, component_type_name[ct->c2->type], (void*)ct->c2); } } - fprintf(stderr, " Unused constraints:\n"); + fprintf(stderr, "Unused constraints:\n"); for(size_t j = 0; j < c->length; j++) { struct constraint *ct = &c->elements[j]; if(ct->used != 0) continue; - fprintf(stderr, " [%zu] %s v=%.2f (%s %p, %s %p)\n", + fprintf(stderr, " [%zu] %s v=%.2f (%s %p, %s %p)\n", j, constraint_type_name[ct->type], ct->v, component_type_name[ct->c1->type], (void*)ct->c1, component_type_name[ct->c2->type], (void*)ct->c2); @@ -1,4 +1,5 @@ #include "cad.h" +#include "cad/debug.h" struct smooth_line { struct component l1; @@ -130,6 +131,7 @@ void draw_from_constraints(struct constraints *c, struct topology *t, struct can place_points(&drawing, params); free(params); + print_subassemblies(c, assemblies, assembly_num); begin_drawing(cv); // for(struct command *current = drawing.root; current != NULL && current != drawing.error; current = current->next) { // if(current->hidden) continue; diff --git a/src/solve.c b/src/solve.c index 17a73d4..491cb6f 100644 --- a/src/solve.c +++ b/src/solve.c @@ -639,6 +639,7 @@ static void draw_for_subassembly(struct constraint *constraints, size_t fix, str .op = CMD_LINE_POINT_LINE_ANGLE, .hidden = !oppo_j->show_when_placed, .result.type = ETYPE_LINE, + .root = 1, .arg1 = p, .arg2 = local_j->e, .arg3 = theta, @@ -651,7 +652,7 @@ static void draw_for_subassembly(struct constraint *constraints, size_t fix, str .arg2 = l, .d = step->assembly, .attachp = oppo_i->e, - .attachl = oppo_k->e, + .attachl = oppo_j->e, }); } @@ -369,7 +369,7 @@ void begin_drawing(struct canvas *canvas) { assert(canvas->f != NULL); assert(canvas->state == CANVAS_INIT); - fprintf(canvas->f, "<svg version=\"1.1\" viewBox=\"-50 -50 100 100\" width=\"1200\" height=\"1200\" xmlns=\"http://www.w3.org/2000/svg\">\n"); + fprintf(canvas->f, "<svg version=\"1.1\" viewBox=\"-100 -150 200 200\" width=\"1200\" height=\"1200\" xmlns=\"http://www.w3.org/2000/svg\">\n"); fprintf(canvas->f, "<defs>\n"); fprintf(canvas->f, "\t<marker id=\"triangle\" viewBox=\"0 0 10 10\" refX=\"10\" refY=\"5\" markerUnits=\"strokeWidth\" markerWidth=\"6\" markerHeight=\"6\" orient=\"auto-start-reverse\">\n"); fprintf(canvas->f, "\t\t<path d=\"M 0 0 L 10 5 L 0 10 z\" fill=\"blue\" opacity=\"0.3\" />\n"); |
