diff options
| -rw-r--r-- | src/solve.c | 9 | ||||
| -rw-r--r-- | test/solve.c | 47 |
2 files changed, 56 insertions, 0 deletions
diff --git a/src/solve.c b/src/solve.c index 31c7947..5cdff63 100644 --- a/src/solve.c +++ b/src/solve.c @@ -680,5 +680,14 @@ bool solve_constraints(struct constraints *constraints, struct drawing *drawing) memcpy(alias->alias, alias->target, sizeof(struct component)); } + // Check for unsolved constraints + for(size_t i = 0; i < constraints->length; i++) { + if(!constraints->elements[i].used) { + free(steps); + return false; + } + } + + free(steps); return true; } diff --git a/test/solve.c b/test/solve.c new file mode 100644 index 0000000..ea767f4 --- /dev/null +++ b/test/solve.c @@ -0,0 +1,47 @@ +#include "cad/solve.h" +#include <assert.h> + +int main(int argc, char *argv[]) { + { + 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}; + + 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 the topmost point + PP_DISTANCE(&p4, &p5, 30), + PP_DISTANCE(&p3, &p4, 30), + PP_DISTANCE(&p3, &p5, 30), + + 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); + } + + return 0; +} |
