File: voronoi_diagram_test.cpp

package info (click to toggle)
boost1.90 1.90.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 593,156 kB
  • sloc: cpp: 4,190,642; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,776; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (125 lines) | stat: -rw-r--r-- 3,550 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Boost.Polygon library voronoi_diagram_test.cpp file

//          Copyright Andrii Sydorchuk 2010-2012.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

// See http://www.boost.org for updates, documentation, and revision history.

#include <boost/core/lightweight_test.hpp>
#include <boost/polygon/voronoi_diagram.hpp>
#include <boost/polygon/voronoi_geometry_type.hpp>

using namespace boost::polygon;

typedef voronoi_cell<double> voronoi_cell_type;
typedef voronoi_vertex<double> voronoi_vertex_type;
typedef voronoi_edge<double> voronoi_edge_type;
typedef voronoi_diagram<double> voronoi_diagram_type;

void voronoi_cell_test()
{
  voronoi_cell_type cell(1, SOURCE_CATEGORY_INITIAL_SEGMENT);
  cell.color(27);
  BOOST_TEST(!cell.contains_point());
  BOOST_TEST(cell.contains_segment());
  BOOST_TEST(cell.is_degenerate());
  BOOST_TEST(cell.source_index() == 1);
  BOOST_TEST(cell.source_category() == SOURCE_CATEGORY_INITIAL_SEGMENT);
  BOOST_TEST(cell.incident_edge() == NULL);
  BOOST_TEST(cell.color() == 27);

  voronoi_edge_type edge(true, true);
  cell.incident_edge(&edge);
  BOOST_TEST(!cell.is_degenerate());
  BOOST_TEST(cell.incident_edge() == &edge);
}

void voronoi_vertex_test()
{
  voronoi_vertex_type vertex(1, 2);
  vertex.color(27);
  BOOST_TEST(vertex.is_degenerate());
  BOOST_TEST(vertex.x() == 1);
  BOOST_TEST(vertex.y() == 2);
  BOOST_TEST(vertex.incident_edge() == NULL);
  BOOST_TEST(vertex.color() == 27);

  voronoi_edge_type edge(true, true);
  vertex.incident_edge(&edge);
  BOOST_TEST(!vertex.is_degenerate());
  BOOST_TEST(vertex.incident_edge() == &edge);
}

void voronoi_edge_test()
{
  voronoi_edge_type edge1(false, false);
  edge1.color(13);
  BOOST_TEST(!edge1.is_primary());
  BOOST_TEST(edge1.is_secondary());
  BOOST_TEST(!edge1.is_linear());
  BOOST_TEST(edge1.is_curved());
  BOOST_TEST(!edge1.is_finite());
  BOOST_TEST(edge1.is_infinite());
  BOOST_TEST(edge1.color() == 13);

  voronoi_edge_type edge2(true, true);
  edge2.color(14);
  BOOST_TEST(edge2.is_primary());
  BOOST_TEST(!edge2.is_secondary());
  BOOST_TEST(edge2.is_linear());
  BOOST_TEST(!edge2.is_curved());
  BOOST_TEST(!edge2.is_finite());
  BOOST_TEST(edge2.is_infinite());
  BOOST_TEST(edge2.color() == 14);

  edge1.twin(&edge2);
  edge2.twin(&edge1);
  BOOST_TEST(edge1.twin() == &edge2);
  BOOST_TEST(edge2.twin() == &edge1);

  edge1.next(&edge2);
  edge1.prev(&edge2);
  edge2.next(&edge1);
  edge2.prev(&edge1);
  BOOST_TEST(edge1.next() == &edge2);
  BOOST_TEST(edge1.prev() == &edge2);
  BOOST_TEST(edge1.rot_next() == &edge1);
  BOOST_TEST(edge1.rot_prev() == &edge1);

  voronoi_cell_type cell(1, SOURCE_CATEGORY_INITIAL_SEGMENT);
  edge1.cell(&cell);
  BOOST_TEST(edge1.cell() == &cell);

  voronoi_vertex_type vertex0(1, 2);
  edge1.vertex0(&vertex0);
  BOOST_TEST(edge1.vertex0() == &vertex0);
  BOOST_TEST(edge2.vertex1() == &vertex0);

  voronoi_vertex_type vertex1(2, 1);
  edge2.vertex0(&vertex1);
  BOOST_TEST(edge1.vertex1() == &vertex1);
  BOOST_TEST(edge2.vertex0() == &vertex1);

  BOOST_TEST(edge1.is_finite());
  BOOST_TEST(edge2.is_finite());
}

void voronoi_diagram_test()
{
  voronoi_diagram_type vd;
  BOOST_TEST(vd.num_cells() == 0);
  BOOST_TEST(vd.num_vertices() == 0);
  BOOST_TEST(vd.num_edges() == 0);
  vd.clear();
}

int main()
{
    voronoi_cell_test();
    voronoi_vertex_test();
    voronoi_edge_test();
    voronoi_diagram_test();
    return boost::report_errors();
}