summaryrefslogtreecommitdiff
path: root/inc/cad
diff options
context:
space:
mode:
authorJesper Jensen <jesper@jnsn.dev>2025-11-20 22:31:53 +0100
committerJesper Jensen <jesper@jnsn.dev>2025-11-20 22:31:53 +0100
commitacfa01613f6e7fbeace88a15df61252156d39cf1 (patch)
tree9d81120f36c1cd74dfe5d2691ccf55c8707cd394 /inc/cad
parent6e4df49832827e21c6d62f722767664e5cb9d575 (diff)
Separate everything out
Diffstat (limited to 'inc/cad')
-rw-r--r--inc/cad/solve.h18
-rw-r--r--inc/cad/svg.h19
-rw-r--r--inc/cad/topology.h50
-rw-r--r--inc/cad/util.h19
4 files changed, 105 insertions, 1 deletions
diff --git a/inc/cad/solve.h b/inc/cad/solve.h
index 4eae272..85b902b 100644
--- a/inc/cad/solve.h
+++ b/inc/cad/solve.h
@@ -22,6 +22,20 @@ struct component {
bool drawn;
};
+struct alias {
+ struct component *alias;
+ struct component *target;
+};
+
+struct constraints {
+ struct constraint *elements;
+ size_t length;
+ size_t capacity;
+
+ struct alias aliases[16];
+ size_t aliases_num;
+};
+
extern char *constraint_type_name[];
enum constraint_type {
CT_POINT_POINT_DISTANCE,
@@ -49,4 +63,6 @@ struct constraint {
bool used;
};
-bool solve_constraints(struct constraint *constraints, size_t constraints_num, struct drawing *drawing);
+void alias_point(struct constraints *c, struct component *alias, struct component *target);
+void add_constraint(struct constraints *c, struct constraint *new);
+bool solve_constraints(struct constraints *constraints, struct drawing *drawing);
diff --git a/inc/cad/svg.h b/inc/cad/svg.h
new file mode 100644
index 0000000..68634b8
--- /dev/null
+++ b/inc/cad/svg.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include "cad/solve.h"
+#include "cad/topology.h"
+
+enum LineStyle {
+ LSTYLE_NORMAL,
+ LSTYLE_CONSTRUCTION,
+ LSTYLE_INDICATOR,
+};
+#define TEXT_OFFSET 0.4
+
+void plot_line_between(struct point p1, struct point p2);
+void plot_arc_between_style(struct point c, struct point p1, struct point p2, enum LineStyle style);
+void plot_arc_between(struct point c, struct point p1, struct point p2);
+void plot_text(struct point p, double angle, char* str);
+
+void draw_constraints(struct constraints *constraints);
+void draw_topology(struct topology *topo);
diff --git a/inc/cad/topology.h b/inc/cad/topology.h
new file mode 100644
index 0000000..b3879b2
--- /dev/null
+++ b/inc/cad/topology.h
@@ -0,0 +1,50 @@
+#pragma once
+
+#include <stddef.h>
+
+#define TOPO_MOVETO(c) \
+ { .cmd = {TOPO_MOVETO} }, \
+ { .arg = {c} } \
+
+#define TOPO_LINETO(c) \
+ { .cmd = {TOPO_LINETO} }, \
+ { .arg = {c} } \
+
+#define TOPO_ARCTO(center, end) \
+ { .cmd = {TOPO_ARCTO} }, \
+ { .arg = {center} }, \
+ { .arg = {end} } \
+
+#define TOPO_END() \
+ { .cmd = {TOPO_END} } \
+
+enum topology_op {
+ TOPO_MOVETO,
+ TOPO_LINETO,
+ TOPO_ARCTO,
+
+ TOPO_END,
+};
+
+struct topology_cmd {
+ enum topology_op op;
+};
+
+struct topology_arg {
+ struct component *c;
+};
+
+struct topology_elem {
+ union {
+ struct topology_cmd cmd;
+ struct topology_arg arg;
+ };
+};
+
+struct topology {
+ struct topology_elem *elements;
+ size_t length;
+ size_t capacity;
+};
+
+void add_fragment(struct topology *topo, struct topology_elem *new);
diff --git a/inc/cad/util.h b/inc/cad/util.h
new file mode 100644
index 0000000..440d29b
--- /dev/null
+++ b/inc/cad/util.h
@@ -0,0 +1,19 @@
+#pragma once
+
+#include <assert.h>
+#include <limits.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+static void resize_buffer(void **buffer, size_t *capacity, size_t elems, size_t elemSize) {
+ assert(elems > 0);
+ uint64_t newpower = (sizeof(elems) * CHAR_BIT) - __builtin_clzl(elems-1);
+ elems = 1 << newpower;
+
+ if(elems != *capacity) {
+ *capacity = elems;
+ *buffer = realloc(*buffer, *capacity * elemSize);
+ }
+}
+