From 57ad11effae4e9562253d1fcf38469bd3d5ae69c Mon Sep 17 00:00:00 2001 From: Jesper Jensen Date: Mon, 6 Apr 2026 09:43:13 +0200 Subject: Refactor the trangle building as propgation style --- examples/mount.c | 43 +------------------------------------------ examples/triangle_tip.c | 2 ++ 2 files changed, 3 insertions(+), 42 deletions(-) (limited to 'examples') 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); -- cgit v1.2.3