mirror of
https://github.com/microsoft/vcpkg.git
synced 2024-12-21 19:27:56 +08:00
47c0b1ce40
* New Port : libigl-triangle * Update ci.baseline.txt for libigl-triangle port * Update ports/libigl-triangle/CONTROL Unnecessary Port-Version Co-authored-by: NancyLi1013 <46708020+NancyLi1013@users.noreply.github.com> * Update ports/libigl-triangle/portfile.cmake Unnecessary inclusion of vcpkg_common_functions Co-authored-by: NancyLi1013 <46708020+NancyLi1013@users.noreply.github.com> * Update ports/libigl-triangle/portfile.cmake Use README from source as the copyright file Co-authored-by: NancyLi1013 <46708020+NancyLi1013@users.noreply.github.com> * Updates to libigl-translate port * Update libigl-triangle port * Update ports/libigl-triangle/CONTROL Co-authored-by: NancyLi1013 <46708020+NancyLi1013@users.noreply.github.com> * Update ports/libigl-triangle/portfile.cmake Co-authored-by: NancyLi1013 <46708020+NancyLi1013@users.noreply.github.com> * Make the header copy properly and add CMake targets * Utilize original sources for triangle library and rename to triangle * Build triangle executable and add it to tools * Fix Linux build which requires linking to m library for math functions * Update scripts/ci.baseline.txt Co-authored-by: NancyLi1013 <46708020+NancyLi1013@users.noreply.github.com> * Instead of defining INT_PTR, use uintptr_t from stdint.h Also, define FLOAT and VOID in the header so the user of the library does not have to define them * Make sure the port works and can be used * Remove the use of the SINGLE define for switching the REAL define to be float or double. Also make the define for VOID be void rather than replacing all VOID with void in order to reduce the patch size. Co-authored-by: Nathan Mercer <nmercer@intermap.com> Co-authored-by: NancyLi1013 <46708020+NancyLi1013@users.noreply.github.com> Co-authored-by: NancyLi1013 <lirui09@beyondsoft.com>
419 lines
18 KiB
Diff
419 lines
18 KiB
Diff
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
|