From 0bbbd51aa2cc215024c895e17c1cf05aba9fdca1 Mon Sep 17 00:00:00 2001 From: Barak Itkin Date: Sat, 7 Jul 2012 11:37:22 +0300 Subject: [PATCH] Configure usage of debugging functions and symbols in the configure script This commit drops by default the option to validate properties of the CDT during the refinement process, and *increases the speed in orders of magnitude* for complex inputs --- configure.ac | 35 ++++++++++++++++++++++++- poly2tri-c/refine/cdt.c | 8 +++--- poly2tri-c/refine/cdt.h | 14 ++++++++-- poly2tri-c/refine/delaunay-terminator.c | 6 ++--- 4 files changed, 53 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index e975dac..9232aa7 100644 --- a/configure.ac +++ b/configure.ac @@ -31,7 +31,7 @@ m4_define([lt_revision], [0]) m4_define([lt_age], [0]) # Declare the package details -AC_INIT([poly2tri-c], p2tc_real_version, [lightningismyname@gmail.com]) +AC_INIT([poly2tri-c],[p2tc_real_version],[lightningismyname@gmail.com]) P2TC_MAJOR_VERSION=p2tc_major_version P2TC_MINOR_VERSION=p2tc_minor_version @@ -103,6 +103,39 @@ CFLAGS="$CFLAGS $GLIB_CFLAGS" LDFLAGS="$LDFLAGS $GLIB_LIBS" LIBS="$LIBS $GLIB_LIBS" +# Allow building with debugging symbols +AC_MSG_CHECKING([whether to turn on debugging]) +AC_ARG_ENABLE(debug, + AS_HELP_STRING([--enable-debug],[turn on debugging (default=no)]), + if eval "test x$enable_debug = xyes"; then + DEBUGFLAG="-g" + fi) + +if test -n "$DEBUGFLAG"; then + AC_MSG_RESULT([yes]) + CFLAGS="$DEBUGFLAG $CFLAGS" +else + AC_MSG_RESULT([no]) +fi + +# Allow forcing a validation of the CDT after each refinement step +AC_MSG_CHECKING([whether to enable CDT validation during refinement]) +AC_ARG_ENABLE(cdt-validation, + AS_HELP_STRING([--enable-cdt-validation],[turn on CDT validation during refinement (WARNING: SLOW!, default=no)]), + if eval "test x$enable_cdt_validation = xyes"; then + P2TR_ENABLE_CDT_VALIDATION="TRUE" + fi) + +if test -n "$P2TR_ENABLE_CDT_VALIDATION"; then + CDTVFLAG="-DP2TR_CDT_VALIDATE=TRUE" + AC_MSG_RESULT([yes]) +else + CDTVFLAG="-DP2TR_CDT_VALIDATE=FALSE" + AC_MSG_RESULT([no]) +fi + +CFLAGS="$CDTVFLAG $CFLAGS" + # Output this configuration header file AC_CONFIG_HEADERS([config.h]) diff --git a/poly2tri-c/refine/cdt.c b/poly2tri-c/refine/cdt.c index 87fda44..34e3a38 100644 --- a/poly2tri-c/refine/cdt.c +++ b/poly2tri-c/refine/cdt.c @@ -295,7 +295,7 @@ p2tr_cdt_insert_point (P2trCDT *self, gboolean inserted = FALSE; gint i; - p2tr_cdt_validate_unused (self); + P2TR_CDT_VALIDATE_UNUSED (self); if (point_location_guess == NULL) tri = p2tr_mesh_find_point (self->mesh, pc); @@ -329,7 +329,7 @@ p2tr_cdt_insert_point (P2trCDT *self, /* We no longer need the triangle */ p2tr_triangle_unref (tri); - p2tr_cdt_validate_unused (self); + P2TR_CDT_VALIDATE_UNUSED (self); return pt; } @@ -446,7 +446,7 @@ p2tr_cdt_split_edge (P2trCDT *self, GList *fan = NULL, *new_edges = NULL; P2trHashSet *fan_edges; - p2tr_cdt_validate_unused (self); + P2TR_CDT_VALIDATE_UNUSED (self); p2tr_edge_remove (e); @@ -482,7 +482,7 @@ p2tr_cdt_split_edge (P2trCDT *self, p2tr_edge_unref (CY); } - p2tr_cdt_validate_unused (self); + P2TR_CDT_VALIDATE_UNUSED (self); return new_edges; } diff --git a/poly2tri-c/refine/cdt.h b/poly2tri-c/refine/cdt.h index 1c8b247..23455a6 100644 --- a/poly2tri-c/refine/cdt.h +++ b/poly2tri-c/refine/cdt.h @@ -43,8 +43,6 @@ typedef struct P2trPSLG *outline; } P2trCDT; -void p2tr_cdt_validate_unused (P2trCDT* self); - /** * Create a new P2trCDT from an existing P2tCDT. The resulting P2trCDT * does not depend on the original P2tCDT which can be freed @@ -72,6 +70,8 @@ gboolean p2tr_cdt_visible_from_edge (P2trCDT *self, */ void p2tr_cdt_validate_edges (P2trCDT *self); +void p2tr_cdt_validate_unused (P2trCDT* self); + /** * Make sure the constrained empty circum-circle property holds, * meaning that each triangles circum-scribing circle is either empty @@ -80,6 +80,16 @@ void p2tr_cdt_validate_edges (P2trCDT *self); */ void p2tr_cdt_validate_cdt (P2trCDT *self); +#if P2TR_CDT_VALIDATE +#define P2TR_CDT_VALIDATE_EDGES(CDT) p2tr_cdt_validate_edges(CDT) +#define P2TR_CDT_VALIDATE_UNUSED(CDT) p2tr_cdt_validate_unused(CDT) +#define P2TR_CDT_VALIDATE_CDT(CDT) p2tr_cdt_validate_cdt(CDT) +#else +#define P2TR_CDT_VALIDATE_EDGES(CDT) G_STMT_START { } G_STMT_END +#define P2TR_CDT_VALIDATE_UNUSED(CDT) G_STMT_START { } G_STMT_END +#define P2TR_CDT_VALIDATE_CDT(CDT) G_STMT_START { } G_STMT_END +#endif + /** * Insert a point into the triangulation while preserving the * constrained delaunay property diff --git a/poly2tri-c/refine/delaunay-terminator.c b/poly2tri-c/refine/delaunay-terminator.c index a60c625..5ed5fb2 100644 --- a/poly2tri-c/refine/delaunay-terminator.c +++ b/poly2tri-c/refine/delaunay-terminator.c @@ -260,7 +260,7 @@ p2tr_dt_refine (P2trDelaunayTerminator *self, P2trVTriangle *vt; gint steps = 0; - p2tr_cdt_validate_cdt(self->mesh); + P2TR_CDT_VALIDATE_CDT (self->mesh); if (steps++ >= max_steps) return; @@ -271,7 +271,7 @@ p2tr_dt_refine (P2trDelaunayTerminator *self, p2tr_dt_enqueue_segment (self, s); SplitEncroachedSubsegments (self, 0, p2tr_refiner_false_too_big); - p2tr_cdt_validate_cdt(self->mesh); + P2TR_CDT_VALIDATE_CDT (self->mesh); p2tr_hash_set_iter_init (&hs_iter, self->mesh->mesh->triangles); while (p2tr_hash_set_iter_next (&hs_iter, (gpointer*)&t)) @@ -293,7 +293,7 @@ p2tr_dt_refine (P2trDelaunayTerminator *self, P2trVEdgeSet *E; P2trPoint *cPoint; - p2tr_cdt_validate_cdt (self->mesh); + P2TR_CDT_VALIDATE_CDT (self->mesh); p2tr_triangle_get_circum_circle (t, &tCircum); c = &tCircum.center; -- 2.50.1