use boostvoronoi::prelude::*;

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

mod common;
use common::almost_equal;

type I = i32;

#[test]
fn sample_primary_031() -> Result<(), BvError> {
    let output = {
        let input = r#"1
0 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)?;
        Builder::<I>::default()
            .with_vertices(points.iter())?
            .with_segments(segments.iter())?
            .build()?
    };
    assert_eq!(output.cells().len(), 37);
    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_eq!(_cat, SourceCategory::SinglePoint);
    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!(!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_eq!(_cat, SourceCategory::Segment);
    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!(!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_eq!(_cat, SourceCategory::Segment);
    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!(!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_eq!(_cat, SourceCategory::Segment);
    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());
    let cell = output.cells()[36];
    assert_eq!(cell.id(), 36);
    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(), 48);
    assert_eq!(output.edges().len(), 168);
    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(), -4.9500000, v.y(), -1.0000000));
    assert_eq!(v.get_incident_edge()?, 57);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), -4.9500000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 59);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), -4.8923311, v.y(), -1.5766889));
    assert_eq!(v.get_incident_edge()?, 61);
    let v = output.vertices()[12];
    assert!(almost_equal(v.x(), -4.8923311, v.y(), 1.5766889));
    assert_eq!(v.get_incident_edge()?, 63);
    let v = output.vertices()[13];
    assert!(almost_equal(v.x(), -4.0000000, v.y(), -3.0000000));
    assert_eq!(v.get_incident_edge()?, 65);
    let v = output.vertices()[14];
    assert!(almost_equal(v.x(), -4.0000000, v.y(), 3.0000000));
    assert_eq!(v.get_incident_edge()?, 67);
    let v = output.vertices()[15];
    assert!(almost_equal(v.x(), -3.5714286, v.y(), -3.5714286));
    assert_eq!(v.get_incident_edge()?, 73);
    let v = output.vertices()[16];
    assert!(almost_equal(v.x(), -3.5714286, v.y(), 3.5714286));
    assert_eq!(v.get_incident_edge()?, 75);
    let v = output.vertices()[17];
    assert!(almost_equal(v.x(), -3.0000000, v.y(), -4.0000000));
    assert_eq!(v.get_incident_edge()?, 77);
    let v = output.vertices()[18];
    assert!(almost_equal(v.x(), -3.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 79);
    let v = output.vertices()[19];
    assert!(almost_equal(v.x(), 1.0000000, v.y(), -11.0000000));
    assert_eq!(v.get_incident_edge()?, 83);
    let v = output.vertices()[20];
    assert!(almost_equal(v.x(), 1.0000000, v.y(), 11.0000000));
    assert_eq!(v.get_incident_edge()?, 87);
    let v = output.vertices()[21];
    assert!(almost_equal(v.x(), 1.5714286, v.y(), -10.4285714));
    assert_eq!(v.get_incident_edge()?, 93);
    let v = output.vertices()[22];
    assert!(almost_equal(v.x(), 1.5714286, v.y(), 10.4285714));
    assert_eq!(v.get_incident_edge()?, 95);
    let v = output.vertices()[23];
    assert!(almost_equal(v.x(), 0.0000000, v.y(), -12.5000000));
    assert_eq!(v.get_incident_edge()?, 97);
    let v = output.vertices()[24];
    assert!(almost_equal(v.x(), 0.0000000, v.y(), 12.5000000));
    assert_eq!(v.get_incident_edge()?, 99);
    let v = output.vertices()[25];
    assert!(almost_equal(v.x(), -1.5766889, v.y(), -4.8923311));
    assert_eq!(v.get_incident_edge()?, 101);
    let v = output.vertices()[26];
    assert!(almost_equal(v.x(), -1.5766889, v.y(), 4.8923311));
    assert_eq!(v.get_incident_edge()?, 103);
    let v = output.vertices()[27];
    assert!(almost_equal(v.x(), -1.0000000, v.y(), -4.9500000));
    assert_eq!(v.get_incident_edge()?, 105);
    let v = output.vertices()[28];
    assert!(almost_equal(v.x(), -1.0000000, v.y(), 4.9500000));
    assert_eq!(v.get_incident_edge()?, 107);
    let v = output.vertices()[29];
    assert!(almost_equal(v.x(), 1.0000000, v.y(), -4.9500000));
    assert_eq!(v.get_incident_edge()?, 113);
    let v = output.vertices()[30];
    assert!(almost_equal(v.x(), 1.0000000, v.y(), 4.9500000));
    assert_eq!(v.get_incident_edge()?, 115);
    let v = output.vertices()[31];
    assert!(almost_equal(v.x(), 1.5766889, v.y(), -4.8923311));
    assert_eq!(v.get_incident_edge()?, 117);
    let v = output.vertices()[32];
    assert!(almost_equal(v.x(), 1.5766889, v.y(), 4.8923311));
    assert_eq!(v.get_incident_edge()?, 119);
    let v = output.vertices()[33];
    assert!(almost_equal(v.x(), 3.0000000, v.y(), -4.0000000));
    assert_eq!(v.get_incident_edge()?, 121);
    let v = output.vertices()[34];
    assert!(almost_equal(v.x(), 3.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 123);
    let v = output.vertices()[35];
    assert!(almost_equal(v.x(), 3.5714286, v.y(), -3.5714286));
    assert_eq!(v.get_incident_edge()?, 133);
    let v = output.vertices()[36];
    assert!(almost_equal(v.x(), 3.5714286, v.y(), 3.5714286));
    assert_eq!(v.get_incident_edge()?, 135);
    let v = output.vertices()[37];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), -3.0000000));
    assert_eq!(v.get_incident_edge()?, 137);
    let v = output.vertices()[38];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), 3.0000000));
    assert_eq!(v.get_incident_edge()?, 139);
    let v = output.vertices()[39];
    assert!(almost_equal(v.x(), 4.9500000, v.y(), -1.0000000));
    assert_eq!(v.get_incident_edge()?, 145);
    let v = output.vertices()[40];
    assert!(almost_equal(v.x(), 4.9500000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 149);
    let v = output.vertices()[41];
    assert!(almost_equal(v.x(), 4.8923311, v.y(), -1.5766889));
    assert_eq!(v.get_incident_edge()?, 151);
    let v = output.vertices()[42];
    assert!(almost_equal(v.x(), 4.8923311, v.y(), 1.5766889));
    assert_eq!(v.get_incident_edge()?, 153);
    let v = output.vertices()[43];
    assert!(almost_equal(v.x(), 10.4285714, v.y(), -1.5714286));
    assert_eq!(v.get_incident_edge()?, 159);
    let v = output.vertices()[44];
    assert!(almost_equal(v.x(), 10.4285714, v.y(), 1.5714286));
    assert_eq!(v.get_incident_edge()?, 161);
    let v = output.vertices()[45];
    assert!(almost_equal(v.x(), 11.0000000, v.y(), -1.0000000));
    assert_eq!(v.get_incident_edge()?, 163);
    let v = output.vertices()[46];
    assert!(almost_equal(v.x(), 11.0000000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 165);
    let v = output.vertices()[47];
    assert!(almost_equal(v.x(), 12.5000000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 167);
    Ok(())
}

#[test]
fn sample_primary_032() -> Result<(), BvError> {
    let output = {
        let input = r#"3
0 -4
2 8
-16 15
1
7 20 7 -20
"#;
        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(), 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(), 6);
    assert_eq!(output.edges().len(), 22);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -9.9826087, v.y(), 3.8304348));
    assert_eq!(v.get_incident_edge()?, 5);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -14.7857143, v.y(), -20.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 0.9166506, v.y(), 2.0138916));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), -4.6426618, v.y(), 17.5617267));
    assert_eq!(v.get_incident_edge()?, 15);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), -5.0434783, v.y(), 20.0000000));
    assert_eq!(v.get_incident_edge()?, 19);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), -63.6869919, v.y(), -41.3943089));
    assert_eq!(v.get_incident_edge()?, 21);
    Ok(())
}

#[test]
fn sample_primary_033() -> Result<(), BvError> {
    let output = {
        let input = r#"4
-6 6
-5 6
-4 6
-3 6
1
0 0 0 7
"#;
        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(), 7);
    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!(!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());
    assert_eq!(output.vertices().len(), 8);
    assert_eq!(output.edges().len(), 28);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -6.0000000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -5.5000000, v.y(), 0.5227744));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), -4.5000000, v.y(), 1.5278640));
    assert_eq!(v.get_incident_edge()?, 15);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), -3.5000000, v.y(), 2.5358984));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), -1.6666667, v.y(), 7.0000000));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), -3.5000000, v.y(), 12.5000000));
    assert_eq!(v.get_incident_edge()?, 23);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), -4.5000000, v.y(), 16.5000000));
    assert_eq!(v.get_incident_edge()?, 25);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), -5.5000000, v.y(), 21.5000000));
    assert_eq!(v.get_incident_edge()?, 27);
    Ok(())
}

#[test]
fn sample_primary_034() -> Result<(), BvError> {
    let output = {
        let input = r#"0
4
0 -4 2 8
2 8 -16 15
0 -4 -16 15
7 20 7 -20
"#;
        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(), 9);
    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());
    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());
    assert_eq!(output.vertices().len(), 12);
    assert_eq!(output.edges().len(), 40);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -16.0000000, v.y(), 15.0000000));
    assert_eq!(v.get_incident_edge()?, 5);
    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(), -2.5741126, v.y(), 5.3969379));
    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(), -14.7857143, v.y(), -20.0000000));
    assert_eq!(v.get_incident_edge()?, 23);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), 3.4760263, v.y(), -4.5793377));
    assert_eq!(v.get_incident_edge()?, 25);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), 4.4828759, v.y(), 7.5861873));
    assert_eq!(v.get_incident_edge()?, 27);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), 3.3301305, v.y(), 11.4203355));
    assert_eq!(v.get_incident_edge()?, 29);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), -2.5389358, v.y(), 20.0000000));
    assert_eq!(v.get_incident_edge()?, 33);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), -23.5569106, v.y(), -23.8373984));
    assert_eq!(v.get_incident_edge()?, 35);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), -8.2749004, v.y(), 34.8645418));
    assert_eq!(v.get_incident_edge()?, 37);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), -151.4715447, v.y(), -99.0813008));
    assert_eq!(v.get_incident_edge()?, 39);
    Ok(())
}

#[test]
fn sample_primary_035() -> Result<(), BvError> {
    let output = {
        let input = r#"0
20
100 0 95 30
95 30 80 58
80 58 58 80
58 80 30 95
30 95 0 99
0 99 -30 95
-30 95 -58 80
-58 80 -80 58
-80 58 -95 30
-95 30 -99 0
-99 0 -95 -30
-95 -30 -80 -58
-80 -58 -58 -80
-58 -80 -30 -95
-30 -95 0 -99
0 -99 30 -95
30 -95 58 -80
58 -80 80 -58
80 -58 95 -30
95 -30 100 0
"#;
        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(), 40);
    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!(!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_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());
    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_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!(!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_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_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!(!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_eq!(_cat, SourceCategory::Segment);
    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_eq!(_cat, SourceCategory::Segment);
    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!(!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!(!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_eq!(_cat, SourceCategory::Segment);
    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_eq!(_cat, SourceCategory::Segment);
    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!(!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_eq!(_cat, SourceCategory::Segment);
    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_eq!(_cat, SourceCategory::Segment);
    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());
    let cell = output.cells()[36];
    assert_eq!(cell.id(), 36);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[37];
    assert_eq!(cell.id(), 37);
    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()[38];
    assert_eq!(cell.id(), 38);
    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()[39];
    assert_eq!(cell.id(), 39);
    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(), 136);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -99.0000000, v.y(), -0.0000000));
    assert_eq!(v.get_incident_edge()?, 5);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -95.0000000, v.y(), -30.0000000));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), -95.0000000, v.y(), 30.0000000));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), -80.0000000, v.y(), -58.0000000));
    assert_eq!(v.get_incident_edge()?, 25);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), -80.0000000, v.y(), 58.0000000));
    assert_eq!(v.get_incident_edge()?, 29);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), -58.0000000, v.y(), -80.0000000));
    assert_eq!(v.get_incident_edge()?, 37);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), -58.0000000, v.y(), 80.0000000));
    assert_eq!(v.get_incident_edge()?, 41);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), -30.0000000, v.y(), -95.0000000));
    assert_eq!(v.get_incident_edge()?, 49);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), -30.0000000, v.y(), 95.0000000));
    assert_eq!(v.get_incident_edge()?, 53);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), -0.0000000, v.y(), -99.0000000));
    assert_eq!(v.get_incident_edge()?, 61);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), -0.0000000, v.y(), 99.0000000));
    assert_eq!(v.get_incident_edge()?, 65);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), 30.0000000, v.y(), -95.0000000));
    assert_eq!(v.get_incident_edge()?, 73);
    let v = output.vertices()[12];
    assert!(almost_equal(v.x(), 30.0000000, v.y(), 95.0000000));
    assert_eq!(v.get_incident_edge()?, 77);
    let v = output.vertices()[13];
    assert!(almost_equal(v.x(), 58.0000000, v.y(), -80.0000000));
    assert_eq!(v.get_incident_edge()?, 85);
    let v = output.vertices()[14];
    assert!(almost_equal(v.x(), 58.0000000, v.y(), 80.0000000));
    assert_eq!(v.get_incident_edge()?, 89);
    let v = output.vertices()[15];
    assert!(almost_equal(v.x(), 80.0000000, v.y(), -58.0000000));
    assert_eq!(v.get_incident_edge()?, 97);
    let v = output.vertices()[16];
    assert!(almost_equal(v.x(), 80.0000000, v.y(), 58.0000000));
    assert_eq!(v.get_incident_edge()?, 101);
    let v = output.vertices()[17];
    assert!(almost_equal(v.x(), -2.0439806, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 103);
    let v = output.vertices()[18];
    assert!(almost_equal(v.x(), -1.8724422, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 105);
    let v = output.vertices()[19];
    assert!(almost_equal(v.x(), 95.0000000, v.y(), -30.0000000));
    assert_eq!(v.get_incident_edge()?, 113);
    let v = output.vertices()[20];
    assert!(almost_equal(v.x(), 95.0000000, v.y(), 30.0000000));
    assert_eq!(v.get_incident_edge()?, 117);
    let v = output.vertices()[21];
    assert!(almost_equal(v.x(), -0.0000000, v.y(), -2.0439806));
    assert_eq!(v.get_incident_edge()?, 119);
    let v = output.vertices()[22];
    assert!(almost_equal(v.x(), 0.0000000, v.y(), 2.0439806));
    assert_eq!(v.get_incident_edge()?, 121);
    let v = output.vertices()[23];
    assert!(almost_equal(v.x(), 0.0000000, v.y(), 1.8724422));
    assert_eq!(v.get_incident_edge()?, 123);
    let v = output.vertices()[24];
    assert!(almost_equal(v.x(), -0.0000000, v.y(), -1.8724422));
    assert_eq!(v.get_incident_edge()?, 125);
    let v = output.vertices()[25];
    assert!(almost_equal(v.x(), -0.0000000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 127);
    let v = output.vertices()[26];
    assert!(almost_equal(v.x(), 1.8724422, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 129);
    let v = output.vertices()[27];
    assert!(almost_equal(v.x(), 6.9786032, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 131);
    let v = output.vertices()[28];
    assert!(almost_equal(v.x(), 100.0000000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 135);
    Ok(())
}

#[allow(clippy::excessive_precision)]
#[test]
fn sample_primary_040() -> Result<(), BvError> {
    let output = {
        let input = r#"10
858993458 1717986916
-429496729 1288490187
-2147483645 -1288490187
-2147483645 -858993458
-1717986916 858993458
-2147483645 -429496729
429496729 -2147483645
858993458 -429496729
-429496729 1717986916
1717986916 -858993458
0
"#;
        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(), 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(), 9);
    assert_eq!(output.edges().len(), 36);
    let v = output.vertices()[0];
    assert!(almost_equal(
        v.x(),
        -1216907398.8333333,
        v.y(),
        1503238551.5000000
    ));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[1];
    assert!(almost_equal(
        v.x(),
        -644245093.5000000,
        v.y(),
        -644245093.5000000
    ));
    assert_eq!(v.get_incident_edge()?, 19);
    let v = output.vertices()[2];
    assert!(almost_equal(
        v.x(),
        -644245093.5000000,
        v.y(),
        -214748364.4999999
    ));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[3];
    assert!(almost_equal(
        v.x(),
        -644245093.5000000,
        v.y(),
        -1073741822.5000000
    ));
    assert_eq!(v.get_incident_edge()?, 23);
    let v = output.vertices()[4];
    assert!(almost_equal(
        v.x(),
        214748364.5000000,
        v.y(),
        1503238551.5000000
    ));
    assert_eq!(v.get_incident_edge()?, 25);
    let v = output.vertices()[5];
    assert!(almost_equal(
        v.x(),
        -596523234.7222221,
        v.y(),
        -978298104.9444439
    ));
    assert_eq!(v.get_incident_edge()?, 27);
    let v = output.vertices()[6];
    assert!(almost_equal(
        v.x(),
        501079517.1666666,
        v.y(),
        644245093.5000000
    ));
    assert_eq!(v.get_incident_edge()?, 29);
    let v = output.vertices()[7];
    assert!(almost_equal(
        v.x(),
        930576246.1666664,
        v.y(),
        -1360072975.1666667
    ));
    assert_eq!(v.get_incident_edge()?, 33);
    let v = output.vertices()[8];
    assert!(almost_equal(
        v.x(),
        1932735280.5000002,
        v.y(),
        644245093.5000000
    ));
    assert_eq!(v.get_incident_edge()?, 35);
    Ok(())
}

#[test]
fn sample_primary_041() -> Result<(), BvError> {
    let output = {
        let input = r#"0
6
0 0 0 10
-5 0 -1 0
-6 2 -1 2
-4 5 -2 5
-8 8 -1 8
-7 -2 -7 7
"#;
        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(), 18);
    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::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());
    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!(!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!(!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!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 25);
    assert_eq!(output.edges().len(), 84);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -57.5000000, v.y(), -2.0000000));
    assert_eq!(v.get_incident_edge()?, 7);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -8.0000000, v.y(), 7.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), -6.0000000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), -6.0000000, v.y(), 3.0000000));
    assert_eq!(v.get_incident_edge()?, 19);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), -6.0000000, v.y(), 7.0000000));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), -5.8284271, v.y(), 0.8284271));
    assert_eq!(v.get_incident_edge()?, 27);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), -5.0000000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 29);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), -5.2426407, v.y(), 3.7573593));
    assert_eq!(v.get_incident_edge()?, 35);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), -5.2426407, v.y(), 6.2426407));
    assert_eq!(v.get_incident_edge()?, 37);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), -5.0000000, v.y(), -2.0000000));
    assert_eq!(v.get_incident_edge()?, 39);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), -4.0000000, v.y(), 3.5000000));
    assert_eq!(v.get_incident_edge()?, 41);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), -4.0000000, v.y(), 6.5000000));
    assert_eq!(v.get_incident_edge()?, 43);
    let v = output.vertices()[12];
    assert!(almost_equal(v.x(), -2.0000000, v.y(), 3.5000000));
    assert_eq!(v.get_incident_edge()?, 53);
    let v = output.vertices()[13];
    assert!(almost_equal(v.x(), -2.0000000, v.y(), 6.5000000));
    assert_eq!(v.get_incident_edge()?, 55);
    let v = output.vertices()[14];
    assert!(almost_equal(v.x(), -0.5000000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 61);
    let v = output.vertices()[15];
    assert!(almost_equal(v.x(), -1.0000000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 63);
    let v = output.vertices()[16];
    assert!(almost_equal(v.x(), -1.0000000, v.y(), 3.0000000));
    assert_eq!(v.get_incident_edge()?, 65);
    let v = output.vertices()[17];
    assert!(almost_equal(v.x(), -1.5358984, v.y(), 3.5358984));
    assert_eq!(v.get_incident_edge()?, 67);
    let v = output.vertices()[18];
    assert!(almost_equal(v.x(), -1.5358984, v.y(), 6.4641016));
    assert_eq!(v.get_incident_edge()?, 69);
    let v = output.vertices()[19];
    assert!(almost_equal(v.x(), -1.0000000, v.y(), 7.0000000));
    assert_eq!(v.get_incident_edge()?, 71);
    let v = output.vertices()[20];
    assert!(almost_equal(v.x(), -1.0000000, v.y(), 9.0000000));
    assert_eq!(v.get_incident_edge()?, 73);
    let v = output.vertices()[21];
    assert!(almost_equal(v.x(), -2.0000000, v.y(), 10.0000000));
    assert_eq!(v.get_incident_edge()?, 77);
    let v = output.vertices()[22];
    assert!(almost_equal(v.x(), -8.0000000, v.y(), 25.0000000));
    assert_eq!(v.get_incident_edge()?, 79);
    let v = output.vertices()[23];
    assert!(almost_equal(v.x(), -1.0000000, v.y(), -10.0000000));
    assert_eq!(v.get_incident_edge()?, 81);
    let v = output.vertices()[24];
    assert!(almost_equal(v.x(), -0.5000000, v.y(), -11.5000000));
    assert_eq!(v.get_incident_edge()?, 83);
    Ok(())
}

#[test]
fn sample_primary_042() -> Result<(), BvError> {
    let output = {
        let input = r#"0
3
-6 -1 -5 3
-1 0 4 -1
3 0 4 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(), 9);
    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!(!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());
    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());
    assert_eq!(output.vertices().len(), 11);
    assert_eq!(output.edges().len(), 38);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -3.2631579, v.y(), -1.6842105));
    assert_eq!(v.get_incident_edge()?, 9);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -2.3684211, v.y(), 2.3421053));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 1.7543219, v.y(), 1.2456781));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), 3.3567892, v.y(), -0.3567892));
    assert_eq!(v.get_incident_edge()?, 19);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), -2.3000000, v.y(), -6.5000000));
    assert_eq!(v.get_incident_edge()?, 25);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), 4.1783946, v.y(), -0.1080271));
    assert_eq!(v.get_incident_edge()?, 27);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), 0.8858048, v.y(), 4.1141952));
    assert_eq!(v.get_incident_edge()?, 29);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), 0.1363636, v.y(), 5.6818182));
    assert_eq!(v.get_incident_edge()?, 31);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), 5.0000000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 33);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), 0.3965572, v.y(), 6.0345072));
    assert_eq!(v.get_incident_edge()?, 35);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), -1.0000000, v.y(), -26.0000000));
    assert_eq!(v.get_incident_edge()?, 37);
    Ok(())
}

#[test]
fn sample_primary_043() -> Result<(), BvError> {
    let output = {
        let input = r#"0
3
-5 -2 -4 2
-5 3 -2 2
-5 5 -2 2
"#;
        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(), 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!(!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!(!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(), -15.0000000, v.y(), 0.5000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -6.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), -5.4153374, v.y(), 1.7539877));
    assert_eq!(v.get_incident_edge()?, 15);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), -4.7639320, v.y(), 3.7082039));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), -4.6645399, v.y(), 2.1661350));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), -3.4301347, v.y(), 1.8575337));
    assert_eq!(v.get_incident_edge()?, 23);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), -2.0000000, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 27);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), -2.5698653, v.y(), 0.2904041));
    assert_eq!(v.get_incident_edge()?, 29);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), 1.2500000, v.y(), -3.5625000));
    assert_eq!(v.get_incident_edge()?, 31);
    Ok(())
}

#[test]
fn sample_primary_044() -> Result<(), BvError> {
    let output = {
        let input = r#"0
3
-9 -8 -4 -3
-8 -3 -4 -3
-2 7 -1 3
"#;
        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(), 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!(!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(), 7);
    assert_eq!(output.edges().len(), 28);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -12.2500000, v.y(), -4.7500000));
    assert_eq!(v.get_incident_edge()?, 7);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -8.0000000, v.y(), -4.6568542));
    assert_eq!(v.get_incident_edge()?, 9);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), -4.0000000, v.y(), -3.0000000));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), -10.0000000, v.y(), 5.0000000));
    assert_eq!(v.get_incident_edge()?, 19);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), -8.0000000, v.y(), 3.6365995));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), -5.6846584, v.y(), 1.8288354));
    assert_eq!(v.get_incident_edge()?, 25);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), -4.0000000, v.y(), 0.7500000));
    assert_eq!(v.get_incident_edge()?, 27);
    Ok(())
}

#[test]
fn sample_primary_045() -> Result<(), BvError> {
    let output = {
        let input = r#"0
3
14 76 38 29
37 47 61 50
39 37 41 35
"#;
        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(), 9);
    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::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());
    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());
    assert_eq!(output.vertices().len(), 12);
    assert_eq!(output.edges().len(), 40);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), 37.3588820, v.y(), 35.3588820));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), 39.0430183, v.y(), 33.0430183));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 37.2324883, v.y(), 41.8464977));
    assert_eq!(v.get_incident_edge()?, 19);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), 37.6341463, v.y(), 41.9268293));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), 41.7105263, v.y(), 30.8947368));
    assert_eq!(v.get_incident_edge()?, 23);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), 35.6273058, v.y(), 57.9815538));
    assert_eq!(v.get_incident_edge()?, 25);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), 43.4560969, v.y(), 41.4560969));
    assert_eq!(v.get_incident_edge()?, 27);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), 46.4342645, v.y(), 40.4342645));
    assert_eq!(v.get_incident_edge()?, 29);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), 64.1250000, v.y(), 25.0000000));
    assert_eq!(v.get_incident_edge()?, 33);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), 55.3487783, v.y(), 95.2097735));
    assert_eq!(v.get_incident_edge()?, 35);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), 56.7744479, v.y(), 97.8422713));
    assert_eq!(v.get_incident_edge()?, 37);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), 70.5000000, v.y(), 16.5000000));
    assert_eq!(v.get_incident_edge()?, 39);
    Ok(())
}

#[test]
fn sample_primary_046() -> Result<(), BvError> {
    let output = {
        let input = r#"2
2 -5
3 -3
1
0 0 2 -7
"#;
        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(), 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!(!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());
    assert_eq!(output.vertices().len(), 4);
    assert_eq!(output.edges().len(), 16);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), 2.3000793, v.y(), -3.9000397));
    assert_eq!(v.get_incident_edge()?, 9);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), 4.2000000, v.y(), 1.2000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 5.5000000, v.y(), -6.0000000));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), 6.5000000, v.y(), -6.0000000));
    assert_eq!(v.get_incident_edge()?, 15);
    Ok(())
}

#[test]
fn sample_primary_047() -> Result<(), BvError> {
    let output = {
        let input = r#"1
-35 -49
2
-48 -29 -46 -78
-46 -46 -45 -42
"#;
        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(), 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!(!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::SinglePoint);
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 8);
    assert_eq!(output.edges().len(), 28);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -46.6461377, v.y(), -45.8384656));
    assert_eq!(v.get_incident_edge()?, 9);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -46.2216040, v.y(), -41.6945990));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), -41.0643516, v.y(), -49.5692893));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), -40.4680851, v.y(), -47.3829787));
    assert_eq!(v.get_incident_edge()?, 19);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), -38.6595745, v.y(), -43.5851064));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), -31.0032271, v.y(), -32.6474673));
    assert_eq!(v.get_incident_edge()?, 23);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), -24.6490787, v.y(), -28.0469012));
    assert_eq!(v.get_incident_edge()?, 25);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), -6.5209380, v.y(), -76.3886097));
    assert_eq!(v.get_incident_edge()?, 27);
    Ok(())
}
