]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | triangle.c | 116 ++++++++++++++++++++++++++----------------------------------- |
2 | triangle.h | 29 +++++++++------- | |
3 | 2 files changed, 66 insertions(+), 79 deletions(-) | |
4 | ||
5 | diff --git a/triangle.c b/triangle.c | |
6 | index f7a5700..084902e 100644 | |
7 | --- a/triangle.c | |
8 | +++ b/triangle.c | |
9 | @@ -194,27 +194,8 @@ | |
10 | /* */ | |
11 | /*****************************************************************************/ | |
12 | ||
13 | -/* For single precision (which will save some memory and reduce paging), */ | |
14 | -/* define the symbol SINGLE by using the -DSINGLE compiler switch or by */ | |
15 | -/* writing "#define SINGLE" below. */ | |
16 | -/* */ | |
17 | -/* For double precision (which will allow you to refine meshes to a smaller */ | |
18 | -/* edge length), leave SINGLE undefined. */ | |
19 | -/* */ | |
20 | -/* Double precision uses more memory, but improves the resolution of the */ | |
21 | -/* meshes you can generate with Triangle. It also reduces the likelihood */ | |
22 | -/* of a floating exception due to overflow. Finally, it is much faster */ | |
23 | -/* than single precision on 64-bit architectures like the DEC Alpha. I */ | |
24 | -/* recommend double precision unless you want to generate a mesh for which */ | |
25 | -/* you do not have enough memory. */ | |
26 | - | |
27 | -/* #define SINGLE */ | |
28 | - | |
29 | -#ifdef SINGLE | |
30 | -#define REAL float | |
31 | -#else /* not SINGLE */ | |
32 | #define REAL double | |
33 | -#endif /* not SINGLE */ | |
34 | +#define VOID void | |
35 | ||
36 | /* If yours is not a Unix system, define the NO_TIMER compiler switch to */ | |
37 | /* remove the Unix-specific timing code. */ | |
38 | @@ -308,12 +289,6 @@ | |
39 | #define DEADVERTEX -32768 | |
40 | #define UNDEADVERTEX -32767 | |
41 | ||
42 | -/* The next line is used to outsmart some very stupid compilers. If your */ | |
43 | -/* compiler is smarter, feel free to replace the "int" with "void". */ | |
44 | -/* Not that it matters. */ | |
45 | - | |
46 | -#define VOID int | |
47 | - | |
48 | /* Two constants for algorithms based on random sampling. Both constants */ | |
49 | /* have been chosen empirically to optimize their respective algorithms. */ | |
50 | ||
51 | @@ -340,6 +315,7 @@ | |
52 | ||
53 | #define ONETHIRD 0.333333333333333333333333333333333333333333333333333333333333 | |
54 | ||
55 | +#include <stdint.h> | |
56 | #include <stdio.h> | |
57 | #include <stdlib.h> | |
58 | #include <string.h> | |
59 | @@ -938,16 +914,16 @@ int minus1mod3[3] = {2, 0, 1}; | |
60 | /* extracted from the two least significant bits of the pointer. */ | |
61 | ||
62 | #define decode(ptr, otri) \ | |
63 | - (otri).orient = (int) ((unsigned long) (ptr) & (unsigned long) 3l); \ | |
64 | + (otri).orient = (int) ((uintptr_t) (ptr) & (uintptr_t) 3l); \ | |
65 | (otri).tri = (triangle *) \ | |
66 | - ((unsigned long) (ptr) ^ (unsigned long) (otri).orient) | |
67 | + ((uintptr_t) (ptr) ^ (uintptr_t) (otri).orient) | |
68 | ||
69 | /* encode() compresses an oriented triangle into a single pointer. It */ | |
70 | /* relies on the assumption that all triangles are aligned to four-byte */ | |
71 | /* boundaries, so the two least significant bits of (otri).tri are zero. */ | |
72 | ||
73 | #define encode(otri) \ | |
74 | - (triangle) ((unsigned long) (otri).tri | (unsigned long) (otri).orient) | |
75 | + (triangle) ((uintptr_t) (otri).tri | (uintptr_t) (otri).orient) | |
76 | ||
77 | /* The following handle manipulation primitives are all described by Guibas */ | |
78 | /* and Stolfi. However, Guibas and Stolfi use an edge-based data */ | |
79 | @@ -1111,16 +1087,16 @@ int minus1mod3[3] = {2, 0, 1}; | |
80 | ||
81 | #define infect(otri) \ | |
82 | (otri).tri[6] = (triangle) \ | |
83 | - ((unsigned long) (otri).tri[6] | (unsigned long) 2l) | |
84 | + ((uintptr_t) (otri).tri[6] | (uintptr_t) 2l) | |
85 | ||
86 | #define uninfect(otri) \ | |
87 | (otri).tri[6] = (triangle) \ | |
88 | - ((unsigned long) (otri).tri[6] & ~ (unsigned long) 2l) | |
89 | + ((uintptr_t) (otri).tri[6] & ~ (uintptr_t) 2l) | |
90 | ||
91 | /* Test a triangle for viral infection. */ | |
92 | ||
93 | #define infected(otri) \ | |
94 | - (((unsigned long) (otri).tri[6] & (unsigned long) 2l) != 0l) | |
95 | + (((uintptr_t) (otri).tri[6] & (uintptr_t) 2l) != 0l) | |
96 | ||
97 | /* Check or set a triangle's attributes. */ | |
98 | ||
99 | @@ -1158,16 +1134,16 @@ int minus1mod3[3] = {2, 0, 1}; | |
100 | /* are masked out to produce the real pointer. */ | |
101 | ||
102 | #define sdecode(sptr, osub) \ | |
103 | - (osub).ssorient = (int) ((unsigned long) (sptr) & (unsigned long) 1l); \ | |
104 | + (osub).ssorient = (int) ((uintptr_t) (sptr) & (uintptr_t) 1l); \ | |
105 | (osub).ss = (subseg *) \ | |
106 | - ((unsigned long) (sptr) & ~ (unsigned long) 3l) | |
107 | + ((uintptr_t) (sptr) & ~ (uintptr_t) 3l) | |
108 | ||
109 | /* sencode() compresses an oriented subsegment into a single pointer. It */ | |
110 | /* relies on the assumption that all subsegments are aligned to two-byte */ | |
111 | /* boundaries, so the least significant bit of (osub).ss is zero. */ | |
112 | ||
113 | #define sencode(osub) \ | |
114 | - (subseg) ((unsigned long) (osub).ss | (unsigned long) (osub).ssorient) | |
115 | + (subseg) ((uintptr_t) (osub).ss | (uintptr_t) (osub).ssorient) | |
116 | ||
117 | /* ssym() toggles the orientation of a subsegment. */ | |
118 | ||
119 | @@ -3891,7 +3867,7 @@ struct memorypool *pool; | |
120 | #endif /* not ANSI_DECLARATORS */ | |
121 | ||
122 | { | |
123 | - unsigned long alignptr; | |
124 | + uintptr_t alignptr = 0; | |
125 | ||
126 | pool->items = 0; | |
127 | pool->maxitems = 0; | |
128 | @@ -3899,11 +3875,11 @@ struct memorypool *pool; | |
129 | /* Set the currently active block. */ | |
130 | pool->nowblock = pool->firstblock; | |
131 | /* Find the first item in the pool. Increment by the size of (VOID *). */ | |
132 | - alignptr = (unsigned long) (pool->nowblock + 1); | |
133 | + alignptr = (uintptr_t) (pool->nowblock + 1); | |
134 | /* Align the item on an `alignbytes'-byte boundary. */ | |
135 | pool->nextitem = (VOID *) | |
136 | - (alignptr + (unsigned long) pool->alignbytes - | |
137 | - (alignptr % (unsigned long) pool->alignbytes)); | |
138 | + (alignptr + (uintptr_t) pool->alignbytes - | |
139 | + (alignptr % (uintptr_t) pool->alignbytes)); | |
140 | /* There are lots of unallocated items left in this block. */ | |
141 | pool->unallocateditems = pool->itemsfirstblock; | |
142 | /* The stack of deallocated items is empty. */ | |
143 | @@ -4008,7 +3984,7 @@ struct memorypool *pool; | |
144 | { | |
145 | VOID *newitem; | |
146 | VOID **newblock; | |
147 | - unsigned long alignptr; | |
148 | + uintptr_t alignptr = 0; | |
149 | ||
150 | /* First check the linked list of dead items. If the list is not */ | |
151 | /* empty, allocate an item from the list rather than a fresh one. */ | |
152 | @@ -4033,11 +4009,11 @@ struct memorypool *pool; | |
153 | pool->nowblock = (VOID **) *(pool->nowblock); | |
154 | /* Find the first item in the block. */ | |
155 | /* Increment by the size of (VOID *). */ | |
156 | - alignptr = (unsigned long) (pool->nowblock + 1); | |
157 | + alignptr = (uintptr_t) (pool->nowblock + 1); | |
158 | /* Align the item on an `alignbytes'-byte boundary. */ | |
159 | pool->nextitem = (VOID *) | |
160 | - (alignptr + (unsigned long) pool->alignbytes - | |
161 | - (alignptr % (unsigned long) pool->alignbytes)); | |
162 | + (alignptr + (uintptr_t) pool->alignbytes - | |
163 | + (alignptr % (uintptr_t) pool->alignbytes)); | |
164 | /* There are lots of unallocated items left in this block. */ | |
165 | pool->unallocateditems = pool->itemsperblock; | |
166 | } | |
167 | @@ -4092,16 +4068,16 @@ struct memorypool *pool; | |
168 | #endif /* not ANSI_DECLARATORS */ | |
169 | ||
170 | { | |
171 | - unsigned long alignptr; | |
172 | + uintptr_t alignptr = 0; | |
173 | ||
174 | /* Begin the traversal in the first block. */ | |
175 | pool->pathblock = pool->firstblock; | |
176 | /* Find the first item in the block. Increment by the size of (VOID *). */ | |
177 | - alignptr = (unsigned long) (pool->pathblock + 1); | |
178 | + alignptr = (uintptr_t) (pool->pathblock + 1); | |
179 | /* Align with item on an `alignbytes'-byte boundary. */ | |
180 | pool->pathitem = (VOID *) | |
181 | - (alignptr + (unsigned long) pool->alignbytes - | |
182 | - (alignptr % (unsigned long) pool->alignbytes)); | |
183 | + (alignptr + (uintptr_t) pool->alignbytes - | |
184 | + (alignptr % (uintptr_t) pool->alignbytes)); | |
185 | /* Set the number of items left in the current block. */ | |
186 | pool->pathitemsleft = pool->itemsfirstblock; | |
187 | } | |
188 | @@ -4129,7 +4105,7 @@ struct memorypool *pool; | |
189 | ||
190 | { | |
191 | VOID *newitem; | |
192 | - unsigned long alignptr; | |
193 | + uintptr_t alignptr = 0; | |
194 | ||
195 | /* Stop upon exhausting the list of items. */ | |
196 | if (pool->pathitem == pool->nextitem) { | |
197 | @@ -4141,11 +4117,11 @@ struct memorypool *pool; | |
198 | /* Find the next block. */ | |
199 | pool->pathblock = (VOID **) *(pool->pathblock); | |
200 | /* Find the first item in the block. Increment by the size of (VOID *). */ | |
201 | - alignptr = (unsigned long) (pool->pathblock + 1); | |
202 | + alignptr = (uintptr_t) (pool->pathblock + 1); | |
203 | /* Align with item on an `alignbytes'-byte boundary. */ | |
204 | pool->pathitem = (VOID *) | |
205 | - (alignptr + (unsigned long) pool->alignbytes - | |
206 | - (alignptr % (unsigned long) pool->alignbytes)); | |
207 | + (alignptr + (uintptr_t) pool->alignbytes - | |
208 | + (alignptr % (uintptr_t) pool->alignbytes)); | |
209 | /* Set the number of items left in the current block. */ | |
210 | pool->pathitemsleft = pool->itemsperblock; | |
211 | } | |
212 | @@ -4197,16 +4173,16 @@ int subsegbytes; | |
213 | #endif /* not ANSI_DECLARATORS */ | |
214 | ||
215 | { | |
216 | - unsigned long alignptr; | |
217 | + uintptr_t alignptr = 0; | |
218 | ||
219 | /* Set up `dummytri', the `triangle' that occupies "outer space." */ | |
220 | m->dummytribase = (triangle *) trimalloc(trianglebytes + | |
221 | m->triangles.alignbytes); | |
222 | /* Align `dummytri' on a `triangles.alignbytes'-byte boundary. */ | |
223 | - alignptr = (unsigned long) m->dummytribase; | |
224 | + alignptr = (uintptr_t) m->dummytribase; | |
225 | m->dummytri = (triangle *) | |
226 | - (alignptr + (unsigned long) m->triangles.alignbytes - | |
227 | - (alignptr % (unsigned long) m->triangles.alignbytes)); | |
228 | + (alignptr + (uintptr_t) m->triangles.alignbytes - | |
229 | + (alignptr % (uintptr_t) m->triangles.alignbytes)); | |
230 | /* Initialize the three adjoining triangles to be "outer space." These */ | |
231 | /* will eventually be changed by various bonding operations, but their */ | |
232 | /* values don't really matter, as long as they can legally be */ | |
233 | @@ -4226,10 +4202,10 @@ int subsegbytes; | |
234 | m->dummysubbase = (subseg *) trimalloc(subsegbytes + | |
235 | m->subsegs.alignbytes); | |
236 | /* Align `dummysub' on a `subsegs.alignbytes'-byte boundary. */ | |
237 | - alignptr = (unsigned long) m->dummysubbase; | |
238 | + alignptr = (uintptr_t) m->dummysubbase; | |
239 | m->dummysub = (subseg *) | |
240 | - (alignptr + (unsigned long) m->subsegs.alignbytes - | |
241 | - (alignptr % (unsigned long) m->subsegs.alignbytes)); | |
242 | + (alignptr + (uintptr_t) m->subsegs.alignbytes - | |
243 | + (alignptr % (uintptr_t) m->subsegs.alignbytes)); | |
244 | /* Initialize the two adjoining subsegments to be the omnipresent */ | |
245 | /* subsegment. These will eventually be changed by various bonding */ | |
246 | /* operations, but their values don't really matter, as long as they */ | |
247 | @@ -4586,7 +4562,7 @@ int number; | |
248 | { | |
249 | VOID **getblock; | |
250 | char *foundvertex; | |
251 | - unsigned long alignptr; | |
252 | + uintptr_t alignptr = 0; | |
253 | int current; | |
254 | ||
255 | getblock = m->vertices.firstblock; | |
256 | @@ -4603,9 +4579,9 @@ int number; | |
257 | } | |
258 | ||
259 | /* Now find the right vertex. */ | |
260 | - alignptr = (unsigned long) (getblock + 1); | |
261 | - foundvertex = (char *) (alignptr + (unsigned long) m->vertices.alignbytes - | |
262 | - (alignptr % (unsigned long) m->vertices.alignbytes)); | |
263 | + alignptr = (uintptr_t) (getblock + 1); | |
264 | + foundvertex = (char *) (alignptr + (uintptr_t) m->vertices.alignbytes - | |
265 | + (alignptr % (uintptr_t) m->vertices.alignbytes)); | |
266 | return (vertex) (foundvertex + m->vertices.itembytes * (number - current)); | |
267 | } | |
268 | ||
269 | @@ -4883,6 +4859,7 @@ struct osub *newsubseg; | |
270 | /* */ | |
271 | /*****************************************************************************/ | |
272 | ||
273 | +static | |
274 | void exactinit() | |
275 | { | |
276 | REAL half; | |
277 | @@ -4956,6 +4933,7 @@ void exactinit() | |
278 | /* */ | |
279 | /*****************************************************************************/ | |
280 | ||
281 | +static | |
282 | #ifdef ANSI_DECLARATORS | |
283 | int fast_expansion_sum_zeroelim(int elen, REAL *e, int flen, REAL *f, REAL *h) | |
284 | #else /* not ANSI_DECLARATORS */ | |
285 | @@ -5050,6 +5028,7 @@ REAL *h; | |
286 | /* */ | |
287 | /*****************************************************************************/ | |
288 | ||
289 | +static | |
290 | #ifdef ANSI_DECLARATORS | |
291 | int scale_expansion_zeroelim(int elen, REAL *e, REAL b, REAL *h) | |
292 | #else /* not ANSI_DECLARATORS */ | |
293 | @@ -5106,6 +5085,7 @@ REAL *h; | |
294 | /* */ | |
295 | /*****************************************************************************/ | |
296 | ||
297 | +static | |
298 | #ifdef ANSI_DECLARATORS | |
299 | REAL estimate(int elen, REAL *e) | |
300 | #else /* not ANSI_DECLARATORS */ | |
301 | @@ -5303,6 +5283,7 @@ vertex pc; | |
302 | /* */ | |
303 | /*****************************************************************************/ | |
304 | ||
305 | +static | |
306 | #ifdef ANSI_DECLARATORS | |
307 | REAL incircleadapt(vertex pa, vertex pb, vertex pc, vertex pd, REAL permanent) | |
308 | #else /* not ANSI_DECLARATORS */ | |
309 | @@ -5882,6 +5863,7 @@ REAL permanent; | |
310 | return finnow[finlength - 1]; | |
311 | } | |
312 | ||
313 | +static | |
314 | #ifdef ANSI_DECLARATORS | |
315 | REAL incircle(struct mesh *m, struct behavior *b, | |
316 | vertex pa, vertex pb, vertex pc, vertex pd) | |
317 | @@ -5964,6 +5946,7 @@ vertex pd; | |
318 | /* */ | |
319 | /*****************************************************************************/ | |
320 | ||
321 | +static | |
322 | #ifdef ANSI_DECLARATORS | |
323 | REAL orient3dadapt(vertex pa, vertex pb, vertex pc, vertex pd, | |
324 | REAL aheight, REAL bheight, REAL cheight, REAL dheight, | |
325 | @@ -6389,6 +6372,7 @@ REAL permanent; | |
326 | return finnow[finlength - 1]; | |
327 | } | |
328 | ||
329 | +static | |
330 | #ifdef ANSI_DECLARATORS | |
331 | REAL orient3d(struct mesh *m, struct behavior *b, | |
332 | vertex pa, vertex pb, vertex pc, vertex pd, | |
333 | @@ -7649,7 +7633,7 @@ struct otri *searchtri; | |
334 | char *firsttri; | |
335 | struct otri sampletri; | |
336 | vertex torg, tdest; | |
337 | - unsigned long alignptr; | |
338 | + uintptr_t alignptr = 0; | |
339 | REAL searchdist, dist; | |
340 | REAL ahead; | |
341 | long samplesperblock, totalsamplesleft, samplesleft; | |
342 | @@ -7721,11 +7705,11 @@ struct otri *searchtri; | |
343 | population = totalpopulation; | |
344 | } | |
345 | /* Find a pointer to the first triangle in the block. */ | |
346 | - alignptr = (unsigned long) (sampleblock + 1); | |
347 | + alignptr = (uintptr_t) (sampleblock + 1); | |
348 | firsttri = (char *) (alignptr + | |
349 | - (unsigned long) m->triangles.alignbytes - | |
350 | + (uintptr_t) m->triangles.alignbytes - | |
351 | (alignptr % | |
352 | - (unsigned long) m->triangles.alignbytes)); | |
353 | + (uintptr_t) m->triangles.alignbytes)); | |
354 | ||
355 | /* Choose `samplesleft' randomly sampled triangles in this block. */ | |
356 | do { | |
357 | diff --git a/triangle.h b/triangle.h | |
358 | index 9df1f39..8d9c754 100644 | |
359 | --- a/triangle.h | |
360 | +++ b/triangle.h | |
361 | @@ -248,16 +248,20 @@ | |
362 | /* */ | |
363 | /*****************************************************************************/ | |
364 | ||
365 | +#ifdef __cplusplus | |
366 | +extern "C" { | |
367 | +#endif | |
368 | + | |
369 | struct triangulateio { | |
370 | - REAL *pointlist; /* In / out */ | |
371 | - REAL *pointattributelist; /* In / out */ | |
372 | + double *pointlist; /* In / out */ | |
373 | + double *pointattributelist; /* In / out */ | |
374 | int *pointmarkerlist; /* In / out */ | |
375 | int numberofpoints; /* In / out */ | |
376 | int numberofpointattributes; /* In / out */ | |
377 | ||
378 | int *trianglelist; /* In / out */ | |
379 | - REAL *triangleattributelist; /* In / out */ | |
380 | - REAL *trianglearealist; /* In only */ | |
381 | + double *triangleattributelist; /* In / out */ | |
382 | + double *trianglearealist; /* In only */ | |
383 | int *neighborlist; /* Out only */ | |
384 | int numberoftriangles; /* In / out */ | |
385 | int numberofcorners; /* In / out */ | |
386 | @@ -267,23 +271,22 @@ struct triangulateio { | |
387 | int *segmentmarkerlist; /* In / out */ | |
388 | int numberofsegments; /* In / out */ | |
389 | ||
390 | - REAL *holelist; /* In / pointer to array copied out */ | |
391 | + double *holelist; /* In / pointer to array copied out */ | |
392 | int numberofholes; /* In / copied out */ | |
393 | ||
394 | - REAL *regionlist; /* In / pointer to array copied out */ | |
395 | + double *regionlist; /* In / pointer to array copied out */ | |
396 | int numberofregions; /* In / copied out */ | |
397 | ||
398 | int *edgelist; /* Out only */ | |
399 | int *edgemarkerlist; /* Not used with Voronoi diagram; out only */ | |
400 | - REAL *normlist; /* Used only with Voronoi diagram; out only */ | |
401 | + double *normlist; /* Used only with Voronoi diagram; out only */ | |
402 | int numberofedges; /* Out only */ | |
403 | }; | |
404 | ||
405 | -#ifdef ANSI_DECLARATORS | |
406 | void triangulate(char *, struct triangulateio *, struct triangulateio *, | |
407 | struct triangulateio *); | |
408 | -void trifree(VOID *memptr); | |
409 | -#else /* not ANSI_DECLARATORS */ | |
410 | -void triangulate(); | |
411 | -void trifree(); | |
412 | -#endif /* not ANSI_DECLARATORS */ | |
413 | +void trifree(void *memptr); | |
414 | + | |
415 | +#ifdef __cplusplus | |
416 | +} | |
417 | +#endif | |
418 | \ No newline at end of file |