Skip to content

TimTheBig/geogram_predicates

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

101 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Geogram Predicates

A Rust port of geograms robust predicates. An interoperability ffi with geograms robust predicates; via cxx also available.

Why Geogram

Geogram is a scientifically proven, well-documented, feature-rich geometry processing library, which leverages "[...] arithmetic filters (Meyer and Pion), expansion arithmetics (Shewchuk) and simulation of simplicity (Edelsbrunner)."
Be sure to check it out here.

It yields easy access to dependency-free parts of its code base, as so called Pluggable Software Modules (PSM), which in turn make it easy to write cxx_bridges for these.

This library is licenced under the MIT, when the legacy feature is enabled the c++ code it uses is under Apache-2.0.

Example

With that, you can add geometry predicates to your rust project, without the need to re-implement existing state-of-the-art software. E.g. using the rust alternative to geograms incircle predicate for triangles:

use geogram_predicates::in_circle_2d_sos;

// Define three points that form a triangle
let a = [0.0, 0.0];
let b = [2.0, 0.0];
let c = [1.0, 1.0];

// Define two points, to test against the triangles circum-circle
let p_in = [1.0, -0.4];
let p_out = [1.0, -1.2];

let is_in_circle_p_in = gp::in_circle_2d_sos(&a, &b, &c, &p_in);
assert_eq!(1, is_in_circle_p_in);

let is_in_circle_p_out = gp::in_circle_2d_sos(&a, &b, &c, &p_out);
assert_eq!(-1, is_in_circle_p_out);

// Do something fancy based on the result
// ...

Safety

The only unsafe code transmutes an array to a struct of the same size and types, which does not affect the values as long as it's not a reference.

Visualizing Advantages of Robust Predicates

Below are visualizations comparing naive and robust orient_2d & in_circle_2d implementations. You can generate these images yourself by running the examples for orient_2d or in_circle_2d.

Naive Robust
orient_2d Orient 2d naive Orient 2d robust
in_circle_2d In circle 2d naive In circle 2d robust

List of currently supported predicates

2D

  • in_circle_2D_SOS()
  • orient_2d()
  • orient_2dlifted_SOS()
  • points_are_identical_2d()

3D

  • det_3d()
  • dot_3d()
  • in_sphere_3d_SOS()
  • orient_3d()
  • orient_3d_inexact()
  • orient_3dlifted_SOS()
  • points_are_colinear_3d()
  • points_are_identical_3d()

Other

  • det_4d() (not in rust)
  • geo_sgn() (renamed to geo_sign)
  • initialize() (not in rust)
  • show_stats() (not in rust)
  • terminate() (not in rust)

There are a lot of predicates still to be implemented. If you are in need for a specific one have a look at the geograms predicate list. The bridge for any one predicate is implemented pretty quickly, so this crate is easily extendable.

Design

The API to the geogram predicates is designed with the following design principles in mind:

  • Relation to geogram: the function names, signatures and doc strings should be as close as possible to the original. This keeps maintaining, updating and comparing as simple as possible

Contribution

If you see something as

  • software design principles that could be improved,
  • potential bugs,
  • ambiguous documentation, typos etc.,
  • ...

feel free to open a PR to address this.

Acknowledgements

Credits go to geogram and cxx, which made this project possible.

B.Levy for making the original geogram library.

Also georust/robust should be mentioned, for helping set up the examples, their visualizations, and use in the codebase.

Thanks @BrunoLevy for appreciating this project!

License

The files in include/geogram_predicates_psm are licensed w.r.t.

Copyright (c) 2000-2022 Inria All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the ALICE Project-Team nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

The rest of this software is licensed under GNU Lesser General Public License, Version 3.0.

About

Geograms robust predicates writen in Rust

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • C++ 84.9%
  • Rust 15.1%