diff options
| -rw-r--r-- | src/construction.c | 7 | ||||
| -rw-r--r-- | src/main.c | 21 | ||||
| -rw-r--r-- | test/construction.c | 83 |
3 files changed, 97 insertions, 14 deletions
diff --git a/src/construction.c b/src/construction.c index 4ef38de..918ceef 100644 --- a/src/construction.c +++ b/src/construction.c @@ -126,8 +126,8 @@ void execute_drawing(struct drawing *drawing, double inputs[]) { if(current->arg1->circle.radius == 0 && current->arg2->circle.radius == 0) { // The tangent is just a line through the two centers - // @FAST: This is wasteful. If the the procedure too the - // two vectors directly, we wouldn't have to copy here. + // @FAST: This is wasteful. If the procedure took the two + // vectors directly, we wouldn't have to copy here. struct point p1; glm_vec2_copy(current->arg1->circle.center, p1.pos); struct point p2; @@ -156,7 +156,8 @@ void execute_drawing(struct drawing *drawing, double inputs[]) { }break; case CMD_POINT_CIRCLE_CIRCLE: { assert(current->result.type == ETYPE_POINT); - vec2 between_centers; glm_vec2_sub(current->arg1->circle.center, current->arg2->circle.center, between_centers); + vec2 between_centers; + glm_vec2_sub(current->arg1->circle.center, current->arg2->circle.center, between_centers); glm_vec2_mul(between_centers, (vec2){2, 2}, between_centers); double a = between_centers[0]; double b = between_centers[1]; @@ -1141,13 +1141,13 @@ int main(int argc, char *argv[]) { }, { .type = CT_POINT_POINT_DISTANCE, - .v = 10, + .v = 7, .c1 = &components[1], .c2 = &components[2], }, { .type = CT_POINT_POINT_DISTANCE, - .v = 10, + .v = 7, .c1 = &components[2], .c2 = &components[0], }, @@ -1360,8 +1360,8 @@ int main(int argc, char *argv[]) { { .type = CT_LINE_LINE_ANGLE, .v = M_PI/2, - .c1 = &box.side[3], - .c2 = &box.side[0], + .c1 = &box.side[0], + .c2 = &box.side[3], }, { .type = CT_LINE_LINE_ANGLE, @@ -1371,9 +1371,9 @@ int main(int argc, char *argv[]) { }, { .type = CT_LINE_LINE_ANGLE, - .v = M_PI/2, - .c1 = &box.side[2], - .c2 = &box.side[3], + .v = M_PI/2.9, + .c1 = &box.side[3], + .c2 = &box.side[2], }, { .type = CT_LINE_LINE_ANGLE, @@ -1384,14 +1384,14 @@ int main(int argc, char *argv[]) { { .type = CT_POINT_POINT_DISTANCE, - .v = 10, - .c1 = &line.corner_start, + .v = 9.5, + .c1 = &line.corner_end, .c2 = &box.corner[0], }, { .type = CT_POINT_POINT_DISTANCE, .v = 10, - .c1 = &line.corner_end, + .c1 = &line.corner_start, .c2 = &box.corner[0], }, @@ -1449,6 +1449,7 @@ int main(int argc, char *argv[]) { if(drawing.error != NULL) { plot_generic(*drawing.error->arg1); plot_generic(*drawing.error->arg2); + fprintf(stderr, "Solver error detected. Drawing will be incomplete\n"); } // plot_line_between(components[0].e->point, components[1].e->point); diff --git a/test/construction.c b/test/construction.c index 10a377c..9ff6a20 100644 --- a/test/construction.c +++ b/test/construction.c @@ -63,6 +63,7 @@ int main(int argc, char *argv[]) { execute_drawing(&drawing, (double[]){1, 1}); + assert(drawing.error == NULL); assert(p3->point.pos[0] == 0.5 && fabs(p3->point.pos[1] - 0.866025) < 0.001); } @@ -128,6 +129,86 @@ int main(int argc, char *argv[]) { execute_drawing(&drawing, (double[]){1, 1}); - assert(p3->point.pos[0] == 0.5 && fabs(p3->point.pos[1] - 0.866025) < 0.001); + assert(drawing.error == NULL); + assert(p3->point.pos[0] == 0.5 && fabs(p3->point.pos[1] - (-0.866025)) < 0.001); + } + + { + struct drawing drawing = {}; + + struct element* origin = insert_cmd(&drawing, (struct command){ + .op = CMD_ORIGIN, + .hidden = true, + .result.type = ETYPE_POINT, + }); + + struct element *xaxis = insert_cmd(&drawing, (struct command){ + .op = CMD_LINE_X, + .hidden = true, + .result.type = ETYPE_LINE, + }); + + struct element* rspace = insert_cmd(&drawing, (struct command){ + .op = CMD_VALUE_INPUT, + .hidden = true, + .result.type = ETYPE_VALUE, + }); + + struct element *cspace = insert_cmd(&drawing, (struct command){ + .op = CMD_CIRCLE_CENTER_RADIUS, + .hidden = true, + .result.type = ETYPE_CIRCLE, + .arg1 = origin, + .arg2 = rspace, + }); + + struct element *p2 = insert_cmd(&drawing, (struct command){ + .op = CMD_POINT_CIRCLE_LINE, + .hidden = true, + .result.type = ETYPE_POINT, + .arg1 = cspace, + .arg2 = xaxis, + }); + + struct element* r1 = insert_cmd(&drawing, (struct command){ + .op = CMD_VALUE_INPUT, + .hidden = true, + .result.type = ETYPE_VALUE, + }); + + struct element *c1 = insert_cmd(&drawing, (struct command){ + .op = CMD_CIRCLE_CENTER_RADIUS, + .hidden = true, + .result.type = ETYPE_CIRCLE, + .arg1 = origin, + .arg2 = r1, + }); + + struct element* r2 = insert_cmd(&drawing, (struct command){ + .op = CMD_VALUE_INPUT, + .hidden = true, + .result.type = ETYPE_VALUE, + }); + + struct element *c2 = insert_cmd(&drawing, (struct command){ + .op = CMD_CIRCLE_CENTER_RADIUS, + .hidden = true, + .result.type = ETYPE_CIRCLE, + .arg1 = p2, + .arg2 = r2, + }); + + struct element *p3 = insert_cmd(&drawing, (struct command){ + .op = CMD_POINT_CIRCLE_CIRCLE, + .hidden = true, + .result.type = ETYPE_POINT, + .arg1 = c2, + .arg2 = c1, + }); + + execute_drawing(&drawing, (double[]){2, 1, 4}); + + assert(&drawing.error != NULL); + assert(&drawing.error->result == p3); } } |
