/[zanavi_public1]/navit/navit/maptool/p2t/common/shapes.h
ZANavi

Contents of /navit/navit/maptool/p2t/common/shapes.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 57 - (show annotations) (download)
Sun Mar 19 16:46:08 2017 UTC (7 years, 1 month ago) by zoff99
File MIME type: text/plain
File size: 9989 byte(s)
updates
1 /*
2 * This file is a part of the C port of the Poly2Tri library
3 * Porting to C done by (c) Barak Itkin <lightningismyname@gmail.com>
4 * http://code.google.com/p/poly2tri-c/
5 *
6 * Poly2Tri Copyright (c) 2009-2010, Poly2Tri Contributors
7 * http://code.google.com/p/poly2tri/
8 *
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 *
14 * * Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * * Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * * Neither the name of Poly2Tri nor the names of its contributors may be
20 * used to endorse or promote products derived from this software without specific
21 * prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36 #ifndef __P2TC_P2T_SHAPES_H__
37 #define __P2TC_P2T_SHAPES_H__
38
39 #include <stddef.h>
40 #include <stdio.h>
41 #include <assert.h>
42 #include <math.h>
43 #include "poly2tri-private.h"
44 #include "cutils.h"
45
46
47
48 // --------EXCEPTIONS-------
49
50 #include <setjmp.h>
51
52 // defined in maptool.h !!
53 extern jmp_buf ex_buf__;
54 extern void (*func_global)(int);
55 long long stack_pt;
56 void fprintf_(FILE *f, const char *fmt, ...);
57
58 #define STACKPTMAX 12000
59
60 #define THROW(x) longjmp(ex_buf__, x)
61 #define MAPTOOL_00001_EXCEPTION (1)
62
63 // --------EXCEPTIONS-------
64
65
66
67
68 /**
69 * P2tPoint:
70 * @x: The x coordinate of the point
71 * @y: The y coordinate of the point
72 * @edge_list: The edges this point constitutes an upper ending point
73 *
74 * A struct to represent 2D points with double precision, and to keep track
75 * of the edges this point constitutes an upper ending point
76 */
77 struct _P2tPoint
78 {
79 /*< public >*/
80 P2tEdgePtrArray edge_list;
81 double x, y;
82 };
83
84 /**
85 * p2t_point_init_dd:
86 * @THIS: The #P2tPoint to initialize
87 * @x: The desired x coordinate of the point
88 * @y: The desired y coordinate of the point
89 *
90 * A function to initialize a #P2tPoint struct with the given coordinates. The
91 * struct must later be finalized by a call to #p2t_point_destroy
92 */
93 void p2t_point_init_dd (P2tPoint* THIS, double x, double y);
94
95 /**
96 * p2t_point_new_dd:
97 * @x: The desired x coordinate of the point
98 * @y: The desired y coordinate of the point
99 *
100 * A utility function to alloacte and initialize a #P2tPoint.
101 * See #p2t_point_init_dd. Note that when finished using the point, it must be
102 * freed by a call to #p2t_point_free and can not be freed like regular memory.
103 *
104 * Returns: The allocated and initialized point
105 */
106 P2tPoint* p2t_point_new_dd (double x, double y);
107
108 /**
109 * p2t_point_init:
110 * @THIS: The #P2tPoint to initialize
111 *
112 * A function to initialize a #P2tPoint struct to (0,0). The struct must later
113 * be finalized by a call to #p2t_point_destroy
114 */
115 void p2t_point_init (P2tPoint* THIS);
116
117 /**
118 * p2t_point_new:
119 *
120 * A utility function to alloacte and initialize a #P2tPoint.
121 * See #p2t_point_init. Note that when finished using the point, it must be
122 * freed by a call to #p2t_point_free and can not be freed like regular memory.
123 */
124 P2tPoint* p2t_point_new ();
125
126 /**
127 * p2t_point_destroy:
128 * @THIS: The #P2tPoint whose resources should be freed
129 *
130 * This function will free all the resources allocated by a #P2tPoint, without
131 * freeing the #P2tPoint pointed by @THIS
132 */
133 void p2t_point_destroy (P2tPoint* THIS);
134
135 /**
136 * p2t_point_free:
137 * @THIS: The #P2tPoint to free
138 *
139 * This function will free all the resources allocated by a #P2tPoint, and will
140 * also free the #P2tPoint pointed by @THIS
141 */
142 void p2t_point_free (P2tPoint* THIS);
143
144 /**
145 * P2tEdge:
146 * @p: The top right point of the edge
147 * @q: The bottom left point of the edge
148 *
149 * Represents a simple polygon's edge
150 */
151 struct _P2tEdge
152 {
153 P2tPoint *p, *q;
154 };
155
156 /**
157 * p2t_edge_init:
158 * @THIS: The #P2tEdge to initialize
159 * @p1: One of the two points that form the edge
160 * @p2: The other point of the two points that form the edge
161 *
162 * A function to initialize a #P2tEdge struct from the given points. The
163 * struct must later be finalized by a call to #p2t_point_destroy.
164 *
165 * Warning: The points must be geometrically not-equal! This means that they
166 * must differ by at least one of their coordinates. Otherwise, a runtime error
167 * would be raised!
168 */
169 void p2t_edge_init (P2tEdge* THIS, P2tPoint* p1, P2tPoint* p2);
170
171 /**
172 * p2t_edge_new:
173 *
174 * A utility function to alloacte and initialize a #P2tEdge.
175 * See #p2t_edge_init. Note that when finished using the point, it must be freed
176 * by a call to #p2t_point_free and can not be freed like regular memory.
177 *
178 * Returns: The allocated and initialized edge
179 */
180 P2tEdge* p2t_edge_new (P2tPoint* p1, P2tPoint* p2);
181
182 /**
183 * p2t_edge_destroy:
184 * @THIS: The #P2tEdge whose resources should be freed
185 *
186 * This function will free all the resources allocated by a #P2tEdge, without
187 * freeing the #P2tPoint pointed by @THIS
188 */
189 void p2t_edge_destroy (P2tEdge* THIS);
190
191 /**
192 * p2t_edge_free:
193 * @THIS: The #P2tEdge to free
194 *
195 * This function will free all the resources allocated by a #P2tEdge, and will
196 * also free the #P2tEdge pointed by @THIS
197 */
198 void p2t_edge_free (P2tEdge* THIS);
199
200
201 /* Triangle-based data structures are know to have better performance than quad-edge structures
202 * See: J. Shewchuk, "Triangle: Engineering a 2D Quality Mesh Generator and Delaunay Triangulator"
203 * "Triangulations in CGAL"
204 */
205
206 /**
207 * P2tTriangle:
208 * @constrained_edge: Flags to determine if an edge is a Constrained edge
209 * @delaunay_edg: Flags to determine if an edge is a Delauney edge
210 * @points_: Triangle points
211 * @neighbors_: Neighbor list
212 * @interior_: Has this triangle been marked as an interior triangle?
213 *
214 * A data structure for representing a triangle, while keeping information about
215 * neighbor triangles, etc.
216 */
217 struct _P2tTriangle
218 {
219 /*< public >*/
220 gboolean constrained_edge[3];
221 gboolean delaunay_edge[3];
222
223 /*< private >*/
224 P2tPoint * points_[3];
225 struct _P2tTriangle * neighbors_[3];
226 gboolean interior_;
227 };
228
229 P2tTriangle* p2t_triangle_new (P2tPoint* a, P2tPoint* b, P2tPoint* c);
230 void p2t_triangle_init (P2tTriangle* THIS, P2tPoint* a, P2tPoint* b, P2tPoint* c);
231 P2tPoint* p2t_triangle_get_point (P2tTriangle* THIS, const int index);
232 P2tPoint* p2t_triangle_point_cw (P2tTriangle* THIS, P2tPoint* point);
233 P2tPoint* p2t_triangle_point_ccw (P2tTriangle* THIS, P2tPoint* point);
234 P2tPoint* p2t_triangle_opposite_point (P2tTriangle* THIS, P2tTriangle* t, P2tPoint* p);
235
236 P2tTriangle* p2t_triangle_get_neighbor (P2tTriangle* THIS, const int index);
237 void p2t_triangle_mark_neighbor_pt_pt_tr (P2tTriangle* THIS, P2tPoint* p1, P2tPoint* p2, P2tTriangle* t);
238 void p2t_triangle_mark_neighbor_tr (P2tTriangle* THIS, P2tTriangle *t);
239
240 void p2t_triangle_mark_constrained_edge_i (P2tTriangle* THIS, const int index);
241 void p2t_triangle_mark_constrained_edge_ed (P2tTriangle* THIS, P2tEdge* edge);
242 void p2t_triangle_mark_constrained_edge_pt_pt (P2tTriangle* THIS, P2tPoint* p, P2tPoint* q);
243
244 int p2t_triangle_index (P2tTriangle* THIS, const P2tPoint* p);
245 int p2t_triangle_edge_index (P2tTriangle* THIS, const P2tPoint* p1, const P2tPoint* p2);
246
247 P2tTriangle* p2t_triangle_neighbor_cw (P2tTriangle* THIS, P2tPoint* point);
248 P2tTriangle* p2t_triangle_neighbor_ccw (P2tTriangle* THIS, P2tPoint* point);
249 gboolean p2t_triangle_get_constrained_edge_ccw (P2tTriangle* THIS, P2tPoint* p);
250 gboolean p2t_triangle_get_constrained_edge_cw (P2tTriangle* THIS, P2tPoint* p);
251 void p2t_triangle_set_constrained_edge_ccw (P2tTriangle* THIS, P2tPoint* p, gboolean ce);
252 void p2t_triangle_set_constrained_edge_cw (P2tTriangle* THIS, P2tPoint* p, gboolean ce);
253 gboolean p2t_triangle_get_delunay_edge_ccw (P2tTriangle* THIS, P2tPoint* p);
254 gboolean p2t_triangle_get_delunay_edge_cw (P2tTriangle* THIS, P2tPoint* p);
255 void p2t_triangle_set_delunay_edge_ccw (P2tTriangle* THIS, P2tPoint* p, gboolean e);
256 void p2t_triangle_set_delunay_edge_cw (P2tTriangle* THIS, P2tPoint* p, gboolean e);
257
258 gboolean p2t_triangle_contains_pt (P2tTriangle* THIS, P2tPoint* p);
259 gboolean p2t_triangle_contains_ed (P2tTriangle* THIS, const P2tEdge* e);
260 gboolean p2t_triangle_contains_pt_pt (P2tTriangle* THIS, P2tPoint* p, P2tPoint* q);
261 void p2t_triangle_legalize_pt (P2tTriangle* THIS, P2tPoint* point);
262 void p2t_triangle_legalize_pt_pt (P2tTriangle* THIS, P2tPoint* opoint, P2tPoint* npoint);
263 /**
264 * Clears all references to all other triangles and points
265 */
266 void p2t_triangle_clear (P2tTriangle* THIS);
267 void p2t_triangle_clear_neighbor_tr (P2tTriangle* THIS, P2tTriangle *triangle);
268 void p2t_triangle_clear_neighbors (P2tTriangle* THIS);
269 void p2t_triangle_clear_delunay_edges (P2tTriangle* THIS);
270
271 gboolean p2t_triangle_is_interior (P2tTriangle* THIS);
272 void p2t_triangle_is_interior_b (P2tTriangle* THIS, gboolean b);
273
274 P2tTriangle* p2t_triangle_neighbor_across (P2tTriangle* THIS, P2tPoint* opoint);
275
276 void p2t_triangle_debug_print (P2tTriangle* THIS);
277
278 gint p2t_point_cmp (gconstpointer a, gconstpointer b);
279
280 /* gboolean operator == (const Point& a, const Point& b); */
281 gboolean p2t_point_equals (const P2tPoint* a, const P2tPoint* b);
282
283 #endif
284
285

   
Visit the ZANavi Wiki