use boostvoronoi::prelude::*;

type I = i32; // this is the integer input type
fn main() -> Result<(), BvError> {
    // Only unique Points will be used. Points should not
    // intersect lines.
    let points: [[I; 2]; 1] = [[9, 10]];
    // Lines may only intersect at the endpoints.
    let segments: [[I; 4]; 1] = [[10, 11, 12, 33]];
    let diagram = Builder::<I>::default()
        // You will have to keep track of the input geometry. it
        // will be referenced as input geometry indices in the
        // output.
        // `with_vertices()` accepts iterators of anything that
        // implements `Into<boostvoronoi::Point>`
        .with_vertices(points.iter())?
        // `with_segments()` accepts iterators of anything that
        //  implements `Into<boostvoronoi::Line>`
        .with_segments(segments.iter())?
        // this will generate the list of cells, edges and circle
        // events (aka vertices)
        .build()?;
    println!(
        "Result: cells:{}, edges:{}, vertices:{}",
        diagram.cells().len(),
        diagram.edges().len(),
        diagram.vertices().len()
    );
    for cell in diagram.cells().iter() {
        println!("Cell : {:?}", cell.id());
        for edge_id in diagram.cell_edge_iterator(cell.id()) {
            let edge = diagram.edge(edge_id)?;
            // The vertices of an edge will have the value `None`
            // if they are infinitely far away.
            println!(
                "  edge: {edge_id:?}, from:{:?} to:{:?}",
                edge.vertex0(),
                diagram.edge_get_vertex1(edge_id)?
            );
        }
    }
    Ok(())
}
