fesoliveira014 / voronator-rs

Delaunay triangulation and Voronoi diagram generation. Ported from Mapbox's Delaunator and d3-voronoi
MIT License
53 stars 13 forks source link

Duplicated points in VoronoiDiagram.cells #7

Closed davideGiovannini closed 2 years ago

davideGiovannini commented 3 years ago

I'm trying to constructs polygons for each cell, but often the list inside VoronoiDiagram.cells contains duplicated points.

For example:

#[test]
fn duplicated_points(){
    use std::collections::HashSet;
    let points =   [(2520.0, 856.0), (794.0, 66.0), (974.0, 446.0)];
    let voronoi = VoronoiDiagram::from_tuple( &(0.0, 0.0), &(2560.0, 2560.0), &points).unwrap();

    for cell_vertices in &voronoi.cells {
        {
            let expected = cell_vertices.len();
            let actual = cell_vertices
                .iter()
                .map(|n| format!("{:?}", n))
                .collect::<HashSet<String>>()
                .len();
            println!(" {} != {}", expected, actual);
            println!(
                "{}",
                cell_vertices
                    .iter()
                    .map(|n| format!("{:?}", n))
                    .collect::<String>()
            );
            assert!( expected == actual)
        }
    }
}
---- duplicated_points stdout ----
 6 != 4
[1919.6455368693403, 0][2560, 0][2560, 2560][1240.7322121604138, 2560][1240.7322121604138, 2560][1919.6455368693403, 0]
thread 'duplicated_points' panicked at 'assertion failed: expected == actual', tests/delaunator.rs:144:13
fesoliveira014 commented 3 years ago

Hello davideGiovannini, thanks for pointing this out. I will investigate what is wrong and push a patch whenever I find the solution.

entropylost commented 3 years ago

Has this been fixed yet?

fesoliveira014 commented 2 years ago

This should have been fixed by pull request #10. I will close this issue for now. Thanks @AlanRace!