summaryrefslogtreecommitdiff
path: root/inc/cad
diff options
context:
space:
mode:
Diffstat (limited to 'inc/cad')
-rw-r--r--inc/cad/construction.h80
1 files changed, 80 insertions, 0 deletions
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 <cglm/cglm.h>
+
+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);