GithubHelp home page GithubHelp logo

isabella232 / voronator-rs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bhickey/voronator-rs

0.0 0.0 0.0 275 KB

Delaunay triangulation and Voronoi diagram generation. Ported from Mapbox's Delaunator and d3-voronoi

License: MIT License

Rust 100.00%

voronator-rs's Introduction

voronator

Port of the d3-delaunay and delaunator libraries in Rust.

This package implements the Voronoi diagram construction as a dual of the Delaunay triangulation for a set of points. It also implements the construction of a centroidal tesselation of a Delaunay triangulation, inspired by Red Blob Games.

Examples

extern crate voronator;
extern crate rand;

use voronator::VoronoiDiagram;
use voronator::delaunator::Point;
use rand::prelude::*;
use rand::distributions::Uniform;

fn main() {
    let mut rng = rand::thread_rng();
    let range1 = Uniform::new(0., 100.);
    let range2 = Uniform::new(0., 100.);
    let mut points: Vec<(f64, f64)> = (0..10)
        .map(|_| (rng.sample(&range1), rng.sample(&range2)))
        .collect();

    let diagram = VoronoiDiagram::<Point>::from_tuple(&(0., 0.), &(100., 100.), &points).unwrap();
    
    for cell in diagram.cells() {
        let p: Vec<(f32, f32)> = cell.points().into_iter()
            .map(|x| (x.x as f32, x.y as f32))
            .collect();
        
        println!("{:?}", p);
    }
}

Possible output:

Possible output

voronator-rs's People

Contributors

alanrace avatar davidegiovannini avatar fesoliveira014 avatar

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.