From: Barak Itkin Date: Sat, 16 Jun 2012 15:24:08 +0000 (+0300) Subject: 1. Points were accidentally given in CW order (instead of CCW) order to the in_circle... X-Git-Tag: p2tc-0.1.0~35 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d738df3f7ea6960d21f3abb71c9e68774d6ddf6d;p=poly2tri-c 1. Points were accidentally given in CW order (instead of CCW) order to the in_circle function. This caused lots of trouble! 2. Fix the implementation of Lawson's legalization --- diff --git a/poly2tri-c/refine/cdt.c b/poly2tri-c/refine/cdt.c index ebe3093..b53c3b1 100644 --- a/poly2tri-c/refine/cdt.c +++ b/poly2tri-c/refine/cdt.c @@ -555,8 +555,7 @@ p2tr_cdt_try_flip (P2trCDT *self, /* Check if the quadriliteral ADBC is concave (because if it is, we * can't flip the edge) */ - if (p2tr_edge_angle_between_positive (DB, BC) >= G_PI - CDT_180_EPS || - p2tr_edge_angle_between_positive (CA, AD) >= G_PI - CDT_180_EPS) + if (p2tr_triangle_circumcircle_contains_point (AB->tri, &D->c) != P2TR_INCIRCLE_IN) return NULL; p2tr_edge_remove (AB); @@ -604,18 +603,15 @@ p2tr_cdt_flip_fix (P2trCDT *self, P2trPoint *A = P2TR_EDGE_START(edge), *B = edge->end; P2trPoint *C1 = p2tr_triangle_get_opposite_point (edge->tri, edge, FALSE); P2trPoint *C2 = p2tr_triangle_get_opposite_point (edge->mirror->tri, edge->mirror, FALSE); - if (p2tr_triangle_circumcircle_contains_point (edge->tri, &C2->c) == P2TR_INCIRCLE_IN - || p2tr_triangle_circumcircle_contains_point (edge->mirror->tri, &C1->c) == P2TR_INCIRCLE_IN) + + P2trEdge *flipped = p2tr_cdt_try_flip (self, edge); + if (flipped != NULL) { - P2trEdge *flipped = p2tr_cdt_try_flip (self, edge); - if (flipped != NULL) - { - p2tr_cdt_add_edge (candidates, p2tr_point_get_edge_to (A, C1, TRUE)); - p2tr_cdt_add_edge (candidates, p2tr_point_get_edge_to (A, C2, TRUE)); - p2tr_cdt_add_edge (candidates, p2tr_point_get_edge_to (B, C1, TRUE)); - p2tr_cdt_add_edge (candidates, p2tr_point_get_edge_to (B, C2, TRUE)); - p2tr_edge_unref (flipped); - } + p2tr_cdt_add_edge (candidates, p2tr_point_get_edge_to (A, C1, TRUE)); + p2tr_cdt_add_edge (candidates, p2tr_point_get_edge_to (A, C2, TRUE)); + p2tr_cdt_add_edge (candidates, p2tr_point_get_edge_to (B, C1, TRUE)); + p2tr_cdt_add_edge (candidates, p2tr_point_get_edge_to (B, C2, TRUE)); + p2tr_edge_unref (flipped); } } diff --git a/poly2tri-c/refine/delaunay-terminator.c b/poly2tri-c/refine/delaunay-terminator.c index 000e1d9..2b87cb0 100644 --- a/poly2tri-c/refine/delaunay-terminator.c +++ b/poly2tri-c/refine/delaunay-terminator.c @@ -294,7 +294,10 @@ p2tr_dt_refine (P2trDelaunayTerminator *self, /* If no edge is encroached, then this must be * inside the triangulation domain!!! */ if (triContaining_c == NULL) - p2tr_exception_geometric ("Should not happen! (%f, %f) is outside the domain!", c->x, c->y); + p2tr_exception_geometric ("Should not happen! (%f, %f) (Center of (%f,%f)->(%f,%f)->(%f,%f)) is outside the domain!", c->x, c->y, + t->edges[2]->end->c.x, t->edges[2]->end->c.y, + t->edges[0]->end->c.x, t->edges[0]->end->c.y, + t->edges[1]->end->c.x, t->edges[1]->end->c.y); /* Now, check if this point would encroach any edge * of the triangulation */ diff --git a/poly2tri-c/refine/rmath.c b/poly2tri-c/refine/rmath.c index e0491c2..f644eaf 100644 --- a/poly2tri-c/refine/rmath.c +++ b/poly2tri-c/refine/rmath.c @@ -226,6 +226,7 @@ P2trOrientation p2tr_math_orient2d (const P2trVector2 *A, #define INCIRCLE_EPSILON 1e-9 +/* Points must be given in CCW order!!!!! */ P2trInCircle p2tr_math_incircle (const P2trVector2 *A, const P2trVector2 *B, diff --git a/poly2tri-c/refine/triangle.c b/poly2tri-c/refine/triangle.c index 5e9d522..2bf9a7f 100644 --- a/poly2tri-c/refine/triangle.c +++ b/poly2tri-c/refine/triangle.c @@ -278,10 +278,11 @@ P2trInCircle p2tr_triangle_circumcircle_contains_point (P2trTriangle *self, const P2trVector2 *pt) { + /* Points must be given in CCW order! */ return p2tr_math_incircle ( - &P2TR_TRIANGLE_GET_POINT(self,0)->c, - &P2TR_TRIANGLE_GET_POINT(self,1)->c, &P2TR_TRIANGLE_GET_POINT(self,2)->c, + &P2TR_TRIANGLE_GET_POINT(self,1)->c, + &P2TR_TRIANGLE_GET_POINT(self,0)->c, pt); }