From: Barak Itkin Date: Sat, 12 May 2012 19:26:55 +0000 (+0300) Subject: Fix the cocentric shell split point algorithm to be more accurate and make the refine... X-Git-Tag: p2tc-0.1.0~77 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b9169fb4993b7a735dda8e7ce08720c88a19d056;p=poly2tri-c Fix the cocentric shell split point algorithm to be more accurate and make the refine library compile under ANSI C --- diff --git a/refine/Makefile.am b/refine/Makefile.am index a087eb8..1fc044e 100644 --- a/refine/Makefile.am +++ b/refine/Makefile.am @@ -1,3 +1,3 @@ lib_LTLIBRARIES = libp2tc-refine.la -libp2tc_refine_la_SOURCES = bounded-line.c bounded-line.h cdt.c cdt.h circle.c circle.h cluster.c cluster.h delaunay-terminator.c delaunay-terminator.h edge.c edge.h line.c line.h math.c math.h mesh.c mesh.h point.c point.h pslg.c pslg.h refine.h triangle.c triangle.h triangulation.h utils.c utils.h vector2.c vector2.h visibility.c visibility.h +libp2tc_refine_la_SOURCES = bounded-line.c bounded-line.h cdt.c cdt.h circle.c circle.h cluster.c cluster.h delaunay-terminator.c delaunay-terminator.h edge.c edge.h line.c line.h rmath.c rmath.h mesh.c mesh.h point.c point.h pslg.c pslg.h refine.h triangle.c triangle.h triangulation.h utils.c utils.h vector2.c vector2.h visibility.c visibility.h diff --git a/refine/cdt.c b/refine/cdt.c index feec2fd..71ca076 100644 --- a/refine/cdt.c +++ b/refine/cdt.c @@ -474,7 +474,7 @@ p2tr_cdt_flip_fix (P2trCDT *self, opposite = p2tr_triangle_get_opposite_point (e->mirror->tri, e->mirror); if (! p2tr_circle_test_point_outside(&circum_circle, &opposite->c)) { - P2trEdge *flipped; + P2trEdge *flipped = NULL; if (p2tr_cdt_try_flip (self, e, &tris_to_fix, &flipped)) { g_queue_push_tail (&flipped_edges, flipped); diff --git a/refine/delaunay-terminator.c b/refine/delaunay-terminator.c index a455ea4..e7a9df2 100644 --- a/refine/delaunay-terminator.c +++ b/refine/delaunay-terminator.c @@ -3,7 +3,7 @@ #include #include "utils.h" -#include "math.h" +#include "rmath.h" #include "point.h" #include "edge.h" @@ -407,7 +407,11 @@ static void ChooseSplitVertex(P2trEdge *e, P2trVector2 *dst) { gdouble sourceLength = p2tr_edge_get_length(e); - gdouble newLength = pow(2, round(LOG2(sourceLength))); + gdouble newLengthFloor = pow(2, floor(LOG2(sourceLength))); + gdouble newLengthCeil = newLengthFloor * 2; + gdouble newLength = + (sourceLength - newLengthFloor < newLengthCeil - sourceLength) + ? newLengthFloor : newLengthCeil; gdouble ratio, resultLength; /* IMPORTANT! DIVIDE BY 2! */ diff --git a/refine/refine.h b/refine/refine.h index 038ef0d..9759ce8 100644 --- a/refine/refine.h +++ b/refine/refine.h @@ -2,7 +2,7 @@ #define __P2TC_REFINE_H__ #include "utils.h" -#include "math.h" +#include "rmath.h" #include "vector2.h" #include "circle.h" @@ -19,4 +19,4 @@ #include "cdt.h" #include "delaunay-terminator.h" -#endif \ No newline at end of file +#endif diff --git a/refine/math.c b/refine/rmath.c similarity index 96% rename from refine/math.c rename to refine/rmath.c index fc6a156..0edf6d6 100644 --- a/refine/math.c +++ b/refine/rmath.c @@ -1,6 +1,6 @@ #include #include -#include "math.h" +#include "rmath.h" gdouble p2tr_math_length_sq (gdouble x1, gdouble y1, diff --git a/refine/math.h b/refine/rmath.h similarity index 100% rename from refine/math.h rename to refine/rmath.h diff --git a/refine/triangle.c b/refine/triangle.c index 599b969..ae231b5 100644 --- a/refine/triangle.c +++ b/refine/triangle.c @@ -2,7 +2,7 @@ #include #include "utils.h" -#include "math.h" +#include "rmath.h" #include "point.h" #include "edge.h" @@ -249,4 +249,4 @@ p2tr_triangle_contains_point2 (P2trTriangle *self, &P2TR_TRIANGLE_GET_POINT(self,1)->c, &P2TR_TRIANGLE_GET_POINT(self,2)->c, pt, u, v); -} \ No newline at end of file +} diff --git a/refine/triangle.h b/refine/triangle.h index dfd54ca..048c1ae 100644 --- a/refine/triangle.h +++ b/refine/triangle.h @@ -2,7 +2,7 @@ #define __P2TC_REFINE_TRIANGLE_H__ #include -#include "math.h" +#include "rmath.h" #include "triangulation.h" /** @@ -58,4 +58,4 @@ P2trInTriangle p2tr_triangle_contains_point2 (P2trTriangle *self, gdouble *v); #define P2TR_TRIANGLE_GET_POINT(tr,index) ((tr)->edges[((index)+3-1)%3]->end) -#endif \ No newline at end of file +#endif