diff --git a/poly2d/Makefile b/poly2d/Makefile index 11b0e59..83ce5f2 100644 --- a/poly2d/Makefile +++ b/poly2d/Makefile @@ -23,7 +23,7 @@ OBJS = v2d_intersect.o v2d_line_distance.o \ CFLAGS_WARN = -Wall -Wshadow -Wmissing-prototypes \ -Wmissing-declarations -Wno-format-zero-length -CFLAGS = $(CFLAGS_WARN) -g +CFLAGS = $(CFLAGS_WARN) -g -std=gnu99 CXXFLAGS = -Wall -frounding-math LDFLAGS = LDLIBS = -lm diff --git a/poly2d/poly2d.h b/poly2d/poly2d.h index fec85ff..2b5cb9e 100644 --- a/poly2d/poly2d.h +++ b/poly2d/poly2d.h @@ -30,6 +30,34 @@ struct p2d { }; +/* + * forall_v2d* need -std=gnu99 + */ + +#define forall_v2d_once(var, first) \ + for (const struct v2d *__fv2do_0 = (var = (first)); \ + var; \ + var = var->next == __fv2do_0 ? NULL : var->next) + +#define forall_v2d(var, first) \ + for (const struct v2d *__fv2d_0 = (var = (first)); \ + var; \ + ({ \ + var = __fv2d_0 ? var->next : NULL; \ + if (var == __fv2d_0) \ + __fv2d_0 = NULL; \ + })) + +#define forall_edges(a, b, first) \ + for (const struct v2d *__fe_0 = \ + (a = (first), b = a ? a->next : a, a); \ + a && b; \ + ({ \ + a = b; \ + b = b == __fe_0 ? NULL : b->next; \ + })) + + /* * Polygon creation */ diff --git a/poly2d/test/Common b/poly2d/test/Common index 2787aaa..deb88bf 100755 --- a/poly2d/test/Common +++ b/poly2d/test/Common @@ -14,6 +14,7 @@ compile_and_run() { + CFLAGS="-Wall -Werror -g -std=gnu99 -I.." LIBS="-lpoly2d -lCGAL -lCGAL_Core -lboost_thread" LIBS="$LIBS -lstdc++ -lmpfr -lgmp -lm" @@ -54,7 +55,7 @@ int main(void) return 0; } EOF - gcc -Wall -Werror -g -I.. _.c -L.. $LIBS || return + gcc $CFLAGS _.c -L.. $LIBS || return $VALGRIND ./a.out } diff --git a/poly2d/test/forall b/poly2d/test/forall new file mode 100755 index 0000000..fd88dec --- /dev/null +++ b/poly2d/test/forall @@ -0,0 +1,121 @@ +#!/bin/sh +. ./Common + +############################################################################### + +tst "forall_v2d_once, open polygon" <v) + printf("%g %g\n", v->x, v->y); +EOF + +expect <v) + printf("%g %g\n", v->x, v->y); +EOF + +expect <v) + printf("%g %g\n", v->x, v->y); +EOF + +expect <v) + printf("%g %g\n", v->x, v->y); +EOF + +expect <v) + printf("%g %g %g %g\n", a->x, a->y, b->x, b->y); +EOF + +expect <v) + printf("%g %g %g %g\n", a->x, a->y, b->x, b->y); +EOF + +expect <