/** * Triangulate a polygon by creating edges to a center point. * 1. If there is a NULL point in the polygon, two triangles are not * created (these are the two that would have used it) * 2. THE RETURNED TRIANGLES MUST BE UNREFFED! */ static GList* p2tr_cdt_triangulate_fan (P2trCDT *self, P2trPoint *center, GList *edge_pts) { GList *new_tris = NULL; GList *iter; /* We can not triangulate unless at least two points are given */ if (edge_pts == NULL || edge_pts->next == NULL) { p2tr_exception_programmatic ("Not enough points to triangulate as" " a star!"); } for (iter = edge_pts; iter != NULL; iter = iter->next) { P2trPoint *A = (P2trPoint*) iter->data; P2trPoint *B = (P2trPoint*) g_list_cyclic_next (edge_pts, iter)->data; P2trEdge *AB, *BC, *CA; P2trTriangle *tri; if (A == NULL || B == NULL) continue; AB = p2tr_point_get_edge_to (A, B); BC = p2tr_mesh_new_or_existing_edge (self->mesh, B, center, FALSE); CA = p2tr_mesh_new_or_existing_edge (self->mesh, center, A, FALSE); tri = p2tr_mesh_new_triangle (self->mesh, AB, BC, CA); new_tris = g_list_prepend (new_tris, tri); p2tr_edge_unref (BC); p2tr_edge_unref (CA); } return new_tris; }
/** * Triangulate a polygon by creating edges to a center point. * 1. If there is a NULL point in the polygon, two triangles are not * created (these are the two that would have used it) * 2. THE RETURNED EDGES MUST BE UNREFFED! */ static P2trVEdgeSet* p2tr_cdt_triangulate_fan (P2trCDT *self, P2trPoint *center, GList *edge_pts) { P2trVEdgeSet* fan_edges = p2tr_vedge_set_new (); GList *iter; /* We can not triangulate unless at least two points are given */ if (edge_pts == NULL || edge_pts->next == NULL) { p2tr_exception_programmatic ("Not enough points to triangulate as" " a star!"); } for (iter = edge_pts; iter != NULL; iter = iter->next) { P2trPoint *A = (P2trPoint*) iter->data; P2trPoint *B = (P2trPoint*) g_list_cyclic_next (edge_pts, iter)->data; P2trEdge *AB, *BC, *CA; if (A == NULL || B == NULL) continue; AB = p2tr_point_get_edge_to (A, B, TRUE); BC = p2tr_mesh_new_or_existing_edge (self->mesh, B, center, FALSE); CA = p2tr_mesh_new_or_existing_edge (self->mesh, center, A, FALSE); p2tr_triangle_unref (p2tr_mesh_new_triangle (self->mesh, AB, BC, CA)); p2tr_vedge_set_add (fan_edges, CA); p2tr_vedge_set_add (fan_edges, BC); p2tr_vedge_set_add (fan_edges, AB); } return fan_edges; }