File: voronoi_structures_test.cpp

package info (click to toggle)
boost1.90 1.90.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 593,120 kB
  • sloc: cpp: 4,190,908; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,774; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (150 lines) | stat: -rw-r--r-- 3,962 bytes parent folder | download | duplicates (15)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Boost.Polygon library voronoi_structures_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/detail/voronoi_structures.hpp>
#include <boost/polygon/voronoi_geometry_type.hpp>
#include <functional>
#include <vector>

using namespace boost::polygon::detail;
using namespace boost::polygon;

typedef point_2d<int> point_type;
typedef site_event<int> site_type;
typedef circle_event<int> circle_type;
typedef ordered_queue<int, std::greater<int> > ordered_queue_type;
typedef beach_line_node_key<int> node_key_type;
typedef beach_line_node_data<int, int> node_data_type;

void point_2d_test1()
{
  point_type p(1, 2);
  BOOST_TEST_EQ(1, p.x());
  BOOST_TEST_EQ(2, p.y());
  p.x(3);
  BOOST_TEST_EQ(3, p.x());
  p.y(4);
  BOOST_TEST_EQ(4, p.y());
}

void site_event_test1()
{
  site_type s(1, 2);
  s.sorted_index(1);
  s.initial_index(2);
  s.source_category(SOURCE_CATEGORY_SEGMENT_START_POINT);
  BOOST_TEST_EQ(1, s.x0());
  BOOST_TEST_EQ(1, s.x1());
  BOOST_TEST_EQ(2, s.y0());
  BOOST_TEST_EQ(2, s.y1());
  BOOST_TEST(s.is_point());
  BOOST_TEST(!s.is_segment());
  BOOST_TEST(!s.is_inverse());
  BOOST_TEST_EQ(1, s.sorted_index());
  BOOST_TEST_EQ(2, s.initial_index());
  BOOST_TEST_EQ(SOURCE_CATEGORY_SEGMENT_START_POINT, s.source_category());
}

void site_event_test2()
{
  site_type s(1, 2, 3, 4);
  s.sorted_index(1);
  s.initial_index(2);
  s.source_category(SOURCE_CATEGORY_INITIAL_SEGMENT);
  BOOST_TEST_EQ(1, s.x0());
  BOOST_TEST_EQ(2, s.y0());
  BOOST_TEST_EQ(3, s.x1());
  BOOST_TEST_EQ(4, s.y1());
  BOOST_TEST(!s.is_point());
  BOOST_TEST(s.is_segment());
  BOOST_TEST(!s.is_inverse());
  BOOST_TEST_EQ(SOURCE_CATEGORY_INITIAL_SEGMENT, s.source_category());

  s.inverse();
  BOOST_TEST_EQ(3, s.x0());
  BOOST_TEST_EQ(4, s.y0());
  BOOST_TEST_EQ(1, s.x1());
  BOOST_TEST_EQ(2, s.y1());
  BOOST_TEST(s.is_inverse());
  BOOST_TEST_EQ(SOURCE_CATEGORY_INITIAL_SEGMENT, s.source_category());
}

void circle_event_test()
{
  circle_type c(0, 1, 2);
  BOOST_TEST_EQ(0, c.x());
  BOOST_TEST_EQ(1, c.y());
  BOOST_TEST_EQ(2, c.lower_x());
  BOOST_TEST_EQ(1, c.lower_y());
  BOOST_TEST(c.is_active());
  c.x(3);
  c.y(4);
  c.lower_x(5);
  BOOST_TEST_EQ(3, c.x());
  BOOST_TEST_EQ(4, c.y());
  BOOST_TEST_EQ(5, c.lower_x());
  BOOST_TEST_EQ(4, c.lower_y());
  c.deactivate();
  BOOST_TEST(!c.is_active());
}

void ordered_queue_test()
{
  ordered_queue_type q;
  BOOST_TEST(q.empty());
  std::vector<int*> vi;
  for (int i = 0; i < 20; ++i)
    vi.push_back(&q.push(i));
  for (int i = 0; i < 20; ++i)
    *vi[i] <<= 1;
  BOOST_TEST(!q.empty());
  for (int i = 0; i < 20; ++i, q.pop())
    BOOST_TEST_EQ(i << 1, q.top());
  BOOST_TEST(q.empty());
}

void beach_line_node_key_test()
{
  node_key_type key(1);
  BOOST_TEST_EQ(1, key.left_site());
  BOOST_TEST_EQ(1, key.right_site());
  key.left_site(2);
  BOOST_TEST_EQ(2, key.left_site());
  BOOST_TEST_EQ(1, key.right_site());
  key.right_site(3);
  BOOST_TEST_EQ(2, key.left_site());
  BOOST_TEST_EQ(3, key.right_site());
}

void beach_line_node_data_test()
{
  node_data_type node_data(NULL);
  BOOST_TEST(node_data.edge() == NULL);
  BOOST_TEST(node_data.circle_event() == NULL);
  int data = 4;
  node_data.circle_event(&data);
  BOOST_TEST(node_data.edge() == NULL);
  BOOST_TEST(node_data.circle_event() == &data);
  node_data.edge(&data);
  BOOST_TEST(node_data.edge() == &data);
  BOOST_TEST(node_data.circle_event() == &data);
}

int main()
{
    point_2d_test1();
    site_event_test1();
    site_event_test2();
    circle_event_test();
    ordered_queue_test();
    beach_line_node_key_test();
    beach_line_node_data_test();
    return boost::report_errors();
}