From 6a12d4724b9c2e09e0d289a2f3fc77ee0e166001 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Thu, 8 Jan 2015 08:07:21 -0300 Subject: [PATCH] slicer/slice.c: repeat lower cuts at intermediate points --- slicer/slice.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/slicer/slice.c b/slicer/slice.c index 167bb07..38b794b 100644 --- a/slicer/slice.c +++ b/slicer/slice.c @@ -23,6 +23,7 @@ struct line { float ax, ay; float bx, by; + float cz; struct line *next; }; @@ -87,6 +88,7 @@ fprintf(stderr, "zero point\n"); line->ay = a->y; line->bx = b->x; line->by = b->y; + line->cz = c->z; line->next = z->lines; z->lines = line; } @@ -112,24 +114,38 @@ void slice(struct v f[3]) /* ----- Dumping ----------------------------------------------------------- */ -static gboolean dump(gpointer key, gpointer value, gpointer data) +static gboolean dump_layer(gpointer key, gpointer value, gpointer data) { - const struct z *z = value; + const struct z *z0 = data; + const struct z *z1 = value; const struct line *line; - if (!z->present) + if (z0->z > z1->z) return 0; - for (line = z->lines; line; line = line->next) - printf("%f %f %f\n%f %f %f\n\n\n", - line->ax, line->ay, z->z, - line->bx, line->by, z->z); + if (!z1->present) + return 0; + for (line = z0->lines; line; line = line->next) + if (line->cz >= z1->z) + printf("%f %f %f\n%f %f %f\n\n\n", + line->ax, line->ay, z1->z, + line->bx, line->by, z1->z); + return 0; +} + + +static gboolean dump_range(gpointer key, gpointer value, gpointer data) +{ + const struct z *z = value; + + if (z->present) + g_tree_foreach(tree, dump_layer, value); return 0; } void slice_dump(void) { - g_tree_foreach(tree, dump, NULL); + g_tree_foreach(tree, dump_range, NULL); }