P2trPoint* p2tr_cdt_insert_point (P2trCDT *self, const P2trVector2 *pc, P2trTriangle *point_location_guess) { P2trTriangle *tri; P2trPoint *pt; gboolean inserted = FALSE; gint i; P2TR_CDT_VALIDATE_UNUSED (self); if (point_location_guess == NULL) tri = p2tr_mesh_find_point (self->mesh, pc); else tri = p2tr_mesh_find_point_local (self->mesh, pc, point_location_guess); if (tri == NULL) p2tr_exception_geometric ("Tried to add point outside of domain!"); pt = p2tr_mesh_new_point (self->mesh, pc); /* If the point falls on a line, we should split the line */ for (i = 0; i < 3; i++) { P2trEdge *edge = tri->edges[i]; if (p2tr_math_orient2d (& P2TR_EDGE_START(edge)->c, &edge->end->c, pc) == P2TR_ORIENTATION_LINEAR) { GList *parts = p2tr_cdt_split_edge (self, edge, pt), *eIter; for (eIter = parts; eIter != NULL; eIter = eIter->next) p2tr_edge_unref ((P2trEdge*)eIter->data); g_list_free(parts); inserted = TRUE; break; } } if (! inserted) /* If we reached this line, then the point is inside the triangle */ p2tr_cdt_insert_point_into_triangle (self, pt, tri); /* We no longer need the triangle */ p2tr_triangle_unref (tri); P2TR_CDT_VALIDATE_UNUSED (self); return pt; }
P2trPoint* p2tr_cdt_insert_point (P2trCDT *self, const P2trVector2 *pc, P2trTriangle *point_location_guess) { P2trTriangle *tri; P2trPoint *pt; gboolean inserted = FALSE; gint i; if (point_location_guess == NULL) tri = p2tr_mesh_find_point (self->mesh, pc); else tri = p2tr_mesh_find_point_local (self->mesh, pc, point_location_guess); if (tri == NULL) p2tr_exception_geometric ("Tried to add point outside of domain!"); pt = p2tr_mesh_new_point (self->mesh, pc); /* If the point falls on a line, we should split the line */ for (i = 0; i < 3; i++) { P2trEdge *edge = tri->edges[i]; if (p2tr_math_orient2d (& P2TR_EDGE_START(edge)->c, &edge->end->c, pc) == P2TR_ORIENTATION_LINEAR) { p2tr_cdt_split_edge (self, edge, pt); inserted = TRUE; break; } } if (! inserted) /* If we reached this line, then the point is inside the triangle */ p2tr_cdt_insert_point_into_triangle (self, pt, tri); p2tr_cdt_on_new_point (self, pt); return pt; }