diff options
| author | Jesper Jensen <jesper@jnsn.dev> | 2026-03-11 21:59:34 +0100 |
|---|---|---|
| committer | Jesper Jensen <jesper@jnsn.dev> | 2026-03-11 21:59:34 +0100 |
| commit | cd1df8f7cb64539842eaad425df5fa7ec9c87fb5 (patch) | |
| tree | e84450ddc91fc3785571267af89c3fbc292a85df /test/solve.c | |
| parent | 96c91046d390b6d5c557ed0a574eacd407cce48c (diff) | |
Add an example for non-solvable figure
Diffstat (limited to 'test/solve.c')
| -rw-r--r-- | test/solve.c | 118 |
1 files changed, 117 insertions, 1 deletions
diff --git a/test/solve.c b/test/solve.c index b52d5f9..06038c9 100644 --- a/test/solve.c +++ b/test/solve.c @@ -3,6 +3,117 @@ int main(int argc, char *argv[]) { { + printf("Triangle by 3 distances\n"); + struct constraints constraints = {}; + + struct component p1 = {.type = COM_POINT}; + struct component p2 = {.type = COM_POINT}; + struct component p3 = {.type = COM_POINT}; + + add_constraint(&constraints, (struct constraint[]){ + PP_DISTANCE(&p1, &p2, 30), + PP_DISTANCE(&p1, &p3, 30), + PP_DISTANCE(&p2, &p3, 30), + CEND(), + }); + + struct drawing drawing = {}; + bool solved = solve_constraints(&constraints, &drawing); + + assert(solved); + + free_drawing(&drawing); + free_constraints(&constraints); + } + + { + printf("Triangle by 2 angles and a distance\n"); + struct constraints constraints = {}; + + struct component l1 = {.type = COM_LINE}; + struct component l2 = {.type = COM_LINE}; + struct component l3 = {.type = COM_LINE}; + + struct component p1 = {.type = COM_POINT}; + struct component p2 = {.type = COM_POINT}; + struct component p3 = {.type = COM_POINT}; + + add_constraint(&constraints, (struct constraint[]){ + POINT_ON_LINE(&p1, &l3), + POINT_ON_LINE(&p1, &l1), + + POINT_ON_LINE(&p2, &l1), + POINT_ON_LINE(&p2, &l2), + + POINT_ON_LINE(&p3, &l2), + POINT_ON_LINE(&p3, &l3), + + PP_DISTANCE(&p1, &p2, 30), + LL_ANGLE(&l1, &l2, DEG(60)), + LL_ANGLE(&l2, &l3, DEG(60)), + CEND(), + }); + + struct drawing drawing = {}; + bool solved = solve_constraints(&constraints, &drawing); + + assert(solved); + + free_drawing(&drawing); + free_constraints(&constraints); + } + + { + printf("Two triangles sharing a point one defined by angles\n"); + struct constraints constraints = {}; + + struct component p1 = {.type = COM_POINT}; + struct component p2 = {.type = COM_POINT}; + struct component p3 = {.type = COM_POINT}; + + struct component p4 = {.type = COM_POINT}; + struct component p5 = {.type = COM_POINT}; + + struct component t1base = {.type = COM_LINE}; + struct component t2base = {.type = COM_LINE}; + struct component t2side = {.type = COM_LINE}; + + add_constraint(&constraints, (struct constraint[]){ + // Make a triangle + PP_DISTANCE(&p1, &p2, 30), + PP_DISTANCE(&p1, &p3, 30), + PP_DISTANCE(&p2, &p3, 30), + + POINT_ON_LINE(&p1, &t1base), + POINT_ON_LINE(&p2, &t1base), + + // With another triangle sharing a point + PP_DISTANCE(&p4, &p5, 30), + PP_DISTANCE(&p3, &p4, 30), + + LL_ANGLE(&t2side, &t2base, DEG(60)), + + POINT_ON_LINE(&p3, &t2side), + POINT_ON_LINE(&p4, &t2side), + + POINT_ON_LINE(&p4, &t2base), + POINT_ON_LINE(&p5, &t2base), + + // The edge they don't share is constrained + LL_ANGLE(&t1base, &t2base, DEG(40)), + CEND(), + }); + + struct drawing drawing = {}; + bool solved = solve_constraints(&constraints, &drawing); + assert(solved); + + free_drawing(&drawing); + free_constraints(&constraints); + } + + { + printf("Two triangles sharing a point with an angle constrained base\n"); struct constraints constraints = {}; struct component p1 = {.type = COM_POINT}; @@ -24,7 +135,7 @@ int main(int argc, char *argv[]) { POINT_ON_LINE(&p1, &t1base), POINT_ON_LINE(&p2, &t1base), - // With another triangle sharing the topmost point + // With another triangle sharing a point PP_DISTANCE(&p4, &p5, 30), PP_DISTANCE(&p3, &p4, 30), PP_DISTANCE(&p3, &p5, 30), @@ -40,7 +151,12 @@ int main(int argc, char *argv[]) { struct drawing drawing = {}; bool solved = solve_constraints(&constraints, &drawing); + // @COMPL: We don't currently know how to derive an angle constraint + // from the rigid triangle. We'd probably need to do some sort of + // recursive solving, and even then you can't construct it without some + // sort of math in the construction phase. assert(!solved); + // assert(solved); free_drawing(&drawing); free_constraints(&constraints); |
