danshapero / predicates

Robust geometric predicates
51 stars 14 forks source link

predicates

This library provides code for performing robust geometric computations using adaptive-precision floating-point arithmetic. It is based on code by Jonathan Richard Shewchuk; the original source is available here. The theory behind adaptive-precision arithmetic used in the original source was described in a paper also by Shewchuk. These geometric predicates were used to write the mesh generation program Triangle, which received the 2003 Wilkinson Prize for Numerical Software.

Things that have changed since the original source code was written in 1996:

This repository is intended to contain an updated version of Shewchuk's original source code accounting for these developments. The original source is one 4.5k-line C file, although full of many helpful comments. This is somewhat hard to digest, so I'm breaking it up into several smaller files. Additionally, I'm adding unit tests, which will demonstrate both robustness of geometric predicates implemented with adaptive-precision arithmetic and the non-robustness of naive implementations. There will be no substantive modifications to the main routines.

Unit tests are in the directory test/; demonstrations of the failure of geometric predicates in floating-point arithmetic are in the directory demos.

Installation

The code is built using CMake as follows:

mkdir build
cd build
cmake ..
make

To run the unit tests:

make test

Demo programs are optionally built if you have zlib and libpng.

Licensing

This code has not been released under a well-known free software license such as the BSD License or the GNU Public License. Instead, Shewchuk released the original predicates code stating only that it was "Placed in the public domain". Lawrence Rosen, general counsel for the Open Source Initiative, has argued that public domain is not a license. I am not a lawyer, but if you're thinking of using this code for proprietary software you should consult a lawyer first. I do not own the copyright on this code and cannot grant a license to use it.