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