Esempio n. 1
0
/**
 * THE GIVEN INPUT TRIANGLES MUST BE GIVEN WITH AN EXTRA REFERENCE SINCE
 * THEY WILL BE UNREFFED!
 */
static void
p2tr_cdt_flip_fix (P2trCDT *self,
                   GList   *initial_triangles)
{
    GQueue flipped_edges, tris_to_fix;
    GList *iter;

    g_queue_init (&flipped_edges);
    g_queue_init (&tris_to_fix);

    for (iter = initial_triangles; iter != NULL; iter = iter->next)
        g_queue_push_tail (&tris_to_fix, iter->data);

    while (! g_queue_is_empty (&tris_to_fix))
    {
        P2trTriangle *tri = (P2trTriangle*)g_queue_pop_head (&tris_to_fix);
        P2trCircle   circum_circle;
        gint         i;

        if (p2tr_triangle_is_removed (tri))
        {
            p2tr_triangle_unref (tri);
            continue;
        }

        p2tr_triangle_get_circum_circle (tri, &circum_circle);

        for (i = 0; i < 3; i++)
        {
            P2trEdge  *e = tri->edges[i];
            P2trPoint *opposite;

            if (e->constrained || e->delaunay)
                continue;

            opposite = p2tr_triangle_get_opposite_point (e->mirror->tri, e->mirror);
            if (! p2tr_circle_test_point_outside(&circum_circle, &opposite->c))
            {
                P2trEdge *flipped;
                if (p2tr_cdt_try_flip (self, e, &tris_to_fix, &flipped))
                {
                    g_queue_push_tail (&flipped_edges, flipped);
                    /* Stop iterating this triangle since it doesn't exist
                     * any more */
                    break;
                }
            }
        }

        /* We are finished with the triangle, so unref it as promised */
        p2tr_triangle_unref (tri);
    }

    while (! g_queue_is_empty (&flipped_edges))
    {
        P2trEdge *e = (P2trEdge*) g_queue_pop_head (&flipped_edges);
        e->delaunay = e->mirror->delaunay = FALSE;
        p2tr_edge_unref (e);
    }
}
Esempio n. 2
0
void
p2tr_cdt_validate_unused (P2trCDT* self)
{
  P2trEdge *ed;
  P2trTriangle *tri;
  P2trHashSetIter iter;

  p2tr_hash_set_iter_init (&iter, self->mesh->edges);
  while (p2tr_hash_set_iter_next (&iter, (gpointer*)&ed))
    {
      g_assert (ed->mirror != NULL);
      g_assert (! p2tr_edge_is_removed (ed));
    }

  p2tr_hash_set_iter_init (&iter, self->mesh->triangles);
  while (p2tr_hash_set_iter_next (&iter, (gpointer*)&tri))
    g_assert (! p2tr_triangle_is_removed (tri));
}