4 个版本 (2 个重大变更)

0.2.0 2022年2月28日
0.1.1 2021年10月31日
0.1.0 2021年6月6日
0.0.1 2021年1月9日

#78 in 可视化

Download history 64/week @ 2024-03-11 70/week @ 2024-03-18 128/week @ 2024-03-25 193/week @ 2024-04-01 51/week @ 2024-04-08 65/week @ 2024-04-15 47/week @ 2024-04-22 54/week @ 2024-04-29 50/week @ 2024-05-06 62/week @ 2024-05-13 42/week @ 2024-05-20 52/week @ 2024-05-27 42/week @ 2024-06-03 39/week @ 2024-06-10 40/week @ 2024-06-17 42/week @ 2024-06-24

每月下载量 168 次
4 个 crate 中使用 (3 个直接使用)

MIT 许可证

120KB
1.5K SLoC

Voronoice

Crate API Build

使用 Rust 编写的构建二维 Voronoi 图 的简单快捷方法。

Voronoice 首先通过快速的 delaunator crate 获取其 Delaunay 三角剖分,然后提取其对应的 Voronoi 图。

示例

use voronoice::*;

// voronoi sites
let sites = vec![
    Point { x: 0.0, y: 0.0 }, Point { x: 1.0, y: 0.0 }, Point { x: 0.0, y: 1.0 }
];

// builds a voronoi diagram from the set of sites above, bounded by a square of size 4
let my_voronoi = VoronoiBuilder::default()
    .set_sites(sites)
    .set_bounding_box(BoundingBox::new_centered_square(4.0))
    .set_lloyd_relaxation_iterations(5)
    .build()
    .unwrap();

// inspect cells through iterators
my_voronoi.iter_cells().for_each(|cell| {
    println!("Vertices of cell: {:?}", cell.vertices().collect::<Vec<&Point>>())
});

// or probe cells individually
let my_cell = my_voronoi.cell(1);
println!("Second cell has site {:?}, voronoi vertices {:?} and delaunay triangles {:?}",
    my_cell.site_position(),
    my_cell.vertices().collect::<Vec<&Point>>(),
    my_cell.triangles().collect::<Vec<usize>>());

// or, for graphical applications, that benefit from index buffers
// you can access the raw, indexed data
let all_voronoi_cell_vertices = my_voronoi.vertices();
let indexed_voronoi_cells = my_voronoi.cells();
println!("The first vertex position for the first voronoi cell is at {:?}",
    all_voronoi_cell_vertices[indexed_voronoi_cells[0][0]]);

文档

docs.rs 上。

性能

以下是在 2012 年的 3.5GHz Core i7 处理器上的生成时间。

点数 时间
1,000 150 µs
10,000 1.5 ms
100,000 18 ms
1,000,000 270 ms
5,000,000 1.6 s
10,000,000 3.5 s

与其他 Rust Voronoi 图生成库的比较基准测试可以在这里找到:这里

示例

svg

cargorun --examplesvg ---s10 -l2 -z0.8 -o example.svg --render-labels false

生成 SVG 图像以可视化 Voronoi-Delaunay 图。提供 --帮助 以查看其他选项。

Example of SVG Voronoi

image

cargorun --release --exampleimage --examples/assets/mona_noice_small.jpg 300

通过叠加 Voronoi 图生成颜色平均图像

Original image Image after voronoi cell averaging

其他

依赖项

~575KB