]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Polygon library voronoi_structures_test.cpp file |
2 | ||
3 | // Copyright Andrii Sydorchuk 2010-2012. | |
4 | // Distributed under the Boost Software License, Version 1.0. | |
5 | // (See accompanying file LICENSE_1_0.txt or copy at | |
6 | // http://www.boost.org/LICENSE_1_0.txt) | |
7 | ||
8 | // See http://www.boost.org for updates, documentation, and revision history. | |
9 | ||
92f5a8d4 TL |
10 | #include <boost/core/lightweight_test.hpp> |
11 | #include <boost/polygon/detail/voronoi_structures.hpp> | |
12 | #include <boost/polygon/voronoi_geometry_type.hpp> | |
7c673cae FG |
13 | #include <functional> |
14 | #include <vector> | |
15 | ||
7c673cae | 16 | using namespace boost::polygon::detail; |
7c673cae FG |
17 | using namespace boost::polygon; |
18 | ||
19 | typedef point_2d<int> point_type; | |
20 | typedef site_event<int> site_type; | |
21 | typedef circle_event<int> circle_type; | |
22 | typedef ordered_queue<int, std::greater<int> > ordered_queue_type; | |
23 | typedef beach_line_node_key<int> node_key_type; | |
24 | typedef beach_line_node_data<int, int> node_data_type; | |
25 | ||
92f5a8d4 TL |
26 | void point_2d_test1() |
27 | { | |
7c673cae | 28 | point_type p(1, 2); |
92f5a8d4 TL |
29 | BOOST_TEST_EQ(1, p.x()); |
30 | BOOST_TEST_EQ(2, p.y()); | |
7c673cae | 31 | p.x(3); |
92f5a8d4 | 32 | BOOST_TEST_EQ(3, p.x()); |
7c673cae | 33 | p.y(4); |
92f5a8d4 | 34 | BOOST_TEST_EQ(4, p.y()); |
7c673cae FG |
35 | } |
36 | ||
92f5a8d4 TL |
37 | void site_event_test1() |
38 | { | |
7c673cae FG |
39 | site_type s(1, 2); |
40 | s.sorted_index(1); | |
41 | s.initial_index(2); | |
42 | s.source_category(SOURCE_CATEGORY_SEGMENT_START_POINT); | |
92f5a8d4 TL |
43 | BOOST_TEST_EQ(1, s.x0()); |
44 | BOOST_TEST_EQ(1, s.x1()); | |
45 | BOOST_TEST_EQ(2, s.y0()); | |
46 | BOOST_TEST_EQ(2, s.y1()); | |
47 | BOOST_TEST(s.is_point()); | |
48 | BOOST_TEST(!s.is_segment()); | |
49 | BOOST_TEST(!s.is_inverse()); | |
50 | BOOST_TEST_EQ(1, s.sorted_index()); | |
51 | BOOST_TEST_EQ(2, s.initial_index()); | |
52 | BOOST_TEST_EQ(SOURCE_CATEGORY_SEGMENT_START_POINT, s.source_category()); | |
7c673cae FG |
53 | } |
54 | ||
92f5a8d4 TL |
55 | void site_event_test2() |
56 | { | |
7c673cae FG |
57 | site_type s(1, 2, 3, 4); |
58 | s.sorted_index(1); | |
59 | s.initial_index(2); | |
60 | s.source_category(SOURCE_CATEGORY_INITIAL_SEGMENT); | |
92f5a8d4 TL |
61 | BOOST_TEST_EQ(1, s.x0()); |
62 | BOOST_TEST_EQ(2, s.y0()); | |
63 | BOOST_TEST_EQ(3, s.x1()); | |
64 | BOOST_TEST_EQ(4, s.y1()); | |
65 | BOOST_TEST(!s.is_point()); | |
66 | BOOST_TEST(s.is_segment()); | |
67 | BOOST_TEST(!s.is_inverse()); | |
68 | BOOST_TEST_EQ(SOURCE_CATEGORY_INITIAL_SEGMENT, s.source_category()); | |
7c673cae FG |
69 | |
70 | s.inverse(); | |
92f5a8d4 TL |
71 | BOOST_TEST_EQ(3, s.x0()); |
72 | BOOST_TEST_EQ(4, s.y0()); | |
73 | BOOST_TEST_EQ(1, s.x1()); | |
74 | BOOST_TEST_EQ(2, s.y1()); | |
75 | BOOST_TEST(s.is_inverse()); | |
76 | BOOST_TEST_EQ(SOURCE_CATEGORY_INITIAL_SEGMENT, s.source_category()); | |
7c673cae FG |
77 | } |
78 | ||
92f5a8d4 TL |
79 | void circle_event_test() |
80 | { | |
7c673cae | 81 | circle_type c(0, 1, 2); |
92f5a8d4 TL |
82 | BOOST_TEST_EQ(0, c.x()); |
83 | BOOST_TEST_EQ(1, c.y()); | |
84 | BOOST_TEST_EQ(2, c.lower_x()); | |
85 | BOOST_TEST_EQ(1, c.lower_y()); | |
86 | BOOST_TEST(c.is_active()); | |
7c673cae FG |
87 | c.x(3); |
88 | c.y(4); | |
89 | c.lower_x(5); | |
92f5a8d4 TL |
90 | BOOST_TEST_EQ(3, c.x()); |
91 | BOOST_TEST_EQ(4, c.y()); | |
92 | BOOST_TEST_EQ(5, c.lower_x()); | |
93 | BOOST_TEST_EQ(4, c.lower_y()); | |
7c673cae | 94 | c.deactivate(); |
92f5a8d4 | 95 | BOOST_TEST(!c.is_active()); |
7c673cae FG |
96 | } |
97 | ||
92f5a8d4 TL |
98 | void ordered_queue_test() |
99 | { | |
7c673cae | 100 | ordered_queue_type q; |
92f5a8d4 | 101 | BOOST_TEST(q.empty()); |
7c673cae FG |
102 | std::vector<int*> vi; |
103 | for (int i = 0; i < 20; ++i) | |
104 | vi.push_back(&q.push(i)); | |
105 | for (int i = 0; i < 20; ++i) | |
106 | *vi[i] <<= 1; | |
92f5a8d4 | 107 | BOOST_TEST(!q.empty()); |
7c673cae | 108 | for (int i = 0; i < 20; ++i, q.pop()) |
92f5a8d4 TL |
109 | BOOST_TEST_EQ(i << 1, q.top()); |
110 | BOOST_TEST(q.empty()); | |
7c673cae FG |
111 | } |
112 | ||
92f5a8d4 TL |
113 | void beach_line_node_key_test() |
114 | { | |
7c673cae | 115 | node_key_type key(1); |
92f5a8d4 TL |
116 | BOOST_TEST_EQ(1, key.left_site()); |
117 | BOOST_TEST_EQ(1, key.right_site()); | |
7c673cae | 118 | key.left_site(2); |
92f5a8d4 TL |
119 | BOOST_TEST_EQ(2, key.left_site()); |
120 | BOOST_TEST_EQ(1, key.right_site()); | |
7c673cae | 121 | key.right_site(3); |
92f5a8d4 TL |
122 | BOOST_TEST_EQ(2, key.left_site()); |
123 | BOOST_TEST_EQ(3, key.right_site()); | |
7c673cae FG |
124 | } |
125 | ||
92f5a8d4 TL |
126 | void beach_line_node_data_test() |
127 | { | |
7c673cae | 128 | node_data_type node_data(NULL); |
92f5a8d4 TL |
129 | BOOST_TEST(node_data.edge() == NULL); |
130 | BOOST_TEST(node_data.circle_event() == NULL); | |
7c673cae FG |
131 | int data = 4; |
132 | node_data.circle_event(&data); | |
92f5a8d4 TL |
133 | BOOST_TEST(node_data.edge() == NULL); |
134 | BOOST_TEST(node_data.circle_event() == &data); | |
7c673cae | 135 | node_data.edge(&data); |
92f5a8d4 TL |
136 | BOOST_TEST(node_data.edge() == &data); |
137 | BOOST_TEST(node_data.circle_event() == &data); | |
138 | } | |
139 | ||
140 | int main() | |
141 | { | |
142 | point_2d_test1(); | |
143 | site_event_test1(); | |
144 | site_event_test2(); | |
145 | circle_event_test(); | |
146 | ordered_queue_test(); | |
147 | beach_line_node_key_test(); | |
148 | beach_line_node_data_test(); | |
149 | return boost::report_errors(); | |
7c673cae | 150 | } |