use boostvoronoi::prelude::*;

use std::io::{BufReader, Cursor};

mod common;
use common::almost_equal;

type I = i32;

#[test]
fn sample_primary_001() -> Result<(), BvError> {
    let output = {
        let input = r#"1
0 0
0
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 1);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 0);
    assert_eq!(output.edges().len(), 0);
    Ok(())
}

#[test]
fn sample_primary_002() -> Result<(), BvError> {
    let output = {
        let input = r#"2
0 0
1 0
0
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 2);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 0);
    assert_eq!(output.edges().len(), 2);
    Ok(())
}

#[test]
fn sample_primary_003() -> Result<(), BvError> {
    let output = {
        let input = r#"2
0 0
0 1
0
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 2);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 0);
    assert_eq!(output.edges().len(), 2);
    Ok(())
}

#[test]
fn sample_primary_004() -> Result<(), BvError> {
    let output = {
        let input = r#"2
0 0
1 1
0
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 2);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 0);
    assert_eq!(output.edges().len(), 2);
    Ok(())
}

#[test]
fn sample_primary_005() -> Result<(), BvError> {
    let output = {
        let input = r#"10
0 0
0 1
0 2
0 3
0 4
0 -1
0 -2
0 -3
0 -4
0 -5
0
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 10);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[5];
    assert_eq!(cell.id(), 5);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[6];
    assert_eq!(cell.id(), 6);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[7];
    assert_eq!(cell.id(), 7);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[8];
    assert_eq!(cell.id(), 8);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[9];
    assert_eq!(cell.id(), 9);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 0);
    assert_eq!(output.edges().len(), 18);
    Ok(())
}
#[test]
fn sample_primary_006() -> Result<(), BvError> {
    let output = {
        let input = r#"10
0 0
1 0
2 0
3 0
4 0
5 0
-1 0
-2 0
-3 0
-4 0
0
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 10);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[5];
    assert_eq!(cell.id(), 5);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[6];
    assert_eq!(cell.id(), 6);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[7];
    assert_eq!(cell.id(), 7);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[8];
    assert_eq!(cell.id(), 8);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[9];
    assert_eq!(cell.id(), 9);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 0);
    assert_eq!(output.edges().len(), 18);
    Ok(())
}

#[test]
fn sample_primary_007() -> Result<(), BvError> {
    let output = {
        let input = r#"11
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
0
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 11);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[5];
    assert_eq!(cell.id(), 5);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[6];
    assert_eq!(cell.id(), 6);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[7];
    assert_eq!(cell.id(), 7);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[8];
    assert_eq!(cell.id(), 8);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[9];
    assert_eq!(cell.id(), 9);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[10];
    assert_eq!(cell.id(), 10);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 0);
    assert_eq!(output.edges().len(), 20);
    Ok(())
}

#[test]
fn sample_primary_008() -> Result<(), BvError> {
    let output = {
        let input = r#"10
-46 -37
-40 -30
-34 -23
-28 -16
-22 -9
-16 -2
-10 5
-4 12
2 19
8 26
0
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 10);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[5];
    assert_eq!(cell.id(), 5);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[6];
    assert_eq!(cell.id(), 6);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[7];
    assert_eq!(cell.id(), 7);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[8];
    assert_eq!(cell.id(), 8);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[9];
    assert_eq!(cell.id(), 9);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 0);
    assert_eq!(output.edges().len(), 18);
    Ok(())
}

#[test]
fn sample_primary_009() -> Result<(), BvError> {
    let output = {
        let input = r#"10
33333 11111
66666 0
99999 -11111
133332 -22222
166665 -33333
199998 -44444
233331 -55555
266664 -66666
299997 -77777
333330 -88888
0
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 10);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[5];
    assert_eq!(cell.id(), 5);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[6];
    assert_eq!(cell.id(), 6);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[7];
    assert_eq!(cell.id(), 7);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[8];
    assert_eq!(cell.id(), 8);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[9];
    assert_eq!(cell.id(), 9);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 0);
    assert_eq!(output.edges().len(), 18);
    Ok(())
}

#[test]
fn sample_primary_010() -> Result<(), BvError> {
    let output = {
        let input = r#"3
0 0
2005 2005
10025 10025
0
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 3);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 0);
    assert_eq!(output.edges().len(), 4);
    Ok(())
}

#[test]
fn sample_primary_011() -> Result<(), BvError> {
    let output = {
        let input = r#"3
0 0
0 4
1 1
0
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 3);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 1);
    assert_eq!(output.edges().len(), 6);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -1.0000000, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 5);
    Ok(())
}

#[test]
fn sample_primary_012() -> Result<(), BvError> {
    let output = {
        let input = r#"4
0 0
0 1
1 0
1 1
0
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 4);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 1);
    assert_eq!(output.edges().len(), 8);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), 0.5000000, v.y(), 0.5000000));
    assert_eq!(v.get_incident_edge()?, 7);
    Ok(())
}

#[test]
fn sample_primary_013() -> Result<(), BvError> {
    let output = {
        let input = r#"13
0 5
0 -5
-4 -3
4 -3
4 3
-4 3
3 -4
-3 4
-3 -4
3 4
-5 0
5 0
0 0
0
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 13);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[5];
    assert_eq!(cell.id(), 5);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[6];
    assert_eq!(cell.id(), 6);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[7];
    assert_eq!(cell.id(), 7);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[8];
    assert_eq!(cell.id(), 8);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[9];
    assert_eq!(cell.id(), 9);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[10];
    assert_eq!(cell.id(), 10);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[11];
    assert_eq!(cell.id(), 11);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[12];
    assert_eq!(cell.id(), 12);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 12);
    assert_eq!(output.edges().len(), 48);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -2.5000000, v.y(), -0.8333333));
    assert_eq!(v.get_incident_edge()?, 15);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -2.5000000, v.y(), 0.8333333));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), -1.7857143, v.y(), -1.7857143));
    assert_eq!(v.get_incident_edge()?, 19);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), -1.7857143, v.y(), 1.7857143));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), -0.8333333, v.y(), -2.5000000));
    assert_eq!(v.get_incident_edge()?, 23);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), -0.8333333, v.y(), 2.5000000));
    assert_eq!(v.get_incident_edge()?, 25);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), 0.8333333, v.y(), -2.5000000));
    assert_eq!(v.get_incident_edge()?, 31);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), 0.8333333, v.y(), 2.5000000));
    assert_eq!(v.get_incident_edge()?, 33);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), 1.7857143, v.y(), -1.7857143));
    assert_eq!(v.get_incident_edge()?, 39);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), 1.7857143, v.y(), 1.7857143));
    assert_eq!(v.get_incident_edge()?, 41);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), 2.5000000, v.y(), -0.8333333));
    assert_eq!(v.get_incident_edge()?, 45);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), 2.5000000, v.y(), 0.8333333));
    assert_eq!(v.get_incident_edge()?, 47);
    Ok(())
}

#[test]
fn sample_primary_014() -> Result<(), BvError> {
    let output = {
        let input = r#"12
0 5
0 -5
-4 -3
4 -3
4 3
-4 3
3 -4
-3 4
-3 -4
3 4
-5 0
5 0
0
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 12);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[5];
    assert_eq!(cell.id(), 5);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[6];
    assert_eq!(cell.id(), 6);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[7];
    assert_eq!(cell.id(), 7);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[8];
    assert_eq!(cell.id(), 8);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[9];
    assert_eq!(cell.id(), 9);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[10];
    assert_eq!(cell.id(), 10);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[11];
    assert_eq!(cell.id(), 11);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 1);
    assert_eq!(output.edges().len(), 24);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -0.0000000, v.y(), -0.0000000));
    assert_eq!(v.get_incident_edge()?, 23);
    Ok(())
}

#[test]
fn sample_primary_015() -> Result<(), BvError> {
    let output = {
        let input = r#"4
4 3
4 8
9 2
9 9
0
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 4);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 1);
    assert_eq!(output.edges().len(), 8);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), 7.1000000, v.y(), 5.5000000));
    assert_eq!(v.get_incident_edge()?, 7);
    Ok(())
}

#[test]
fn sample_primary_017() -> Result<(), BvError> {
    let output = {
        let input = r#"0
1
0 0 1 1
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 3);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 0);
    assert_eq!(output.edges().len(), 4);
    Ok(())
}

#[test]
fn sample_primary_018() -> Result<(), BvError> {
    let output = {
        let input = r#"2
3 1
1 3
1
0 0 4 4
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 5);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 4);
    assert_eq!(output.edges().len(), 16);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -2.5000000, v.y(), 2.5000000));
    assert_eq!(v.get_incident_edge()?, 5);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), 1.5000000, v.y(), 6.5000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 2.5000000, v.y(), -2.5000000));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), 6.5000000, v.y(), 1.5000000));
    assert_eq!(v.get_incident_edge()?, 15);
    Ok(())
}

#[test]
fn sample_primary_019() -> Result<(), BvError> {
    let output = {
        let input = r#"2
3 2
2 3
1
4 0 0 4
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 5);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 3);
    assert_eq!(output.edges().len(), 14);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), 2.5000000, v.y(), 2.5000000));
    assert_eq!(v.get_incident_edge()?, 7);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), 2.5000000, v.y(), 6.5000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 6.5000000, v.y(), 2.5000000));
    assert_eq!(v.get_incident_edge()?, 13);
    Ok(())
}

#[test]
fn sample_primary_020() -> Result<(), BvError> {
    let output = {
        let input = r#"3
-2 -2
-2 4
-2 10
1
0 0 0 8
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 6);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[5];
    assert_eq!(cell.id(), 5);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 4);
    assert_eq!(output.edges().len(), 18);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -2.0000000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 9);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -3.2500000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), -3.2500000, v.y(), 7.0000000));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), -2.0000000, v.y(), 8.0000000));
    assert_eq!(v.get_incident_edge()?, 17);
    Ok(())
}

#[test]
fn sample_primary_021() -> Result<(), BvError> {
    let output = {
        let input = r#"1
-1 1
1
1 0 1 2
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 4);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 2);
    assert_eq!(output.edges().len(), 10);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -0.2500000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 5);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -0.2500000, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 9);
    Ok(())
}

#[test]
fn sample_primary_022() -> Result<(), BvError> {
    let output = {
        let input = r#"0
3
0 0 4 0
4 0 0 4
0 4 4 4
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 7);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[5];
    assert_eq!(cell.id(), 5);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[6];
    assert_eq!(cell.id(), 6);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 6);
    assert_eq!(output.edges().len(), 24);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -0.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 9);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -2.0000000, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 0.0000000, v.y(), 1.6568542));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), 2.3431458));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), 6.0000000, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 23);
    Ok(())
}

#[test]
fn sample_primary_023() -> Result<(), BvError> {
    let output = {
        let input = r#"0
4
0 0 4 0
4 0 4 4
4 4 0 4
0 4 0 0
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 8);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[5];
    assert_eq!(cell.id(), 5);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[6];
    assert_eq!(cell.id(), 6);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[7];
    assert_eq!(cell.id(), 7);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 5);
    assert_eq!(output.edges().len(), 24);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), 0.0000000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 7);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -0.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), -0.0000000));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), 2.0000000, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 19);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 23);
    Ok(())
}

#[test]
fn sample_primary_024() -> Result<(), BvError> {
    let output = {
        let input = r#"0
2
0 0 4 0
2 2 2 4
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 6);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[5];
    assert_eq!(cell.id(), 5);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 4);
    assert_eq!(output.edges().len(), 18);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), 0.0000000, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 7);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -3.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 15);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), 7.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 17);
    Ok(())
}

#[test]
fn sample_primary_025() -> Result<(), BvError> {
    let output = {
        let input = r#"1
5 6
2
0 0 4 0
2 2 2 4
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 7);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[5];
    assert_eq!(cell.id(), 5);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[6];
    assert_eq!(cell.id(), 6);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 5);
    assert_eq!(output.edges().len(), 22);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), 0.0000000, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 7);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -3.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), 4.1666667, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 19);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), 5.1020134, v.y(), 2.8996644));
    assert_eq!(v.get_incident_edge()?, 21);
    Ok(())
}

#[test]
fn sample_primary_026() -> Result<(), BvError> {
    let output = {
        let input = r#"2
0 0
1 6
2
-4 5 5 -1
3 -11 13 -1
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 8);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[5];
    assert_eq!(cell.id(), 5);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[6];
    assert_eq!(cell.id(), 6);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[7];
    assert_eq!(cell.id(), 7);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 9);
    assert_eq!(output.edges().len(), 32);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -9.8571429, v.y(), -3.7857143));
    assert_eq!(v.get_incident_edge()?, 5);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -2.0000000, v.y(), 8.0000000));
    assert_eq!(v.get_incident_edge()?, 9);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), -18.9827586, v.y(), -11.0862069));
    assert_eq!(v.get_incident_edge()?, 15);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), -1.6428571, v.y(), -6.3571429));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), 1.5560757, v.y(), -5.0163094));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), 2.3766275, v.y(), -4.9350587));
    assert_eq!(v.get_incident_edge()?, 23);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), 9.0000000, v.y(), 3.0000000));
    assert_eq!(v.get_incident_edge()?, 27);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), 9.0000000, v.y(), 5.0000000));
    assert_eq!(v.get_incident_edge()?, 29);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), 9.0167098, v.y(), 5.9572167));
    assert_eq!(v.get_incident_edge()?, 31);
    Ok(())
}

#[test]
fn sample_primary_027() -> Result<(), BvError> {
    let output = {
        let input = r#"2
0 0
1 6
8
-6 5 2 -7
3 -11 13 -1
-4 5 5 -1
4 4 11 4
4 4 8 10
11 4 8 10
8 10 5 13
8 10 11 13
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 21);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[5];
    assert_eq!(cell.id(), 5);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[6];
    assert_eq!(cell.id(), 6);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[7];
    assert_eq!(cell.id(), 7);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[8];
    assert_eq!(cell.id(), 8);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[9];
    assert_eq!(cell.id(), 9);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[10];
    assert_eq!(cell.id(), 10);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[11];
    assert_eq!(cell.id(), 11);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[12];
    assert_eq!(cell.id(), 12);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[13];
    assert_eq!(cell.id(), 13);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[14];
    assert_eq!(cell.id(), 14);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[15];
    assert_eq!(cell.id(), 15);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[16];
    assert_eq!(cell.id(), 16);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[17];
    assert_eq!(cell.id(), 17);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[18];
    assert_eq!(cell.id(), 18);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[19];
    assert_eq!(cell.id(), 19);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[20];
    assert_eq!(cell.id(), 20);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 30);
    assert_eq!(output.edges().len(), 98);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -5.0000000, v.y(), 5.6666667));
    assert_eq!(v.get_incident_edge()?, 7);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -4.4800000, v.y(), 4.2800000));
    assert_eq!(v.get_incident_edge()?, 9);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), -1.3263027, v.y(), 1.1263027));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), -2.0000000, v.y(), 8.0000000));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), -3.1000000, v.y(), -10.4000000));
    assert_eq!(v.get_incident_edge()?, 25);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), 1.3000000, v.y(), -9.3000000));
    assert_eq!(v.get_incident_edge()?, 27);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 35);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), 1.7500000, v.y(), 3.8750000));
    assert_eq!(v.get_incident_edge()?, 37);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), 2.5000000, v.y(), 5.0000000));
    assert_eq!(v.get_incident_edge()?, 39);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), 1.7263027, v.y(), -1.9263027));
    assert_eq!(v.get_incident_edge()?, 41);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), -2.9838710, v.y(), 12.9193548));
    assert_eq!(v.get_incident_edge()?, 49);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), -5.0000000, v.y(), 15.1875000));
    assert_eq!(v.get_incident_edge()?, 51);
    let v = output.vertices()[12];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), 2.0319584));
    assert_eq!(v.get_incident_edge()?, 53);
    let v = output.vertices()[13];
    assert!(almost_equal(v.x(), 2.0454545, v.y(), 10.0454545));
    assert_eq!(v.get_incident_edge()?, 55);
    let v = output.vertices()[14];
    assert!(almost_equal(v.x(), 3.3200000, v.y(), -3.5200000));
    assert_eq!(v.get_incident_edge()?, 57);
    let v = output.vertices()[15];
    assert!(almost_equal(v.x(), 2.8890100, v.y(), 9.4939123));
    assert_eq!(v.get_incident_edge()?, 59);
    let v = output.vertices()[16];
    assert!(almost_equal(v.x(), 4.4594117, v.y(), -5.3603922));
    assert_eq!(v.get_incident_edge()?, 61);
    let v = output.vertices()[17];
    assert!(almost_equal(v.x(), 8.0000000, v.y(), 10.0000000));
    assert_eq!(v.get_incident_edge()?, 67);
    let v = output.vertices()[18];
    assert!(almost_equal(v.x(), 4.5461461, v.y(), -4.4844594));
    assert_eq!(v.get_incident_edge()?, 69);
    let v = output.vertices()[19];
    assert!(almost_equal(v.x(), 6.5138782, v.y(), 1.2708173));
    assert_eq!(v.get_incident_edge()?, 71);
    let v = output.vertices()[20];
    assert!(almost_equal(v.x(), 7.7514493, v.y(), 6.0077147));
    assert_eq!(v.get_incident_edge()?, 73);
    let v = output.vertices()[21];
    assert!(almost_equal(v.x(), 11.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 77);
    let v = output.vertices()[22];
    assert!(almost_equal(v.x(), 8.0000000, v.y(), 16.0000000));
    assert_eq!(v.get_incident_edge()?, 81);
    let v = output.vertices()[23];
    assert!(almost_equal(v.x(), 8.6854142, v.y(), 0.1417722));
    assert_eq!(v.get_incident_edge()?, 83);
    let v = output.vertices()[24];
    assert!(almost_equal(v.x(), 10.9289322, v.y(), 1.0710678));
    assert_eq!(v.get_incident_edge()?, 87);
    let v = output.vertices()[25];
    assert!(almost_equal(v.x(), 11.0000000, v.y(), 1.1000000));
    assert_eq!(v.get_incident_edge()?, 89);
    let v = output.vertices()[26];
    assert!(almost_equal(v.x(), -107.1000000, v.y(), -62.4000000));
    assert_eq!(v.get_incident_edge()?, 91);
    let v = output.vertices()[27];
    assert!(almost_equal(v.x(), 15.1622777, v.y(), 8.8377223));
    assert_eq!(v.get_incident_edge()?, 93);
    let v = output.vertices()[28];
    assert!(almost_equal(v.x(), 20.0000000, v.y(), 8.5000000));
    assert_eq!(v.get_incident_edge()?, 95);
    let v = output.vertices()[29];
    assert!(almost_equal(v.x(), 29.5000000, v.y(), 8.5000000));
    assert_eq!(v.get_incident_edge()?, 97);
    Ok(())
}

#[test]
fn sample_primary_028() -> Result<(), BvError> {
    let output = {
        let input = r#"0
3
0 0 4 2
4 2 4 -2
4 -2 0 0
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 6);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[5];
    assert_eq!(cell.id(), 5);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 4);
    assert_eq!(output.edges().len(), 18);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), 0.0000000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 5);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), -2.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 2.7639320, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 17);
    Ok(())
}

#[test]
fn sample_primary_029() -> Result<(), BvError> {
    let output = {
        let input = r#"0
8
0 0 0 1
0 0 1 0
0 0 -1 0
0 0 0 -1
0 0 1 1
0 0 1 -1
0 0 -1 1
0 0 -1 -1
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?
    };
    assert_eq!(output.cells().len(), 17);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[5];
    assert_eq!(cell.id(), 5);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[6];
    assert_eq!(cell.id(), 6);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[7];
    assert_eq!(cell.id(), 7);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[8];
    assert_eq!(cell.id(), 8);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[9];
    assert_eq!(cell.id(), 9);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[10];
    assert_eq!(cell.id(), 10);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[11];
    assert_eq!(cell.id(), 11);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[12];
    assert_eq!(cell.id(), 12);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[13];
    assert_eq!(cell.id(), 13);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[14];
    assert_eq!(cell.id(), 14);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[15];
    assert_eq!(cell.id(), 15);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[16];
    assert_eq!(cell.id(), 16);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 17);
    assert_eq!(output.edges().len(), 64);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -1.5000000, v.y(), -0.5000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -1.5000000, v.y(), 0.5000000));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), -1.0000000, v.y(), -0.4142136));
    assert_eq!(v.get_incident_edge()?, 15);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), -1.0000000, v.y(), 0.4142136));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), -0.4142136, v.y(), -1.0000000));
    assert_eq!(v.get_incident_edge()?, 23);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), -0.4142136, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 29);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), 0.0000000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 37);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), -0.5000000, v.y(), -1.5000000));
    assert_eq!(v.get_incident_edge()?, 39);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), -0.5000000, v.y(), 1.5000000));
    assert_eq!(v.get_incident_edge()?, 41);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), 0.4142136, v.y(), -1.0000000));
    assert_eq!(v.get_incident_edge()?, 43);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), 0.4142136, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 45);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), 0.5000000, v.y(), -1.5000000));
    assert_eq!(v.get_incident_edge()?, 53);
    let v = output.vertices()[12];
    assert!(almost_equal(v.x(), 0.5000000, v.y(), 1.5000000));
    assert_eq!(v.get_incident_edge()?, 55);
    let v = output.vertices()[13];
    assert!(almost_equal(v.x(), 1.0000000, v.y(), -0.4142136));
    assert_eq!(v.get_incident_edge()?, 57);
    let v = output.vertices()[14];
    assert!(almost_equal(v.x(), 1.0000000, v.y(), 0.4142136));
    assert_eq!(v.get_incident_edge()?, 59);
    let v = output.vertices()[15];
    assert!(almost_equal(v.x(), 1.5000000, v.y(), 0.5000000));
    assert_eq!(v.get_incident_edge()?, 61);
    let v = output.vertices()[16];
    assert!(almost_equal(v.x(), 1.5000000, v.y(), -0.5000000));
    assert_eq!(v.get_incident_edge()?, 63);
    Ok(())
}

#[test]
fn sample_primary_030() -> Result<(), BvError> {
    let output = {
        let input = r#"0
12
-1 10 1 10
10 -1 10 1
-1 -10 1 -10
-10 -1 -10 1
-6 8 -2 11
-8 6 -11 2
6 8 2 11
8 6 11 2
6 -8 2 -11
8 -6 11 -2
-6 -8 -2 -11
-8 -6 -11 -2
"#;
        let br = BufReader::new(Cursor::new(input));
        let (points, segments) = read_boost_input_buffer::<I, _>(br)?;
        let output = Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?;
        #[cfg(feature = "geo")]
        common::diagram_sanity_check(&output, &points, &segments, 0.00001)?;
        output
    };
    assert_eq!(output.cells().len(), 36);
    let cell = output.cells()[0];
    assert_eq!(cell.id(), 0);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[1];
    assert_eq!(cell.id(), 1);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[2];
    assert_eq!(cell.id(), 2);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[3];
    assert_eq!(cell.id(), 3);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[4];
    assert_eq!(cell.id(), 4);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[5];
    assert_eq!(cell.id(), 5);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[6];
    assert_eq!(cell.id(), 6);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[7];
    assert_eq!(cell.id(), 7);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[8];
    assert_eq!(cell.id(), 8);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[9];
    assert_eq!(cell.id(), 9);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[10];
    assert_eq!(cell.id(), 10);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[11];
    assert_eq!(cell.id(), 11);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[12];
    assert_eq!(cell.id(), 12);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[13];
    assert_eq!(cell.id(), 13);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[14];
    assert_eq!(cell.id(), 14);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[15];
    assert_eq!(cell.id(), 15);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[16];
    assert_eq!(cell.id(), 16);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[17];
    assert_eq!(cell.id(), 17);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[18];
    assert_eq!(cell.id(), 18);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[19];
    assert_eq!(cell.id(), 19);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[20];
    assert_eq!(cell.id(), 20);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[21];
    assert_eq!(cell.id(), 21);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[22];
    assert_eq!(cell.id(), 22);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[23];
    assert_eq!(cell.id(), 23);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[24];
    assert_eq!(cell.id(), 24);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[25];
    assert_eq!(cell.id(), 25);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[26];
    assert_eq!(cell.id(), 26);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[27];
    assert_eq!(cell.id(), 27);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[28];
    assert_eq!(cell.id(), 28);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[29];
    assert_eq!(cell.id(), 29);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[30];
    assert_eq!(cell.id(), 30);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[31];
    assert_eq!(cell.id(), 31);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[32];
    assert_eq!(cell.id(), 32);
    let (_source_index, _cat) = cell.source_index_2();
    assert_eq!(_cat, SourceCategory::Segment);
    assert!(!cell.is_degenerate());
    assert!(!cell.contains_point());
    assert!(cell.contains_segment());
    let cell = output.cells()[33];
    assert_eq!(cell.id(), 33);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[34];
    assert_eq!(cell.id(), 34);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[35];
    assert_eq!(cell.id(), 35);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 29);
    assert_eq!(output.edges().len(), 128);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -11.0000000, v.y(), -1.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -12.5000000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), -11.0000000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), -10.4285714, v.y(), -1.5714286));
    assert_eq!(v.get_incident_edge()?, 19);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), -10.4285714, v.y(), 1.5714286));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), -1.5714286, v.y(), -10.4285714));
    assert_eq!(v.get_incident_edge()?, 47);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), -1.5714286, v.y(), 10.4285714));
    assert_eq!(v.get_incident_edge()?, 49);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), -1.0000000, v.y(), -11.0000000));
    assert_eq!(v.get_incident_edge()?, 51);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), -1.0000000, v.y(), 11.0000000));
    assert_eq!(v.get_incident_edge()?, 53);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), 1.0000000, v.y(), -11.0000000));
    assert_eq!(v.get_incident_edge()?, 61);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), 1.0000000, v.y(), 11.0000000));
    assert_eq!(v.get_incident_edge()?, 65);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), 1.5714286, v.y(), -10.4285714));
    assert_eq!(v.get_incident_edge()?, 71);
    let v = output.vertices()[12];
    assert!(almost_equal(v.x(), 1.5714286, v.y(), 10.4285714));
    assert_eq!(v.get_incident_edge()?, 73);
    let v = output.vertices()[13];
    assert!(almost_equal(v.x(), 0.0000000, v.y(), -12.5000000));
    assert_eq!(v.get_incident_edge()?, 75);
    let v = output.vertices()[14];
    assert!(almost_equal(v.x(), 0.0000000, v.y(), 12.5000000));
    assert_eq!(v.get_incident_edge()?, 77);
    let v = output.vertices()[15];
    assert!(almost_equal(v.x(), -3.0000000, v.y(), -1.0000000));
    assert_eq!(v.get_incident_edge()?, 79);
    let v = output.vertices()[16];
    assert!(almost_equal(v.x(), -3.0000000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 81);
    let v = output.vertices()[17];
    assert!(almost_equal(v.x(), -1.0000000, v.y(), -3.0000000));
    assert_eq!(v.get_incident_edge()?, 83);
    let v = output.vertices()[18];
    assert!(almost_equal(v.x(), -1.0000000, v.y(), 3.0000000));
    assert_eq!(v.get_incident_edge()?, 85);
    let v = output.vertices()[19];
    assert!(almost_equal(v.x(), 1.0000000, v.y(), -3.0000000));
    assert_eq!(v.get_incident_edge()?, 91);
    let v = output.vertices()[20];
    assert!(almost_equal(v.x(), 1.0000000, v.y(), 3.0000000));
    assert_eq!(v.get_incident_edge()?, 93);
    let v = output.vertices()[21];
    assert!(almost_equal(v.x(), 3.0000000, v.y(), -1.0000000));
    assert_eq!(v.get_incident_edge()?, 107);
    let v = output.vertices()[22];
    assert!(almost_equal(v.x(), -0.0000000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 109);
    let v = output.vertices()[23];
    assert!(almost_equal(v.x(), 3.0000000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 113);
    let v = output.vertices()[24];
    assert!(almost_equal(v.x(), 10.4285714, v.y(), -1.5714286));
    assert_eq!(v.get_incident_edge()?, 119);
    let v = output.vertices()[25];
    assert!(almost_equal(v.x(), 10.4285714, v.y(), 1.5714286));
    assert_eq!(v.get_incident_edge()?, 121);
    let v = output.vertices()[26];
    assert!(almost_equal(v.x(), 11.0000000, v.y(), -1.0000000));
    assert_eq!(v.get_incident_edge()?, 123);
    let v = output.vertices()[27];
    assert!(almost_equal(v.x(), 11.0000000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 125);
    let v = output.vertices()[28];
    assert!(almost_equal(v.x(), 12.5000000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 127);
    Ok(())
}
