diff --git a/slicer/slice.c b/slicer/slice.c index 38b794b..cdc05aa 100644 --- a/slicer/slice.c +++ b/slicer/slice.c @@ -71,17 +71,26 @@ static void mark_z(float z) static void add(const struct v *a, const struct v *b, const struct v *c) { + float cross; struct z *z; struct line *line; - /* @@@ should check that C is above AB */ - if (eq(a->x, b->x) && eq(a->y, b->y)) { fprintf(stderr, "zero point\n"); return; } + if (c->z < a->z) return; + + cross = (b->x - a->x) * (c->y - a->y) - (b->y - a->y) * (c->x - a->x); + if (!eq(cross, 0)) { + fprintf(stderr, + "inclined facet\n\t%f %f %f\n\t%f %f %f\n\t%f %f %f\n", + a->x, a->y, a->z, b->x, b->y, b->z, c->x, c->y, c->z); + exit(1); + } + z = get_z(a->z); line = alloc_type(struct line); line->ax = a->x;