7 p2tr_point_new (const P2trVector2 *c)
9 return p2tr_point_new2 (c->x, c->y);
13 p2tr_point_new2 (gdouble x, gdouble y)
15 P2trPoint *self = g_slice_new (P2trPoint);
20 self->outgoing_edges = NULL;
27 p2tr_point_remove (P2trPoint *self)
29 /* We can not iterate over the list of edges while removing the edges,
30 * because the removal action will modify the list. Instead we will
31 * simply look at the first edge untill the list is emptied. */
32 while (self->outgoing_edges != NULL)
33 p2tr_edge_remove ((P2trEdge*) self->outgoing_edges->data);
35 if (self->mesh != NULL)
37 p2tr_mesh_on_point_removed (self->mesh, self);
38 p2tr_mesh_unref (self->mesh);
44 p2tr_point_free (P2trPoint *self)
46 p2tr_point_remove (self);
47 g_slice_free (P2trPoint, self);
51 p2tr_point_has_edge_to (P2trPoint *start,
56 for (iter = start->outgoing_edges; iter != NULL; iter = iter->next)
58 P2trEdge *edge = (P2trEdge*) iter->data;
67 p2tr_point_get_edge_to (P2trPoint *start,
70 P2trEdge* result = p2tr_point_has_edge_to (start, end);
72 p2tr_exception_programmatic ("Tried to get an edge that doesn't exist!");
74 return p2tr_edge_ref (result);
78 _p2tr_point_insert_edge (P2trPoint *self, P2trEdge *e)
80 GList *iter = self->outgoing_edges;
82 /* Remember: Edges are sorted in ASCENDING angle! */
83 while (iter != NULL && ((P2trEdge*)iter->data)->angle < e->angle)
86 self->outgoing_edges =
87 g_list_insert_before (self->outgoing_edges, iter, e);
93 _p2tr_point_remove_edge (P2trPoint *self, P2trEdge* e)
97 if (P2TR_EDGE_START(e) != self)
98 p2tr_exception_programmatic ("Could not remove the given outgoing "
99 "edge because doesn't start on this point!");
101 node = g_list_find (self->outgoing_edges, e);
103 p2tr_exception_programmatic ("Could not remove the given outgoing "
104 "edge because it's not present in the outgoing-edges list!");
106 self->outgoing_edges = g_list_delete_link (self->outgoing_edges, node);
112 p2tr_point_edge_ccw (P2trPoint *self,
118 if (P2TR_EDGE_START(e) != self)
119 p2tr_exception_programmatic ("Not an edge of this point!");
121 node = g_list_find (self->outgoing_edges, e);
123 p2tr_exception_programmatic ("Could not find the CCW sibling edge"
124 "because the edge is not present in the outgoing-edges list!");
126 result = (P2trEdge*) g_list_cyclic_next (self->outgoing_edges, node);
127 return p2tr_edge_ref (result);
131 p2tr_point_edge_cw (P2trPoint* self,
137 if (P2TR_EDGE_START(e) != self)
138 p2tr_exception_programmatic ("Not an edge of this point!");
140 node = g_list_find (self->outgoing_edges, e);
142 p2tr_exception_programmatic ("Could not find the CW sibling edge"
143 "because the edge is not present in the outgoing-edges list!");
145 result = (P2trEdge*) g_list_cyclic_prev (self->outgoing_edges, node);
146 return p2tr_edge_ref (result);
150 p2tr_point_is_fully_in_domain (P2trPoint *self)
153 for (iter = self->outgoing_edges; iter != NULL; iter = iter->next)
154 if (((P2trEdge*) iter->data)->tri == NULL)
161 p2tr_point_has_constrained_edge (P2trPoint *self)
164 for (iter = self->outgoing_edges; iter != NULL; iter = iter->next)
165 if (((P2trEdge*) iter->data)->constrained)
172 * Increase the reference count of the given input point
173 * @param self - The point to ref
174 * @return The point given
177 p2tr_point_ref (P2trPoint *self)
184 p2tr_point_unref (P2trPoint *self)
186 if (--self->refcount == 0)
187 p2tr_point_free (self);
191 p2tr_point_get_mesh (P2trPoint *self)
194 return p2tr_mesh_ref (self->mesh);