Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[triangle] Add new port #13322

Merged
merged 18 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions ports/triangle/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
cmake_minimum_required(VERSION 2.8.12)
project(triangle)

include(GNUInstallDirs)

add_library(triangleLib triangle.c exports.def)
add_executable(triangle triangle.c)

target_compile_definitions(triangleLib PRIVATE -DTRILIBRARY -DANSI_DECLARATORS)
target_compile_definitions(triangle PRIVATE -DANSI_DECLARATORS)
if(WIN32)
target_compile_definitions(triangleLib PRIVATE -DNO_TIMER)
target_compile_definitions(triangle PRIVATE -DNO_TIMER)
endif()

if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(triangle m)
endif()

target_include_directories(triangleLib PUBLIC
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}>
)

set_target_properties(triangleLib PROPERTIES POSITION_INDEPENDENT_CODE ON)

set_target_properties(triangleLib PROPERTIES PUBLIC_HEADER
"${CMAKE_SOURCE_DIR}/triangle.h"
)

set_target_properties(triangleLib PROPERTIES OUTPUT_NAME "triangle")

install(TARGETS triangleLib EXPORT triangleTargets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(TARGETS triangle DESTINATION tools/triangle)

install(EXPORT triangleTargets
FILE triangleConfig.cmake
NAMESPACE triangle::
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/triangle"
)
5 changes: 5 additions & 0 deletions ports/triangle/CONTROL
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Source: triangle
Version: 1.6
Homepage: http://www.cs.cmu.edu/~quake/triangle.html
Description: A Two-Dimensional Quality Mesh Generator and Delaunay Triangulator.
Supports: !uwp
346 changes: 346 additions & 0 deletions ports/triangle/enable_64bit_architecture.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,346 @@
diff --git a/triangle.c b/triangle.c
index f7a5700..9f9ee82 100644
--- a/triangle.c
+++ b/triangle.c
@@ -340,6 +340,11 @@

#define ONETHIRD 0.333333333333333333333333333333333333333333333333333333333333

+
+/* Define the size large enough to store and operate on a pointer. */
+#define INT_PTR unsigned long long
+
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -938,16 +943,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) ((INT_PTR) (ptr) & (INT_PTR) 3l); \
(otri).tri = (triangle *) \
- ((unsigned long) (ptr) ^ (unsigned long) (otri).orient)
+ ((INT_PTR) (ptr) ^ (INT_PTR) (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) ((INT_PTR) (otri).tri | (INT_PTR) (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 +1116,16 @@ int minus1mod3[3] = {2, 0, 1};

#define infect(otri) \
(otri).tri[6] = (triangle) \
- ((unsigned long) (otri).tri[6] | (unsigned long) 2l)
+ ((INT_PTR) (otri).tri[6] | (INT_PTR) 2l)

#define uninfect(otri) \
(otri).tri[6] = (triangle) \
- ((unsigned long) (otri).tri[6] & ~ (unsigned long) 2l)
+ ((INT_PTR) (otri).tri[6] & ~ (INT_PTR) 2l)

/* Test a triangle for viral infection. */

#define infected(otri) \
- (((unsigned long) (otri).tri[6] & (unsigned long) 2l) != 0l)
+ (((INT_PTR) (otri).tri[6] & (INT_PTR) 2l) != 0l)

/* Check or set a triangle's attributes. */

@@ -1158,16 +1163,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) ((INT_PTR) (sptr) & (INT_PTR) 1l); \
(osub).ss = (subseg *) \
- ((unsigned long) (sptr) & ~ (unsigned long) 3l)
+ ((INT_PTR) (sptr) & ~ (INT_PTR) 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) ((INT_PTR) (osub).ss | (INT_PTR) (osub).ssorient)

/* ssym() toggles the orientation of a subsegment. */

@@ -3891,7 +3896,7 @@ struct memorypool *pool;
#endif /* not ANSI_DECLARATORS */

{
- unsigned long alignptr;
+ INT_PTR alignptr = 0;

pool->items = 0;
pool->maxitems = 0;
@@ -3899,11 +3904,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 = (INT_PTR) (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 + (INT_PTR) pool->alignbytes -
+ (alignptr % (INT_PTR) 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 +4013,7 @@ struct memorypool *pool;
{
VOID *newitem;
VOID **newblock;
- unsigned long alignptr;
+ INT_PTR 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 +4038,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 = (INT_PTR) (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 + (INT_PTR) pool->alignbytes -
+ (alignptr % (INT_PTR) pool->alignbytes));
/* There are lots of unallocated items left in this block. */
pool->unallocateditems = pool->itemsperblock;
}
@@ -4092,16 +4097,16 @@ struct memorypool *pool;
#endif /* not ANSI_DECLARATORS */

{
- unsigned long alignptr;
+ INT_PTR 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 = (INT_PTR) (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 + (INT_PTR) pool->alignbytes -
+ (alignptr % (INT_PTR) pool->alignbytes));
/* Set the number of items left in the current block. */
pool->pathitemsleft = pool->itemsfirstblock;
}
@@ -4129,7 +4134,7 @@ struct memorypool *pool;

{
VOID *newitem;
- unsigned long alignptr;
+ INT_PTR alignptr = 0;

/* Stop upon exhausting the list of items. */
if (pool->pathitem == pool->nextitem) {
@@ -4141,11 +4146,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 = (INT_PTR) (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 + (INT_PTR) pool->alignbytes -
+ (alignptr % (INT_PTR) pool->alignbytes));
/* Set the number of items left in the current block. */
pool->pathitemsleft = pool->itemsperblock;
}
@@ -4197,16 +4202,16 @@ int subsegbytes;
#endif /* not ANSI_DECLARATORS */

{
- unsigned long alignptr;
+ INT_PTR 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 = (INT_PTR) m->dummytribase;
m->dummytri = (triangle *)
- (alignptr + (unsigned long) m->triangles.alignbytes -
- (alignptr % (unsigned long) m->triangles.alignbytes));
+ (alignptr + (INT_PTR) m->triangles.alignbytes -
+ (alignptr % (INT_PTR) 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 +4231,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 = (INT_PTR) m->dummysubbase;
m->dummysub = (subseg *)
- (alignptr + (unsigned long) m->subsegs.alignbytes -
- (alignptr % (unsigned long) m->subsegs.alignbytes));
+ (alignptr + (INT_PTR) m->subsegs.alignbytes -
+ (alignptr % (INT_PTR) 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 +4591,7 @@ int number;
{
VOID **getblock;
char *foundvertex;
- unsigned long alignptr;
+ INT_PTR alignptr = 0;
int current;

getblock = m->vertices.firstblock;
@@ -4603,9 +4608,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 = (INT_PTR) (getblock + 1);
+ foundvertex = (char *) (alignptr + (INT_PTR) m->vertices.alignbytes -
+ (alignptr % (INT_PTR) m->vertices.alignbytes));
return (vertex) (foundvertex + m->vertices.itembytes * (number - current));
}

@@ -4883,6 +4888,7 @@ struct osub *newsubseg;
/* */
/*****************************************************************************/

+static
void exactinit()
{
REAL half;
@@ -4956,6 +4962,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 +5057,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 +5114,7 @@ REAL *h;
/* */
/*****************************************************************************/

+static
#ifdef ANSI_DECLARATORS
REAL estimate(int elen, REAL *e)
#else /* not ANSI_DECLARATORS */
@@ -5303,6 +5312,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 +5892,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 +5975,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 +6401,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 +7662,7 @@ struct otri *searchtri;
char *firsttri;
struct otri sampletri;
vertex torg, tdest;
- unsigned long alignptr;
+ INT_PTR alignptr = 0;
REAL searchdist, dist;
REAL ahead;
long samplesperblock, totalsamplesleft, samplesleft;
@@ -7721,11 +7734,11 @@ struct otri *searchtri;
population = totalpopulation;
}
/* Find a pointer to the first triangle in the block. */
- alignptr = (unsigned long) (sampleblock + 1);
+ alignptr = (INT_PTR) (sampleblock + 1);
firsttri = (char *) (alignptr +
- (unsigned long) m->triangles.alignbytes -
+ (INT_PTR) m->triangles.alignbytes -
(alignptr %
- (unsigned long) m->triangles.alignbytes));
+ (INT_PTR) m->triangles.alignbytes));

/* Choose `samplesleft' randomly sampled triangles in this block. */
do {
diff --git a/triangle.h b/triangle.h
index 9df1f39..70a352d 100644
--- a/triangle.h
+++ b/triangle.h
@@ -248,6 +248,10 @@
/* */
/*****************************************************************************/

+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct triangulateio {
REAL *pointlist; /* In / out */
REAL *pointattributelist; /* In / out */
@@ -279,11 +283,10 @@ struct triangulateio {
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 */
+
+#ifdef __cplusplus
+}
+#endif
\ No newline at end of file
Loading