]> granicus.if.org Git - poly2tri-c/commitdiff
1. Points were accidentally given in CW order (instead of CCW) order to the in_circle...
authorBarak Itkin <lightningismyname@gmail.com>
Sat, 16 Jun 2012 15:24:08 +0000 (18:24 +0300)
committerBarak Itkin <lightningismyname@gmail.com>
Sat, 16 Jun 2012 15:24:08 +0000 (18:24 +0300)
2. Fix the implementation of Lawson's legalization

poly2tri-c/refine/cdt.c
poly2tri-c/refine/delaunay-terminator.c
poly2tri-c/refine/rmath.c
poly2tri-c/refine/triangle.c

index ebe3093d332fc3a81d64c944f3eb1826aec09a1a..b53c3b14465c258c668049db7119b368ebc3f09c 100644 (file)
@@ -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);
             }
         }
 
index 000e1d983a6727da61051390b4df7e3de5462551..2b87cb0a7dd5f555a0cc22db4c1840cf614907c0 100644 (file)
@@ -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 */
index e0491c24e1ba66cdaf4bfe87577968637159e926..f644eaf61a78a9ba13b79151d75caf02c006dae1 100644 (file)
@@ -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,
index 5e9d5221e213baa1ec89a88d5ad3baad526ef7bc..2bf9a7f48295c0d331d41940feb929d14f729826 100644 (file)
@@ -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);
 }