Code Monkey home page Code Monkey logo

rtriangulate's Introduction

rtriangulate

crates.io Build Status Coverage Status

A Rust implementation of the Delaunay triangulation algorithm presented by Paul Bourke.

Find the crate documentation on docs.rs, or here on Github.

This was developed as an exercise to get more used to Rust. As far as I know, it works, but it might not. Also, this is a O(n1.5) (approximatively) algorithm, it's not parallelized, and it doesn't use the GPU at all.

Usage

Add the rtriangulate dependency to Cargo.toml:

[dependencies]
rtriangulate = "0.3"

And use the crate as such:

extern crate rtriangulate;

use rtriangulate::{TriangulationPoint, triangulate};

fn main() {
    // A list of points (which has to be sorted on x).
    // Note that you can use your own point type, just implement the rtriangulate::Point trait.
    let points = [
        TriangulationPoint::new(10.0, 50.0),
        TriangulationPoint::new(25.0, 40.0),
        TriangulationPoint::new(30.0, 40.0)
    ];

    // In case you need to sort your points:
    // points.sort_unstable_by(rtriangulate::sort_points);

    // Do the triangulation.
    let triangles = triangulate(&points).unwrap();

    println!("{:?}", triangles); // [Triangle(1, 0, 2)]
}

License

MIT - See LICENSE file.

rtriangulate's People

Contributors

llogiq avatar tynril avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

llogiq

rtriangulate's Issues

suggestion - more generic, for easier interfacing

how about
(i) parameterising the float type so you can use f32 or f64 ... f32 is very common in graphics applications,

(iia) parameterising the point type, such that you can apply this algorithm to any existing data structure with vertex arrays, so long as it can supply .x() .y() (i.e. use a 2d point trait instead of a specific point type which users can impl on their data)

(iib) alternatively make it take [T;2] as the point type, as this is a 'dependancy-free' way of passing coordinate data between libraries

(iii) avoid impl'ing 'partialord' for the point type, instead using a 'sort_by' or whatever to get the ordering - to keep the specific (ambiguous) meaning of point ordering open for applications to do with as they please

does not produce convex hull

The Delaunay triangulation should produce a triangulation with a convex hull.

To fix it you would need to check if some of the triangles that have a point of the supertriangle need to have an edge flipped, before removing them from the triangulation.

Don't know if it matters to you, but just leaving it here in case someone wants to use this implementation and needs a convex hull.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.