summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJesper Jensen <jesper@jnsn.dev>2026-04-06 09:43:13 +0200
committerJesper Jensen <jesper@jnsn.dev>2026-04-06 13:02:39 +0200
commit57ad11effae4e9562253d1fcf38469bd3d5ae69c (patch)
tree5520ed05e1421a1969a878f42a14b0cd706fb1e5 /examples
parent40190bc4e1a994a3faf5f5477d9f6e8b73ffe95d (diff)
Refactor the trangle building as propgation style
Diffstat (limited to 'examples')
-rw-r--r--examples/mount.c43
-rw-r--r--examples/triangle_tip.c2
2 files changed, 3 insertions, 42 deletions
diff --git a/examples/mount.c b/examples/mount.c
index 7f4ba15..bd0ace5 100644
--- a/examples/mount.c
+++ b/examples/mount.c
@@ -1,46 +1,5 @@
#include "cad.h"
-
-static const char *component_type_name[] = {
- [COM_POINT] = "point",
- [COM_LINE] = "line",
-};
-
-static void print_subassemblies(struct constraints *c, struct subassembly *assemblies, size_t assemblies_num) {
- fprintf(stderr, "=== Subassemblies: %zu ===\n", assemblies_num);
- for(size_t i = 0; i < assemblies_num; i++) {
- struct subassembly *a = &assemblies[i];
- fprintf(stderr, "Assembly %zu: %zu steps, fix=%zu, fixed=%s\n",
- i, a->steps_num, a->fix, a->fixed ? "yes" : "no");
-
- if(a->articulation_num > 0) {
- fprintf(stderr, " Articulations (%zu):\n", a->articulation_num);
- for(size_t j = 0; j < a->articulation_num; j++) {
- struct component *comp = a->articulation[j];
- fprintf(stderr, " [%zu] %s %p\n", j, component_type_name[comp->type], (void*)comp);
- }
- }
-
- fprintf(stderr, " Constraints used:\n");
- for(size_t j = 0; j < c->length; j++) {
- struct constraint *ct = &c->elements[j];
- if(ct->used != i + 1) continue;
- fprintf(stderr, " [%zu] %s v=%.2f (%s %p, %s %p)\n",
- j, constraint_type_name[ct->type], ct->v,
- component_type_name[ct->c1->type], (void*)ct->c1,
- component_type_name[ct->c2->type], (void*)ct->c2);
- }
- }
- fprintf(stderr, " Unused constraints:\n");
- for(size_t j = 0; j < c->length; j++) {
- struct constraint *ct = &c->elements[j];
- if(ct->used != 0) continue;
- fprintf(stderr, " [%zu] %s v=%.2f (%s %p, %s %p)\n",
- j, constraint_type_name[ct->type], ct->v,
- component_type_name[ct->c1->type], (void*)ct->c1,
- component_type_name[ct->c2->type], (void*)ct->c2);
- }
- fprintf(stderr, "=========================\n");
-}
+#include "cad/debug.h"
void draw_from_constraints(struct constraints *c, struct topology *t, struct canvas *cv) {
struct drawing drawing = {};
diff --git a/examples/triangle_tip.c b/examples/triangle_tip.c
index 4da57da..0781377 100644
--- a/examples/triangle_tip.c
+++ b/examples/triangle_tip.c
@@ -1,4 +1,5 @@
#include "cad.h"
+#include "cad/debug.h"
void draw_from_constraints(struct constraints *c, struct topology *t, struct canvas *cv) {
struct drawing drawing = {};
@@ -18,6 +19,7 @@ void draw_from_constraints(struct constraints *c, struct topology *t, struct can
free(params);
reconstruct_drawing(c, assemblies, &assemblies_num);
+ print_subassemblies(c, assemblies, assemblies_num);
begin_drawing(cv);
draw_topology(cv, t);