From bfbecd4a3639fb4b8c85f0637c612bb65ef7ec99 Mon Sep 17 00:00:00 2001 From: Jesper Jensen Date: Sun, 27 Sep 2026 23:39:11 +0200 Subject: Closer to drawing the box and lines We're stilling missing the lines somehow --- src/construction.c | 57 +++++++++++++++- src/solve.c | 187 +++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 187 insertions(+), 57 deletions(-) (limited to 'src') diff --git a/src/construction.c b/src/construction.c index 2177fba..0da289a 100644 --- a/src/construction.c +++ b/src/construction.c @@ -110,6 +110,7 @@ static void transform_part(struct command *cmd, const struct command *last_cmd, case CMD_VALUE_INPUT: case CMD_OFFSET_INPUT: case CMD_MEASURE_POINT_LINE_DISTANCE: + case CMD_MEASURE_POINT_POINT_DISTANCE: case CMD_MEASURE_LINE_LINE_ANGLE: break; case CMD_LINE_X: @@ -141,6 +142,7 @@ static void transform_part(struct command *cmd, const struct command *last_cmd, case CMD_IMPORT_POINT_LINE: case CMD_IMPORT_LINE_LINE: + case CMD_IMPORT_POINT_POINT: transform_part(cmd->d->first_command, cmd->d->last_command, transform); break; } @@ -196,7 +198,10 @@ void dump_program(struct drawing *drawing, double inputs[]) { fprintf(stderr, "%p -> CCP(%p, %p) = ((x-%f)^2 + (y-%f)^2 = %f^2)\n", ¤t->result, current->arg1, current->arg2, current->result.circle.center[0], current->result.circle.center[1], current->result.circle.radius); }break; case CMD_IMPORT_POINT_LINE: { - fprintf(stderr, "%p -> IMP(%p, %p, %p, %p) = \n", ¤t->result, current->arg1, current->arg2, current->attachp, current->attachl); + fprintf(stderr, "%p -> IPL(%p, %p, %p, %p) = \n", ¤t->result, current->arg1, current->arg2, current->attachp, current->attachl); + }break; + case CMD_IMPORT_POINT_POINT: { + fprintf(stderr, "%p -> IPP(%p, %p, %p, %p) = \n", ¤t->result, current->arg1, current->arg2, current->attachp, current->attachl); }break; case CMD_IMPORT_LINE_LINE: { // Deprecated @@ -204,6 +209,9 @@ void dump_program(struct drawing *drawing, double inputs[]) { case CMD_MEASURE_POINT_LINE_DISTANCE: { fprintf(stderr, "%p -> MPL(%p, %p) = %f\n", ¤t->result, current->arg1, current->arg2, current->result.value); }break; + case CMD_MEASURE_POINT_POINT_DISTANCE: { + fprintf(stderr, "%p -> MPP(%p, %p) = %f\n", ¤t->result, current->arg1, current->arg2, current->result.value); + }break; case CMD_MEASURE_LINE_LINE_ANGLE: { fprintf(stderr, "%p -> MLL(%p, %p) = %f\n", ¤t->result, current->arg1, current->arg2, current->result.value); }break; @@ -371,6 +379,45 @@ void place_points(struct drawing *drawing, double inputs[]) { fprintf(stderr, "Assembly %p %p %p %f %f %f\n", current->d, current->d->first_command, current->d->last_command, transform[2][0], transform[2][1], theta); transform_part(current->d->first_command, current->d->last_command, transform); }break; + case CMD_IMPORT_POINT_POINT: { + assert(current->arg1->type == ETYPE_POINT); + assert(current->arg2->type == ETYPE_POINT); + + assert(current->d != NULL); + assert(current->attachp != NULL); + assert(current->attachl != NULL); + assert(current->attachp->type == ETYPE_POINT); + assert(current->attachl->type == ETYPE_POINT); + + struct line l1; + line_through_points(current->arg1->point, current->arg2->point, &l1); + fprintf(stderr, "theta %f %f\n", current->arg1->point.pos[0], current->arg1->point.pos[1]); + fprintf(stderr, "theta %f %f\n", current->arg2->point.pos[0], current->arg2->point.pos[1]); + struct line l2; + line_through_points(current->attachp->point, current->attachl->point, &l2); + fprintf(stderr, "theta %f %f\n", current->attachp->point.pos[0], current->attachp->point.pos[1]); + fprintf(stderr, "theta %f %f\n", current->attachl->point.pos[0], current->attachl->point.pos[1]); + + double theta; + // Align the two lines + theta = atan2(l1.norm[1], l1.norm[0]) - atan2(l2.norm[1], l2.norm[0]); + + mat3 transform; + glm_mat3_identity(transform); + + glm_translate2d(transform, current->arg1->point.pos); + + glm_rotate2d(transform, theta); + + { + vec2 negative_translate; + glm_vec2_negate_to(current->attachp->point.pos, negative_translate); + glm_translate2d(transform, negative_translate); + } + + fprintf(stderr, "PP Assembly %p %p %p %f %f %f\n", current->d, current->d->first_command, current->d->last_command, transform[2][0], transform[2][1], theta); + transform_part(current->d->first_command, current->d->last_command, transform); + }break; case CMD_IMPORT_LINE_LINE: { abort(); }break; @@ -382,6 +429,13 @@ void place_points(struct drawing *drawing, double inputs[]) { double dot = glm_vec2_dot(current->arg2->line.norm, current->arg1->point.pos); current->result.value = (dot + current->arg2->line.C) / glm_vec2_norm(current->arg2->line.norm); }break; + case CMD_MEASURE_POINT_POINT_DISTANCE: { + assert(current->arg1->type == ETYPE_POINT); + assert(current->arg2->type == ETYPE_POINT); + assert(current->result.type == ETYPE_VALUE); + + current->result.value = glm_vec2_distance(current->arg1->point.pos, current->arg2->point.pos); + }break; case CMD_MEASURE_LINE_LINE_ANGLE: { assert(current->arg1->type == ETYPE_LINE); assert(current->arg2->type == ETYPE_LINE); @@ -391,7 +445,6 @@ void place_points(struct drawing *drawing, double inputs[]) { current->result.value = theta; }break; } - // printf("%fx + %fy + %f = 0\n", cmd[2].line.norm[0], cmd[2].line.norm[1], cmd[2].line.C); } 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 -- cgit v1.2.3