use boostvoronoi::prelude::*;

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

mod common;
use common::almost_equal;

type I = i32;

#[test]
fn sample_polygon_001() -> Result<(), BvError> {
    let output = {
        let input = r#"0
8
0 0 -3 5
-3 5 2 10
2 10 4 6
4 6 10 12
10 12 13 6
13 6 11 1
11 1 5 1
5 1 0 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(), 16);
    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_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_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_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());
    assert_eq!(output.vertices().len(), 20);
    assert_eq!(output.edges().len(), 70);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -3.0000000, v.y(), 5.0000000));
    assert_eq!(v.get_incident_edge()?, 5);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), 0.0000000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 2.0000000, v.y(), 10.0000000));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), 6.0000000));
    assert_eq!(v.get_incident_edge()?, 23);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), 1.1169631, v.y(), 4.5584816));
    assert_eq!(v.get_incident_edge()?, 25);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), 1.1068348, v.y(), 4.4944255));
    assert_eq!(v.get_incident_edge()?, 27);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), 1.6345790, v.y(), 3.6950503));
    assert_eq!(v.get_incident_edge()?, 29);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), 5.0000000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 35);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), 4.5000000, v.y(), 3.5000000));
    assert_eq!(v.get_incident_edge()?, 37);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), 5.0000000, v.y(), 3.6000000));
    assert_eq!(v.get_incident_edge()?, 39);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), 4.8830369, v.y(), 11.4415184));
    assert_eq!(v.get_incident_edge()?, 41);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), 6.0710678, v.y(), 3.9289322));
    assert_eq!(v.get_incident_edge()?, 43);
    let v = output.vertices()[12];
    assert!(almost_equal(v.x(), 10.0000000, v.y(), 12.0000000));
    assert_eq!(v.get_incident_edge()?, 49);
    let v = output.vertices()[13];
    assert!(almost_equal(v.x(), 11.0000000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 55);
    let v = output.vertices()[14];
    assert!(almost_equal(v.x(), 8.3718060, v.y(), 4.8819292));
    assert_eq!(v.get_incident_edge()?, 57);
    let v = output.vertices()[15];
    assert!(almost_equal(v.x(), 4.3333333, v.y(), 17.6666667));
    assert_eq!(v.get_incident_edge()?, 59);
    let v = output.vertices()[16];
    assert!(almost_equal(v.x(), 8.9993300, v.y(), 5.8335938));
    assert_eq!(v.get_incident_edge()?, 61);
    let v = output.vertices()[17];
    assert!(almost_equal(v.x(), 13.0000000, v.y(), 6.0000000));
    assert_eq!(v.get_incident_edge()?, 65);
    let v = output.vertices()[18];
    assert!(almost_equal(v.x(), 10.0990195, v.y(), -50.4950976));
    assert_eq!(v.get_incident_edge()?, 67);
    let v = output.vertices()[19];
    assert!(almost_equal(v.x(), 11.0000000, v.y(), -60.0000000));
    assert_eq!(v.get_incident_edge()?, 69);
    Ok(())
}

#[test]
fn sample_polygon_002() -> Result<(), BvError> {
    let output = {
        let input = r#"0
14
0 0 -3 5
-3 5 2 10
2 10 4 6
4 6 10 12
10 12 13 6
13 6 11 1
11 1 5 1
5 1 0 0
1 2 0 5
0 5 5 2
5 2 1 2
10 3 8 6
8 6 10 8
10 8 10 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(), 28);
    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_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!(!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_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());
    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::Segment);
    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!(!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!(!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());
    assert_eq!(output.vertices().len(), 43);
    assert_eq!(output.edges().len(), 140);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -3.0000000, v.y(), 5.0000000));
    assert_eq!(v.get_incident_edge()?, 5);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), 0.0000000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), -0.0000000, v.y(), 5.0000000));
    assert_eq!(v.get_incident_edge()?, 19);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), -1.3189096, v.y(), 4.7930483));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), -1.2349376, v.y(), 4.5883541));
    assert_eq!(v.get_incident_edge()?, 23);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), 1.0000000, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 29);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), 0.0943791, v.y(), 1.6981264));
    assert_eq!(v.get_incident_edge()?, 31);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), 0.4984229, v.y(), 1.1267106));
    assert_eq!(v.get_incident_edge()?, 33);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), 1.0000000, v.y(), 1.1088244));
    assert_eq!(v.get_incident_edge()?, 35);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), 2.0000000, v.y(), 10.0000000));
    assert_eq!(v.get_incident_edge()?, 41);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), 0.8783735, v.y(), 6.4639558));
    assert_eq!(v.get_incident_edge()?, 43);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), 1.6656629, v.y(), 2.9235579));
    assert_eq!(v.get_incident_edge()?, 45);
    let v = output.vertices()[12];
    assert!(almost_equal(v.x(), 1.4373458, v.y(), 6.5327684));
    assert_eq!(v.get_incident_edge()?, 47);
    let v = output.vertices()[13];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), 6.0000000));
    assert_eq!(v.get_incident_edge()?, 53);
    let v = output.vertices()[14];
    assert!(almost_equal(v.x(), 2.5855967, v.y(), 5.2927983));
    assert_eq!(v.get_incident_edge()?, 55);
    let v = output.vertices()[15];
    assert!(almost_equal(v.x(), 5.0000000, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 61);
    let v = output.vertices()[16];
    assert!(almost_equal(v.x(), 5.0000000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 65);
    let v = output.vertices()[17];
    assert!(almost_equal(v.x(), 4.9009805, v.y(), 1.4950976));
    assert_eq!(v.get_incident_edge()?, 67);
    let v = output.vertices()[18];
    assert!(almost_equal(v.x(), 5.0000000, v.y(), 1.5000000));
    assert_eq!(v.get_incident_edge()?, 69);
    let v = output.vertices()[19];
    assert!(almost_equal(v.x(), 8.0000000, v.y(), 6.0000000));
    assert_eq!(v.get_incident_edge()?, 77);
    let v = output.vertices()[20];
    assert!(almost_equal(v.x(), 5.6591499, v.y(), 4.3408501));
    assert_eq!(v.get_incident_edge()?, 79);
    let v = output.vertices()[21];
    assert!(almost_equal(v.x(), 4.8830369, v.y(), 11.4415184));
    assert_eq!(v.get_incident_edge()?, 81);
    let v = output.vertices()[22];
    assert!(almost_equal(v.x(), 6.0324706, v.y(), 4.6883138));
    assert_eq!(v.get_incident_edge()?, 83);
    let v = output.vertices()[23];
    assert!(almost_equal(v.x(), 7.0000000, v.y(), 7.0000000));
    assert_eq!(v.get_incident_edge()?, 85);
    let v = output.vertices()[24];
    assert!(almost_equal(v.x(), 6.0022473, v.y(), 4.3830874));
    assert_eq!(v.get_incident_edge()?, 87);
    let v = output.vertices()[25];
    assert!(almost_equal(v.x(), 6.2742420, v.y(), 4.1237366));
    assert_eq!(v.get_incident_edge()?, 89);
    let v = output.vertices()[26];
    assert!(almost_equal(v.x(), 6.9276228, v.y(), 3.3578647));
    assert_eq!(v.get_incident_edge()?, 91);
    let v = output.vertices()[27];
    assert!(almost_equal(v.x(), 10.0000000, v.y(), 3.0000000));
    assert_eq!(v.get_incident_edge()?, 97);
    let v = output.vertices()[28];
    assert!(almost_equal(v.x(), 9.1254138, v.y(), 5.8885621));
    assert_eq!(v.get_incident_edge()?, 99);
    let v = output.vertices()[29];
    assert!(almost_equal(v.x(), 10.0000000, v.y(), 8.0000000));
    assert_eq!(v.get_incident_edge()?, 103);
    let v = output.vertices()[30];
    assert!(almost_equal(v.x(), 10.0000000, v.y(), 12.0000000));
    assert_eq!(v.get_incident_edge()?, 109);
    let v = output.vertices()[31];
    assert!(almost_equal(v.x(), 8.9296325, v.y(), 2.2864217));
    assert_eq!(v.get_incident_edge()?, 111);
    let v = output.vertices()[32];
    assert!(almost_equal(v.x(), 9.0000000, v.y(), 9.0000000));
    assert_eq!(v.get_incident_edge()?, 113);
    let v = output.vertices()[33];
    assert!(almost_equal(v.x(), 11.0000000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 119);
    let v = output.vertices()[34];
    assert!(almost_equal(v.x(), 9.5864741, v.y(), 9.4517384));
    assert_eq!(v.get_incident_edge()?, 121);
    let v = output.vertices()[35];
    assert!(almost_equal(v.x(), 10.3070132, v.y(), 2.0235643));
    assert_eq!(v.get_incident_edge()?, 123);
    let v = output.vertices()[36];
    assert!(almost_equal(v.x(), 10.8666208, v.y(), 3.0000000));
    assert_eq!(v.get_incident_edge()?, 125);
    let v = output.vertices()[37];
    assert!(almost_equal(v.x(), 10.9442719, v.y(), 8.0000000));
    assert_eq!(v.get_incident_edge()?, 127);
    let v = output.vertices()[38];
    assert!(almost_equal(v.x(), 4.3333333, v.y(), 17.6666667));
    assert_eq!(v.get_incident_edge()?, 129);
    let v = output.vertices()[39];
    assert!(almost_equal(v.x(), 11.4318062, v.y(), 5.9347716));
    assert_eq!(v.get_incident_edge()?, 131);
    let v = output.vertices()[40];
    assert!(almost_equal(v.x(), 13.0000000, v.y(), 6.0000000));
    assert_eq!(v.get_incident_edge()?, 135);
    let v = output.vertices()[41];
    assert!(almost_equal(v.x(), 10.0990195, v.y(), -50.4950976));
    assert_eq!(v.get_incident_edge()?, 137);
    let v = output.vertices()[42];
    assert!(almost_equal(v.x(), 11.0000000, v.y(), -60.0000000));
    assert_eq!(v.get_incident_edge()?, 139);
    Ok(())
}

#[test]
fn sample_polygon_003() -> Result<(), BvError> {
    let output = {
        let input = r#"0
8
0 0 0 8
0 8 4 12
4 12 9 13
9 13 13 13
13 13 13 4
13 4 10 0
10 0 5 -1
5 -1 0 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(), 16);
    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());
    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_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_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());
    assert_eq!(output.vertices().len(), 14);
    assert_eq!(output.edges().len(), 58);
    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(), 8.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), 12.0000000));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), 5.0000000, v.y(), -1.0000000));
    assert_eq!(v.get_incident_edge()?, 23);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), 9.0000000, v.y(), 13.0000000));
    assert_eq!(v.get_incident_edge()?, 29);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), 5.0000000, v.y(), 4.0990195));
    assert_eq!(v.get_incident_edge()?, 31);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), 10.0000000, v.y(), -0.0000000));
    assert_eq!(v.get_incident_edge()?, 37);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), 6.1198856, v.y(), 5.4650604));
    assert_eq!(v.get_incident_edge()?, 39);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), 6.4458560, v.y(), 5.6395144));
    assert_eq!(v.get_incident_edge()?, 41);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), 13.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 47);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), 6.8126625, v.y(), 6.0624458));
    assert_eq!(v.get_incident_edge()?, 49);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), 6.9719175, v.y(), 6.4469214));
    assert_eq!(v.get_incident_edge()?, 51);
    let v = output.vertices()[12];
    assert!(almost_equal(v.x(), 9.3603922, v.y(), 9.3603922));
    assert_eq!(v.get_incident_edge()?, 53);
    let v = output.vertices()[13];
    assert!(almost_equal(v.x(), 13.0000000, v.y(), 13.0000000));
    assert_eq!(v.get_incident_edge()?, 57);
    Ok(())
}

#[test]
fn sample_polygon_004() -> Result<(), BvError> {
    let output = {
        let input = r#"0
8
0 0 0 8
0 8 4 12
4 12 9 13
9 13 7 7
7 7 13 4
13 4 10 0
10 0 5 -1
5 -1 0 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(), 16);
    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());
    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());
    assert_eq!(output.vertices().len(), 17);
    assert_eq!(output.edges().len(), 64);
    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(), 8.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), 12.0000000));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), 5.0000000, v.y(), -1.0000000));
    assert_eq!(v.get_incident_edge()?, 23);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), 7.0000000, v.y(), 7.0000000));
    assert_eq!(v.get_incident_edge()?, 31);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), 3.5148459, v.y(), 6.5441032));
    assert_eq!(v.get_incident_edge()?, 33);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), 4.1671843, v.y(), 7.9442719));
    assert_eq!(v.get_incident_edge()?, 35);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), 5.2408359, v.y(), 9.6814768));
    assert_eq!(v.get_incident_edge()?, 37);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), 4.3444660, v.y(), 3.5616102));
    assert_eq!(v.get_incident_edge()?, 39);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), 9.0000000, v.y(), 13.0000000));
    assert_eq!(v.get_incident_edge()?, 43);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), 5.0000000, v.y(), 3.2943300));
    assert_eq!(v.get_incident_edge()?, 45);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), 5.1374151, v.y(), 3.2748301));
    assert_eq!(v.get_incident_edge()?, 47);
    let v = output.vertices()[12];
    assert!(almost_equal(v.x(), 10.0000000, v.y(), -0.0000000));
    assert_eq!(v.get_incident_edge()?, 53);
    let v = output.vertices()[13];
    assert!(almost_equal(v.x(), 8.1941104, v.y(), 2.8654834));
    assert_eq!(v.get_incident_edge()?, 55);
    let v = output.vertices()[14];
    assert!(almost_equal(v.x(), 13.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 59);
    let v = output.vertices()[15];
    assert!(almost_equal(v.x(), 15.9180581, v.y(), 10.6939806));
    assert_eq!(v.get_incident_edge()?, 61);
    let v = output.vertices()[16];
    assert!(almost_equal(v.x(), 16.4642857, v.y(), 10.9285714));
    assert_eq!(v.get_incident_edge()?, 63);
    Ok(())
}

#[test]
fn sample_polygon_005() -> Result<(), BvError> {
    let output = {
        let input = r#"0
6
0 0 10 0
10 0 16 -6
16 -6 22 0
22 0 22 -12
22 -12 10 -12
10 -12 0 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(), 12);
    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_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());
    assert_eq!(output.vertices().len(), 11);
    assert_eq!(output.edges().len(), 44);
    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(), 10.0000000, v.y(), -12.0000000));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 10.0000000, v.y(), -0.0000000));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), 8.3751585, v.y(), -3.9227144));
    assert_eq!(v.get_incident_edge()?, 19);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), 16.0000000, v.y(), -6.0000000));
    assert_eq!(v.get_incident_edge()?, 25);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), 11.9498098, v.y(), -7.8370749));
    assert_eq!(v.get_incident_edge()?, 27);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), 13.5147186, v.y(), -8.4852814));
    assert_eq!(v.get_incident_edge()?, 29);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), 22.0000000, v.y(), -12.0000000));
    assert_eq!(v.get_incident_edge()?, 35);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), 18.4852814, v.y(), -8.4852814));
    assert_eq!(v.get_incident_edge()?, 37);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), 22.0000000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 41);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), 16.0000000, v.y(), 6.0000000));
    assert_eq!(v.get_incident_edge()?, 43);
    Ok(())
}

#[test]
fn sample_polygon_006() -> Result<(), BvError> {
    let output = {
        let input = r#"0
7
0 0 0 10
0 10 6 10
6 10 10 7
10 7 14 10
14 10 20 10
20 10 20 0
20 0 0 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(), 14);
    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());
    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_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());
    assert_eq!(output.vertices().len(), 14);
    assert_eq!(output.edges().len(), 54);
    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(), 10.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 6.0000000, v.y(), 10.0000000));
    assert_eq!(v.get_incident_edge()?, 17);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), 4.5000000, v.y(), 5.5000000));
    assert_eq!(v.get_incident_edge()?, 19);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), 4.8333333, v.y(), 4.8333333));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), 10.0000000, v.y(), 7.0000000));
    assert_eq!(v.get_incident_edge()?, 27);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), 7.6666667, v.y(), 3.8888889));
    assert_eq!(v.get_incident_edge()?, 29);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), 14.0000000, v.y(), 10.0000000));
    assert_eq!(v.get_incident_edge()?, 35);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), 12.3333333, v.y(), 3.8888889));
    assert_eq!(v.get_incident_edge()?, 37);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), 10.0000000, v.y(), 15.3333333));
    assert_eq!(v.get_incident_edge()?, 39);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), 20.0000000, v.y(), -0.0000000));
    assert_eq!(v.get_incident_edge()?, 45);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), 15.1666667, v.y(), 4.8333333));
    assert_eq!(v.get_incident_edge()?, 47);
    let v = output.vertices()[12];
    assert!(almost_equal(v.x(), 15.5000000, v.y(), 5.5000000));
    assert_eq!(v.get_incident_edge()?, 49);
    let v = output.vertices()[13];
    assert!(almost_equal(v.x(), 20.0000000, v.y(), 10.0000000));
    assert_eq!(v.get_incident_edge()?, 53);
    Ok(())
}

#[test]
fn sample_polygon_007() -> Result<(), BvError> {
    let output = {
        let input = r#"0
12
0 0 8 3
8 3 10 13
10 13 16 6
16 6 16 15
16 15 25 10
25 10 15 1
15 1 27 -1
27 -1 14 -4
14 -4 13 3
13 3 11 -5
11 -5 10 0
10 0 0 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(), 24);
    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_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_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_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_eq!(_cat, SourceCategory::Segment);
    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!(!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());
    assert_eq!(output.vertices().len(), 39);
    assert_eq!(output.edges().len(), 124);
    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(), 8.0000000, v.y(), 3.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), -5.3972466, v.y(), 14.3926577));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), 10.0000000, v.y(), -0.0000000));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), 10.0000000, v.y(), 13.0000000));
    assert_eq!(v.get_incident_edge()?, 25);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), 8.5440037, v.y(), 1.5493233));
    assert_eq!(v.get_incident_edge()?, 27);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), -8.1756757, v.y(), 16.6351351));
    assert_eq!(v.get_incident_edge()?, 29);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), 11.0000000, v.y(), -5.0000000));
    assert_eq!(v.get_incident_edge()?, 35);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), 4.9009805, v.y(), -6.2198039));
    assert_eq!(v.get_incident_edge()?, 37);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), 10.0000000, v.y(), 2.1666667));
    assert_eq!(v.get_incident_edge()?, 39);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), 11.1243311, v.y(), 0.2248662));
    assert_eq!(v.get_incident_edge()?, 41);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), 10.3499812, v.y(), 2.3999875));
    assert_eq!(v.get_incident_edge()?, 43);
    let v = output.vertices()[12];
    assert!(almost_equal(v.x(), 10.3796042, v.y(), 2.5240792));
    assert_eq!(v.get_incident_edge()?, 45);
    let v = output.vertices()[13];
    assert!(almost_equal(v.x(), 13.0000000, v.y(), 3.0000000));
    assert_eq!(v.get_incident_edge()?, 51);
    let v = output.vertices()[14];
    assert!(almost_equal(v.x(), 10.6203958, v.y(), 3.5949010));
    assert_eq!(v.get_incident_edge()?, 53);
    let v = output.vertices()[15];
    assert!(almost_equal(v.x(), 14.0000000, v.y(), -4.0000000));
    assert_eq!(v.get_incident_edge()?, 59);
    let v = output.vertices()[16];
    assert!(almost_equal(v.x(), 12.6287894, v.y(), -4.1958872));
    assert_eq!(v.get_incident_edge()?, 61);
    let v = output.vertices()[17];
    assert!(almost_equal(v.x(), 0.0000000, v.y(), -14.6000000));
    assert_eq!(v.get_incident_edge()?, 63);
    let v = output.vertices()[18];
    assert!(almost_equal(v.x(), 12.8181818, v.y(), -5.4545455));
    assert_eq!(v.get_incident_edge()?, 65);
    let v = output.vertices()[19];
    assert!(almost_equal(v.x(), 15.0000000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 73);
    let v = output.vertices()[20];
    assert!(almost_equal(v.x(), 11.8388155, v.y(), 5.9636818));
    assert_eq!(v.get_incident_edge()?, 75);
    let v = output.vertices()[21];
    assert!(almost_equal(v.x(), 14.2709180, v.y(), 1.8100911));
    assert_eq!(v.get_incident_edge()?, 77);
    let v = output.vertices()[22];
    assert!(almost_equal(v.x(), 16.0000000, v.y(), 6.0000000));
    assert_eq!(v.get_incident_edge()?, 83);
    let v = output.vertices()[23];
    assert!(almost_equal(v.x(), 12.6706833, v.y(), 15.0000000));
    assert_eq!(v.get_incident_edge()?, 87);
    let v = output.vertices()[24];
    assert!(almost_equal(v.x(), 16.0000000, v.y(), 15.0000000));
    assert_eq!(v.get_incident_edge()?, 91);
    let v = output.vertices()[25];
    assert!(almost_equal(v.x(), 12.5925926, v.y(), 15.2222222));
    assert_eq!(v.get_incident_edge()?, 93);
    let v = output.vertices()[26];
    assert!(almost_equal(v.x(), 14.7857588, v.y(), -0.2854474));
    assert_eq!(v.get_incident_edge()?, 95);
    let v = output.vertices()[27];
    assert!(almost_equal(v.x(), 14.3846154, v.y(), 4.6153846));
    assert_eq!(v.get_incident_edge()?, 97);
    let v = output.vertices()[28];
    assert!(almost_equal(v.x(), 14.7957019, v.y(), 3.2565288));
    assert_eq!(v.get_incident_edge()?, 99);
    let v = output.vertices()[29];
    assert!(almost_equal(v.x(), 14.9966711, v.y(), 4.0033289));
    assert_eq!(v.get_incident_edge()?, 101);
    let v = output.vertices()[30];
    assert!(almost_equal(v.x(), 15.8206765, v.y(), -1.3447128));
    assert_eq!(v.get_incident_edge()?, 103);
    let v = output.vertices()[31];
    assert!(almost_equal(v.x(), 17.8259859, v.y(), 6.0000000));
    assert_eq!(v.get_incident_edge()?, 105);
    let v = output.vertices()[32];
    assert!(almost_equal(v.x(), 19.3207627, v.y(), 9.3563158));
    assert_eq!(v.get_incident_edge()?, 107);
    let v = output.vertices()[33];
    assert!(almost_equal(v.x(), 25.0000000, v.y(), 10.0000000));
    assert_eq!(v.get_incident_edge()?, 111);
    let v = output.vertices()[34];
    assert!(almost_equal(v.x(), 27.0000000, v.y(), -1.0000000));
    assert_eq!(v.get_incident_edge()?, 115);
    let v = output.vertices()[35];
    assert!(almost_equal(v.x(), 27.9636000, v.y(), 4.7816000));
    assert_eq!(v.get_incident_edge()?, 117);
    let v = output.vertices()[36];
    assert!(almost_equal(v.x(), 17.7500000, v.y(), -20.2500000));
    assert_eq!(v.get_incident_edge()?, 119);
    let v = output.vertices()[37];
    assert!(almost_equal(v.x(), 29.3945312, v.y(), 5.1171875));
    assert_eq!(v.get_incident_edge()?, 121);
    let v = output.vertices()[38];
    assert!(almost_equal(v.x(), 129.0000000, v.y(), -443.0000000));
    assert_eq!(v.get_incident_edge()?, 123);
    Ok(())
}

#[test]
fn sample_polygon_008() -> Result<(), BvError> {
    let output = {
        let input = r#"0
10
0 0 1 8
1 8 10 7
10 7 20 10
20 10 25 9
25 9 28 5
28 5 23 -2
23 -2 24 -7
24 -7 13 -9
13 -9 10 -3
10 -3 0 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(), 20);
    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_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_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_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_eq!(_cat, SourceCategory::Segment);
    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!(!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());
    assert_eq!(output.vertices().len(), 26);
    assert_eq!(output.edges().len(), 90);
    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(), 1.0000000, v.y(), 8.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 4.8287081, v.y(), 3.1463387));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), 10.0000000, v.y(), -3.0000000));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), 10.0000000, v.y(), 7.0000000));
    assert_eq!(v.get_incident_edge()?, 25);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), 13.0000000, v.y(), -9.0000000));
    assert_eq!(v.get_incident_edge()?, 31);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), 9.4667833, v.y(), 2.2010493));
    assert_eq!(v.get_incident_edge()?, 33);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), -0.8865536, v.y(), -15.9432768));
    assert_eq!(v.get_incident_edge()?, 35);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), 11.5000000, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 37);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), -7.3529412, v.y(), -24.5098039));
    assert_eq!(v.get_incident_edge()?, 39);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), 20.0000000, v.y(), 10.0000000));
    assert_eq!(v.get_incident_edge()?, 45);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), 23.0000000, v.y(), -2.0000000));
    assert_eq!(v.get_incident_edge()?, 53);
    let v = output.vertices()[12];
    assert!(almost_equal(v.x(), 16.5865390, v.y(), -1.8269220));
    assert_eq!(v.get_incident_edge()?, 55);
    let v = output.vertices()[13];
    assert!(almost_equal(v.x(), 18.0869499, v.y(), -2.9826100));
    assert_eq!(v.get_incident_edge()?, 57);
    let v = output.vertices()[14];
    assert!(almost_equal(v.x(), 16.2962963, v.y(), 0.1481481));
    assert_eq!(v.get_incident_edge()?, 59);
    let v = output.vertices()[15];
    assert!(almost_equal(v.x(), 16.2237557, v.y(), 1.0911758));
    assert_eq!(v.get_incident_edge()?, 61);
    let v = output.vertices()[16];
    assert!(almost_equal(v.x(), 24.0000000, v.y(), -7.0000000));
    assert_eq!(v.get_incident_edge()?, 65);
    let v = output.vertices()[17];
    assert!(almost_equal(v.x(), 17.3847094, v.y(), 2.0109218));
    assert_eq!(v.get_incident_edge()?, 67);
    let v = output.vertices()[18];
    assert!(almost_equal(v.x(), 25.0000000, v.y(), 9.0000000));
    assert_eq!(v.get_incident_edge()?, 73);
    let v = output.vertices()[19];
    assert!(almost_equal(v.x(), 20.2785677, v.y(), 4.0812532));
    assert_eq!(v.get_incident_edge()?, 75);
    let v = output.vertices()[20];
    assert!(almost_equal(v.x(), 22.4383624, v.y(), 4.9353385));
    assert_eq!(v.get_incident_edge()?, 77);
    let v = output.vertices()[21];
    assert!(almost_equal(v.x(), 28.0000000, v.y(), 5.0000000));
    assert_eq!(v.get_incident_edge()?, 81);
    let v = output.vertices()[22];
    assert!(almost_equal(v.x(), 35.5411601, v.y(), -4.6917680));
    assert_eq!(v.get_incident_edge()?, 83);
    let v = output.vertices()[23];
    assert!(almost_equal(v.x(), 5.9065134, v.y(), 52.1586207));
    assert_eq!(v.get_incident_edge()?, 85);
    let v = output.vertices()[24];
    assert!(almost_equal(v.x(), 5.2027027, v.y(), 59.3243243));
    assert_eq!(v.get_incident_edge()?, 87);
    let v = output.vertices()[25];
    assert!(almost_equal(v.x(), 45.5000000, v.y(), -7.5000000));
    assert_eq!(v.get_incident_edge()?, 89);
    Ok(())
}

#[test]
fn sample_polygon_009() -> Result<(), BvError> {
    let output = {
        let input = r#"0
4
0 0 0 10
0 10 30 10
30 10 30 0
30 0 0 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(), 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(), 6);
    assert_eq!(output.edges().len(), 26);
    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(), 10.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 5.0000000, v.y(), 5.0000000));
    assert_eq!(v.get_incident_edge()?, 13);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), 30.0000000, v.y(), -0.0000000));
    assert_eq!(v.get_incident_edge()?, 19);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), 25.0000000, v.y(), 5.0000000));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), 30.0000000, v.y(), 10.0000000));
    assert_eq!(v.get_incident_edge()?, 25);
    Ok(())
}

#[test]
fn sample_polygon_010() -> Result<(), BvError> {
    let output = {
        let input = r#"0
23
-12 4 -12 -4
-12 -4 -8 -4
-8 -4 -8 -1
-8 -1 -9 0
-9 0 -8 1
-8 1 -8 4
-8 4 -12 4
-4 4 -4 -4
-4 -4 0 -4
0 -4 0 4
0 4 -4 4
4 4 4 -4
4 -4 8 -4
8 -4 8 4
8 4 4 4
-4 -8 -8 -8
-8 -8 -8 -12
-8 -12 -4 -12
-4 -12 -4 -16
-4 -16 -8 -16
0 -8 2 -8
2 -8 4 -8
2 -8 2 -16
"#;

        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(), 48);
    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_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!(!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!(!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());
    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::Segment);
    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_eq!(_cat, SourceCategory::Segment);
    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_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!(!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_eq!(_cat, SourceCategory::Segment);
    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!(!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_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_eq!(_cat, SourceCategory::Segment);
    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!(!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());
    let cell = output.cells()[40];
    assert_eq!(cell.id(), 40);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[41];
    assert_eq!(cell.id(), 41);
    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()[42];
    assert_eq!(cell.id(), 42);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[43];
    assert_eq!(cell.id(), 43);
    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()[44];
    assert_eq!(cell.id(), 44);
    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()[45];
    assert_eq!(cell.id(), 45);
    let (_source_index, _cat) = cell.source_index_2();
    assert!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    let cell = output.cells()[46];
    assert_eq!(cell.id(), 46);
    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()[47];
    assert_eq!(cell.id(), 47);
    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(), 61);
    assert_eq!(output.edges().len(), 216);
    let v = output.vertices()[0];
    assert!(almost_equal(v.x(), -12.0000000, v.y(), -4.0000000));
    assert_eq!(v.get_incident_edge()?, 7);
    let v = output.vertices()[1];
    assert!(almost_equal(v.x(), -12.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), -9.0000000, v.y(), -0.0000000));
    assert_eq!(v.get_incident_edge()?, 19);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), -10.2426407, v.y(), -1.2426407));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), -10.2426407, v.y(), 1.2426407));
    assert_eq!(v.get_incident_edge()?, 23);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), -18.0000000, v.y(), -12.0000000));
    assert_eq!(v.get_incident_edge()?, 31);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), -12.0000000, v.y(), -8.0000000));
    assert_eq!(v.get_incident_edge()?, 35);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), -8.0000000, v.y(), -4.0000000));
    assert_eq!(v.get_incident_edge()?, 41);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), -10.0000000, v.y(), -2.0000000));
    assert_eq!(v.get_incident_edge()?, 43);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), -10.0000000, v.y(), -1.8284271));
    assert_eq!(v.get_incident_edge()?, 45);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), -8.0000000, v.y(), -1.0000000));
    assert_eq!(v.get_incident_edge()?, 49);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), -8.0000000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 55);
    let v = output.vertices()[12];
    assert!(almost_equal(v.x(), -10.0000000, v.y(), 1.8284271));
    assert_eq!(v.get_incident_edge()?, 57);
    let v = output.vertices()[13];
    assert!(almost_equal(v.x(), -10.0000000, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 59);
    let v = output.vertices()[14];
    assert!(almost_equal(v.x(), -8.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 63);
    let v = output.vertices()[15];
    assert!(almost_equal(v.x(), -8.0000000, v.y(), -12.0000000));
    assert_eq!(v.get_incident_edge()?, 69);
    let v = output.vertices()[16];
    assert!(almost_equal(v.x(), -8.0000000, v.y(), -8.0000000));
    assert_eq!(v.get_incident_edge()?, 73);
    let v = output.vertices()[17];
    assert!(almost_equal(v.x(), -22.0000000, v.y(), -14.0000000));
    assert_eq!(v.get_incident_edge()?, 75);
    let v = output.vertices()[18];
    assert!(almost_equal(v.x(), -8.0000000, v.y(), -14.0000000));
    assert_eq!(v.get_incident_edge()?, 77);
    let v = output.vertices()[19];
    assert!(almost_equal(v.x(), -8.0000000, v.y(), -6.0000000));
    assert_eq!(v.get_incident_edge()?, 79);
    let v = output.vertices()[20];
    assert!(almost_equal(v.x(), -7.0000000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 81);
    let v = output.vertices()[21];
    assert!(almost_equal(v.x(), -6.0000000, v.y(), -10.0000000));
    assert_eq!(v.get_incident_edge()?, 83);
    let v = output.vertices()[22];
    assert!(almost_equal(v.x(), -4.0000000, v.y(), -16.0000000));
    assert_eq!(v.get_incident_edge()?, 89);
    let v = output.vertices()[23];
    assert!(almost_equal(v.x(), -6.0000000, v.y(), -14.0000000));
    assert_eq!(v.get_incident_edge()?, 91);
    let v = output.vertices()[24];
    assert!(almost_equal(v.x(), -4.0000000, v.y(), -12.0000000));
    assert_eq!(v.get_incident_edge()?, 95);
    let v = output.vertices()[25];
    assert!(almost_equal(v.x(), -6.0000000, v.y(), -4.0000000));
    assert_eq!(v.get_incident_edge()?, 103);
    let v = output.vertices()[26];
    assert!(almost_equal(v.x(), -6.0000000, v.y(), -1.0000000));
    assert_eq!(v.get_incident_edge()?, 105);
    let v = output.vertices()[27];
    assert!(almost_equal(v.x(), -6.1250000, v.y(), 0.0000000));
    assert_eq!(v.get_incident_edge()?, 107);
    let v = output.vertices()[28];
    assert!(almost_equal(v.x(), -6.0000000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 109);
    let v = output.vertices()[29];
    assert!(almost_equal(v.x(), -6.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 113);
    let v = output.vertices()[30];
    assert!(almost_equal(v.x(), -4.0000000, v.y(), -4.0000000));
    assert_eq!(v.get_incident_edge()?, 117);
    let v = output.vertices()[31];
    assert!(almost_equal(v.x(), -4.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 121);
    let v = output.vertices()[32];
    assert!(almost_equal(v.x(), -6.0000000, v.y(), -5.5000000));
    assert_eq!(v.get_incident_edge()?, 123);
    let v = output.vertices()[33];
    assert!(almost_equal(v.x(), -4.0000000, v.y(), -10.0000000));
    assert_eq!(v.get_incident_edge()?, 125);
    let v = output.vertices()[34];
    assert!(almost_equal(v.x(), -4.0000000, v.y(), -6.0000000));
    assert_eq!(v.get_incident_edge()?, 127);
    let v = output.vertices()[35];
    assert!(almost_equal(v.x(), -0.0000000, v.y(), -4.0000000));
    assert_eq!(v.get_incident_edge()?, 135);
    let v = output.vertices()[36];
    assert!(almost_equal(v.x(), -2.0000000, v.y(), -2.0000000));
    assert_eq!(v.get_incident_edge()?, 137);
    let v = output.vertices()[37];
    assert!(almost_equal(v.x(), -2.0000000, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 139);
    let v = output.vertices()[38];
    assert!(almost_equal(v.x(), 0.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 143);
    let v = output.vertices()[39];
    assert!(almost_equal(v.x(), -2.0000000, v.y(), -6.5000000));
    assert_eq!(v.get_incident_edge()?, 147);
    let v = output.vertices()[40];
    assert!(almost_equal(v.x(), -2.0000000, v.y(), -10.0000000));
    assert_eq!(v.get_incident_edge()?, 149);
    let v = output.vertices()[41];
    assert!(almost_equal(v.x(), 0.0000000, v.y(), -6.0000000));
    assert_eq!(v.get_incident_edge()?, 151);
    let v = output.vertices()[42];
    assert!(almost_equal(v.x(), -1.0000000, v.y(), -16.0000000));
    assert_eq!(v.get_incident_edge()?, 157);
    let v = output.vertices()[43];
    assert!(almost_equal(v.x(), -1.0000000, v.y(), -12.0000000));
    assert_eq!(v.get_incident_edge()?, 159);
    let v = output.vertices()[44];
    assert!(almost_equal(v.x(), -1.1010205, v.y(), -10.8989795));
    assert_eq!(v.get_incident_edge()?, 161);
    let v = output.vertices()[45];
    assert!(almost_equal(v.x(), 0.0000000, v.y(), -10.0000000));
    assert_eq!(v.get_incident_edge()?, 163);
    let v = output.vertices()[46];
    assert!(almost_equal(v.x(), 2.0000000, v.y(), -8.0000000));
    assert_eq!(v.get_incident_edge()?, 169);
    let v = output.vertices()[47];
    assert!(almost_equal(v.x(), 2.0000000, v.y(), -4.0000000));
    assert_eq!(v.get_incident_edge()?, 177);
    let v = output.vertices()[48];
    assert!(almost_equal(v.x(), 2.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 181);
    let v = output.vertices()[49];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), -4.0000000));
    assert_eq!(v.get_incident_edge()?, 185);
    let v = output.vertices()[50];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 189);
    let v = output.vertices()[51];
    assert!(almost_equal(v.x(), 2.0000000, v.y(), -5.5000000));
    assert_eq!(v.get_incident_edge()?, 191);
    let v = output.vertices()[52];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), -10.0000000));
    assert_eq!(v.get_incident_edge()?, 193);
    let v = output.vertices()[53];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), -6.0000000));
    assert_eq!(v.get_incident_edge()?, 195);
    let v = output.vertices()[54];
    assert!(almost_equal(v.x(), 8.0000000, v.y(), -4.0000000));
    assert_eq!(v.get_incident_edge()?, 201);
    let v = output.vertices()[55];
    assert!(almost_equal(v.x(), 6.0000000, v.y(), -2.0000000));
    assert_eq!(v.get_incident_edge()?, 203);
    let v = output.vertices()[56];
    assert!(almost_equal(v.x(), 6.0000000, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 205);
    let v = output.vertices()[57];
    assert!(almost_equal(v.x(), 8.0000000, v.y(), 4.0000000));
    assert_eq!(v.get_incident_edge()?, 209);
    let v = output.vertices()[58];
    assert!(almost_equal(v.x(), 8.0000000, v.y(), -8.0000000));
    assert_eq!(v.get_incident_edge()?, 211);
    let v = output.vertices()[59];
    assert!(almost_equal(v.x(), 14.8989795, v.y(), -14.8989795));
    assert_eq!(v.get_incident_edge()?, 213);
    let v = output.vertices()[60];
    assert!(almost_equal(v.x(), 17.0000000, v.y(), -16.0000000));
    assert_eq!(v.get_incident_edge()?, 215);
    Ok(())
}

#[test]
fn sample_polygon_011() -> Result<(), BvError> {
    let output = {
        let input = r#"0
9
0 0 1 10
1 10 4 9
4 9 4 2
4 2 0 0
5 5 6 8
6 8 10 10
10 10 9 1
9 1 6 2
6 2 5 5
"#;

        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_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_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_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(), 28);
    assert_eq!(output.edges().len(), 90);
    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(), 1.0000000, v.y(), 10.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(), 2.1614009, v.y(), 3.1363167));
    assert_eq!(v.get_incident_edge()?, 19);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), 2.3962019, v.y(), 7.8440477));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), 4.0000000, v.y(), 9.0000000));
    assert_eq!(v.get_incident_edge()?, 25);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), 5.0000000, v.y(), 5.0000000));
    assert_eq!(v.get_incident_edge()?, 33);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), 4.5131670, v.y(), 4.8377223));
    assert_eq!(v.get_incident_edge()?, 35);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), 4.5131670, v.y(), 5.1622777));
    assert_eq!(v.get_incident_edge()?, 37);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), 4.9736660, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 39);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), 6.0000000, v.y(), 2.0000000));
    assert_eq!(v.get_incident_edge()?, 47);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), 6.0000000, v.y(), 8.0000000));
    assert_eq!(v.get_incident_edge()?, 51);
    let v = output.vertices()[12];
    assert!(almost_equal(v.x(), 5.0263340, v.y(), 8.3245553));
    assert_eq!(v.get_incident_edge()?, 53);
    let v = output.vertices()[13];
    assert!(almost_equal(v.x(), 5.0000000, v.y(), 1.6666667));
    assert_eq!(v.get_incident_edge()?, 55);
    let v = output.vertices()[14];
    assert!(almost_equal(v.x(), 5.2500000, v.y(), 9.0000000));
    assert_eq!(v.get_incident_edge()?, 57);
    let v = output.vertices()[15];
    assert!(almost_equal(v.x(), 5.3750000, v.y(), 9.2500000));
    assert_eq!(v.get_incident_edge()?, 59);
    let v = output.vertices()[16];
    assert!(almost_equal(v.x(), 5.0000000, v.y(), -0.0000000));
    assert_eq!(v.get_incident_edge()?, 61);
    let v = output.vertices()[17];
    assert!(almost_equal(v.x(), 5.0343146, v.y(), -0.8970563));
    assert_eq!(v.get_incident_edge()?, 63);
    let v = output.vertices()[18];
    assert!(almost_equal(v.x(), 9.0000000, v.y(), 1.0000000));
    assert_eq!(v.get_incident_edge()?, 69);
    let v = output.vertices()[19];
    assert!(almost_equal(v.x(), 7.4392737, v.y(), 3.4392737));
    assert_eq!(v.get_incident_edge()?, 71);
    let v = output.vertices()[20];
    assert!(almost_equal(v.x(), 7.2739298, v.y(), 5.0000000));
    assert_eq!(v.get_incident_edge()?, 73);
    let v = output.vertices()[21];
    assert!(almost_equal(v.x(), 7.6235670, v.y(), 6.5918878));
    assert_eq!(v.get_incident_edge()?, 75);
    let v = output.vertices()[22];
    assert!(almost_equal(v.x(), 10.0000000, v.y(), 10.0000000));
    assert_eq!(v.get_incident_edge()?, 79);
    let v = output.vertices()[23];
    assert!(almost_equal(v.x(), 5.9313708, v.y(), 14.7941125));
    assert_eq!(v.get_incident_edge()?, 81);
    let v = output.vertices()[24];
    assert!(almost_equal(v.x(), 5.6544156, v.y(), 18.6911688));
    assert_eq!(v.get_incident_edge()?, 83);
    let v = output.vertices()[25];
    assert!(almost_equal(v.x(), 5.6201010, v.y(), -9.1396970));
    assert_eq!(v.get_incident_edge()?, 85);
    let v = output.vertices()[26];
    assert!(almost_equal(v.x(), 5.8571429, v.y(), -11.7142857));
    assert_eq!(v.get_incident_edge()?, 87);
    let v = output.vertices()[27];
    assert!(almost_equal(v.x(), 5.5000000, v.y(), 23.5000000));
    assert_eq!(v.get_incident_edge()?, 89);
    Ok(())
}

#[test]
fn sample_polygon_012() -> Result<(), BvError> {
    let output = {
        let input = r#"0
12
0 0 100 0
100 0 100 100
100 100 0 100
0 100 0 0
15 15 60 20
60 20 87 23
60 20 57 47
15 85 30 80
30 80 25 65
30 80 60 70
60 70 75 65
60 70 65 85
"#;

        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(), 26);
    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!(!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_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_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_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_eq!(_cat, SourceCategory::Segment);
    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!(!cell.is_degenerate());
    assert!(cell.contains_point());
    assert!(!cell.contains_segment());
    assert_eq!(output.vertices().len(), 35);
    assert_eq!(output.edges().len(), 120);
    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(), 100.0000000));
    assert_eq!(v.get_incident_edge()?, 11);
    let v = output.vertices()[2];
    assert!(almost_equal(v.x(), 8.7867966, v.y(), 8.7867966));
    assert_eq!(v.get_incident_edge()?, 21);
    let v = output.vertices()[3];
    assert!(almost_equal(v.x(), 8.7867966, v.y(), 91.2132034));
    assert_eq!(v.get_incident_edge()?, 23);
    let v = output.vertices()[4];
    assert!(almost_equal(v.x(), 11.3962039, v.y(), 74.1886117));
    assert_eq!(v.get_incident_edge()?, 25);
    let v = output.vertices()[5];
    assert!(almost_equal(v.x(), 15.8307771, v.y(), 7.5230064));
    assert_eq!(v.get_incident_edge()?, 27);
    let v = output.vertices()[6];
    assert!(almost_equal(v.x(), 17.4341649, v.y(), 92.3024947));
    assert_eq!(v.get_incident_edge()?, 33);
    let v = output.vertices()[7];
    assert!(almost_equal(v.x(), 12.8291755, v.y(), 69.0569415));
    assert_eq!(v.get_incident_edge()?, 35);
    let v = output.vertices()[8];
    assert!(almost_equal(v.x(), 13.2455532, v.y(), 71.6227766));
    assert_eq!(v.get_incident_edge()?, 37);
    let v = output.vertices()[9];
    assert!(almost_equal(v.x(), 13.5082620, v.y(), 28.4256419));
    assert_eq!(v.get_incident_edge()?, 39);
    let v = output.vertices()[10];
    assert!(almost_equal(v.x(), 30.0000000, v.y(), 80.0000000));
    assert_eq!(v.get_incident_edge()?, 45);
    let v = output.vertices()[11];
    assert!(almost_equal(v.x(), 33.2455532, v.y(), 89.7366596));
    assert_eq!(v.get_incident_edge()?, 47);
    let v = output.vertices()[12];
    assert!(almost_equal(v.x(), 24.4059656, v.y(), 40.6012648));
    assert_eq!(v.get_incident_edge()?, 49);
    let v = output.vertices()[13];
    assert!(almost_equal(v.x(), 40.0000000, v.y(), 60.0000000));
    assert_eq!(v.get_incident_edge()?, 51);
    let v = output.vertices()[14];
    assert!(almost_equal(v.x(), 34.5333333, v.y(), 44.5037037));
    assert_eq!(v.get_incident_edge()?, 57);
    let v = output.vertices()[15];
    assert!(almost_equal(v.x(), 32.8588176, v.y(), 41.7129459));
    assert_eq!(v.get_incident_edge()?, 59);
    let v = output.vertices()[16];
    assert!(almost_equal(v.x(), 41.4538727, v.y(), 56.8068847));
    assert_eq!(v.get_incident_edge()?, 61);
    let v = output.vertices()[17];
    assert!(almost_equal(v.x(), 60.0000000, v.y(), 20.0000000));
    assert_eq!(v.get_incident_edge()?, 69);
    let v = output.vertices()[18];
    assert!(almost_equal(v.x(), 60.0000000, v.y(), 70.0000000));
    assert_eq!(v.get_incident_edge()?, 75);
    let v = output.vertices()[19];
    assert!(almost_equal(v.x(), 51.6227766, v.y(), 86.7544468));
    assert_eq!(v.get_incident_edge()?, 77);
    let v = output.vertices()[20];
    assert!(almost_equal(v.x(), 54.1886117, v.y(), 88.6037961));
    assert_eq!(v.get_incident_edge()?, 81);
    let v = output.vertices()[21];
    assert!(almost_equal(v.x(), 56.2638889, v.y(), 58.7916667));
    assert_eq!(v.get_incident_edge()?, 83);
    let v = output.vertices()[22];
    assert!(almost_equal(v.x(), 61.1077028, v.y(), 10.0306751));
    assert_eq!(v.get_incident_edge()?, 85);
    let v = output.vertices()[23];
    assert!(almost_equal(v.x(), 70.5000000, v.y(), 51.5000000));
    assert_eq!(v.get_incident_edge()?, 89);
    let v = output.vertices()[24];
    assert!(almost_equal(v.x(), 73.2000000, v.y(), 48.8000000));
    assert_eq!(v.get_incident_edge()?, 93);
    let v = output.vertices()[25];
    assert!(almost_equal(v.x(), 80.0000000, v.y(), 80.0000000));
    assert_eq!(v.get_incident_edge()?, 95);
    let v = output.vertices()[26];
    assert!(almost_equal(v.x(), 88.2738582, v.y(), 11.5352764));
    assert_eq!(v.get_incident_edge()?, 97);
    let v = output.vertices()[27];
    assert!(almost_equal(v.x(), 100.0000000, v.y(), -0.0000000));
    assert_eq!(v.get_incident_edge()?, 103);
    let v = output.vertices()[28];
    assert!(almost_equal(v.x(), 88.4540385, v.y(), 11.5459615));
    assert_eq!(v.get_incident_edge()?, 105);
    let v = output.vertices()[29];
    assert!(almost_equal(v.x(), 85.3861728, v.y(), 37.5244452));
    assert_eq!(v.get_incident_edge()?, 107);
    let v = output.vertices()[30];
    assert!(almost_equal(v.x(), 78.7624025, v.y(), 43.4530031));
    assert_eq!(v.get_incident_edge()?, 109);
    let v = output.vertices()[31];
    assert!(almost_equal(v.x(), 78.7288796, v.y(), 44.0582709));
    assert_eq!(v.get_incident_edge()?, 111);
    let v = output.vertices()[32];
    assert!(almost_equal(v.x(), 82.2875656, v.y(), 81.1437828));
    assert_eq!(v.get_incident_edge()?, 113);
    let v = output.vertices()[33];
    assert!(almost_equal(v.x(), 82.4037035, v.y(), 82.4037035));
    assert_eq!(v.get_incident_edge()?, 115);
    let v = output.vertices()[34];
    assert!(almost_equal(v.x(), 100.0000000, v.y(), 100.0000000));
    assert_eq!(v.get_incident_edge()?, 119);
    Ok(())
}
