Pierre-Monier / voronoi_diagram

Draw voronoi diagram for given sites and diagram size

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

voronoi_diagram

voronoi_diagram

This repository is used to draw voronoi diagrams. You just have to pass sites point and the size of your diagram.

getVoronoiDiagram(sites: sites, diagramBound: diagramBound)

This return a Future<List<List<Offset>>>, each List<Offset> represent a voronoi cell. Then you can draw your voronoi diagram easily with a CustomPainter, e.g

for (final voronoiCell in voronoiDiagram) {
    canvas.drawPoints(
    PointMode.polygon,
    voronoiCell,
    Paint()
        ..color = Colors.red
        ..strokeWidth = 2,
    );
}

There is also a default VoronoiDiagramPainter to display the diagram on the screen. You can use it like this inside a CustomPaint widget :

CustomPaint(
        size: benchmarkData.diagramSize,
        painter: VoronoiDiagramPainter(
            generatorPoints: benchmarkData.generatorPoints,
            voronoiDiagram: data,
    ),
)

Benchmark

It get the drawable voronoi diagram representation in ~115ms, with 10000 sites and a diagram size of 400x400

It's calculated in "real life" context, i.e in a flutter app

you can run the benchmark with the benchmark.sh script, in the example folder.

How does it works ?

Dart code take inputs, then it use dart:ffi to calculate the voronoi diagram with the rust language, then the result is pass back to the dart side.

The rust side is using an implementation of the Fortune's algorithm. If you want to know more about this amazing topic, I recommand to read this amazing article

Contribution

To start working on the project, you must check the following.

To begin, ensure that you have a working installation of the following items:

echo "ANDROID_NDK=.." >> ~/.gradle/gradle.properties

If you are struggling during the set up, please check the flutter_rust_bridge documenation

About

Draw voronoi diagram for given sites and diagram size

License:MIT License


Languages

Language:Dart 57.4%Language:Rust 15.4%Language:Ruby 11.9%Language:C 6.0%Language:Shell 4.5%Language:Swift 2.8%Language:Objective-C 1.7%Language:Kotlin 0.3%