]> granicus.if.org Git - poly2tri-c/blob - refine/mesh.h
Make functions on point/edge/triangle/mesh return reffed objects
[poly2tri-c] / refine / mesh.h
1 #ifndef __P2TC_REFINE_MESH_H__
2 #define __P2TC_REFINE_MESH_H__
3
4 #include <glib.h>
5 #include "vector2.h"
6 #include "utils.h"
7 #include "triangulation.h"
8
9 struct P2trMesh_
10 {
11   P2trHashSet *triangles;
12   P2trHashSet *edges;
13   P2trHashSet *points;
14   
15   guint        refcount;
16   
17   gboolean     _is_clearing_now;
18 };
19
20 P2trMesh*     p2tr_mesh_new             (void);
21
22 P2trPoint*    p2tr_mesh_new_point       (P2trMesh          *mesh,
23                                          const P2trVector2 *c);
24
25 P2trPoint*    p2tr_mesh_new_point2      (P2trMesh  *mesh,
26                                          gdouble    x,
27                                          gdouble    y);
28
29 P2trEdge*     p2tr_mesh_new_edge        (P2trMesh  *mesh,
30                                          P2trPoint *start,
31                                          P2trPoint *end,
32                                          gboolean   constrained);
33
34 /**
35  * Return a new edge between the two points if an edge doesn't exist, or
36  * return an existing edge between the two points if there is such one.
37  * THE RETURNED EDGE MUST BE UNREFFED, NO MATTER IF IT'S A NEW EDGE OR
38  * AN EXISTING EDGE!
39  */
40 P2trEdge*     p2tr_mesh_new_or_existing_edge (P2trMesh  *self,
41                                               P2trPoint *start,
42                                               P2trPoint *end,
43                                               gboolean   constrained);
44
45 P2trTriangle* p2tr_mesh_new_triangle        (P2trMesh *mesh,
46                                              P2trEdge *AB,
47                                              P2trEdge *BC,
48                                              P2trEdge *CA);
49
50 void          p2tr_mesh_on_point_removed    (P2trMesh  *mesh,
51                                              P2trPoint *point);
52
53 void          p2tr_mesh_on_edge_removed     (P2trMesh *mesh,
54                                              P2trEdge *edge);
55
56 void          p2tr_mesh_on_triangle_removed (P2trMesh     *mesh,
57                                              P2trTriangle *triangle);
58
59 void          p2tr_mesh_clear           (P2trMesh *mesh);
60
61 void          p2tr_mesh_destroy         (P2trMesh *mesh);
62
63 void          p2tr_mesh_unref           (P2trMesh *mesh);
64
65 P2trMesh*     p2tr_mesh_ref             (P2trMesh *mesh);
66
67 P2trTriangle* p2tr_mesh_find_point      (P2trMesh *self,
68                                          const P2trVector2 *pt);
69
70 P2trTriangle* p2tr_mesh_find_point2     (P2trMesh          *self,
71                                          const P2trVector2 *pt,
72                                          gdouble           *u,
73                                          gdouble           *v);
74
75 /** This function assumes the mesh is composed entirely of one
76  *  continuous region. The region may have holes, but eventually every
77  *  triangle should be accessible from any other triangle by going
78  *  through a chain of neigbor triangles
79  * @param[in] self The mesh to search
80  * @param[in] pt The point to find
81  * @param[in] initial_guess An initial guess for which triangle contains
82  *            the point or is at least near it
83  * @return The triangle containing the point, or NULL if it's outside
84  *         the triangulation domain
85  */
86 P2trTriangle* p2tr_mesh_find_point_local (P2trMesh *self,
87                                           const P2trVector2 *pt,
88                                           P2trTriangle *initial_guess);
89
90 /** Same as @ref p2tr_mesh_find_point_local but also returns the u and v
91  * coordinates of the given point inside the triangle
92  * @param[in] self The mesh to search
93  * @param[in] pt The point to find
94  * @param[in] initial_guess An initial guess for which triangle contains
95  *            the point or is at least near it
96  * @param[out] u The u coordinate of the point inside the returned triangle
97  * @param[out] v The v coordinate of the point inside the returned triangle
98  * @return The triangle containing the point, or NULL if it's outside
99  *         the triangulation domain
100  */
101 P2trTriangle* p2tr_mesh_find_point_local2 (P2trMesh *self,
102                                            const P2trVector2 *pt,
103                                            P2trTriangle *initial_guess,
104                                            gdouble *u,
105                                            gdouble *v);
106
107 #endif