From 9b33e6879b79905adfa415eba911d7e8b540429f Mon Sep 17 00:00:00 2001 From: Jesper Jensen Date: Sun, 19 Oct 2025 13:53:57 +0200 Subject: Add tests --- inc/cad/construction.h | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 inc/cad/construction.h (limited to 'inc/cad') diff --git a/inc/cad/construction.h b/inc/cad/construction.h new file mode 100644 index 0000000..eee5fa3 --- /dev/null +++ b/inc/cad/construction.h @@ -0,0 +1,80 @@ +#pragma once +#include + +enum operation { + CMD_VALUE_INPUT, + CMD_ORIGIN, + CMD_LINE_X, + CMD_CIRCLE_CENTER_RADIUS, + CMD_CIRCLE_CENTER_POINT, + CMD_LINE_POINT_POINT, + CMD_LINE_POINT_LINE_ANGLE, + CMD_POINT_CIRCLE_LINE, + CMD_POINT_CIRCLE_CIRCLE, + CMD_POINT_LINE_LINE, + + // Additional operations we need to handle explicitly to avoid degenerate + // cases + CMD_LINE_CIRCLE_CIRCLE_TANGENT, + CMD_LINE_LINE_DISTANCE_PARALLEL, +}; + +struct point { + vec2 pos; +}; + +struct circle { + vec2 center; + double radius; +}; + +struct line { + vec2 norm; + double C; +}; + +enum EType { + ETYPE_VALUE, + ETYPE_CIRCLE, + ETYPE_POINT, + ETYPE_LINE, +}; + +struct element { + enum EType type; + + union { + double value; + struct circle circle; + struct point point; + struct line line; + }; +}; + +struct command { + enum operation op; + uint8_t root; + bool hidden; + + struct element *arg1; + struct element *arg2; + struct element *arg3; + + struct element result; + + struct command *next; +}; + +struct drawing { + struct command *root; + struct command *tail; + + struct command *error; +}; + +struct element* insert_cmd(struct drawing *drawing, struct command cmd); +void execute_drawing(struct drawing *drawing, double inputs[]); + +bool circle_line_intersect(struct circle circle, struct line line, uint8_t root, struct point *point); +void line_through_points(struct point p1, struct point p2, struct line* l); +void line_line_intersect(struct line l1, struct line l2, struct point* p); -- cgit v1.2.3