1 // Boost.Polygon library voronoi_structures_test.cpp file
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)
8 // See http://www.boost.org for updates, documentation, and revision history.
10 #include <boost/core/lightweight_test.hpp>
11 #include <boost/polygon/detail/voronoi_structures.hpp>
12 #include <boost/polygon/voronoi_geometry_type.hpp>
16 using namespace boost::polygon::detail
;
17 using namespace boost::polygon
;
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
;
29 BOOST_TEST_EQ(1, p
.x());
30 BOOST_TEST_EQ(2, p
.y());
32 BOOST_TEST_EQ(3, p
.x());
34 BOOST_TEST_EQ(4, p
.y());
37 void site_event_test1()
42 s
.source_category(SOURCE_CATEGORY_SEGMENT_START_POINT
);
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());
55 void site_event_test2()
57 site_type
s(1, 2, 3, 4);
60 s
.source_category(SOURCE_CATEGORY_INITIAL_SEGMENT
);
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());
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());
79 void circle_event_test()
81 circle_type
c(0, 1, 2);
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());
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());
95 BOOST_TEST(!c
.is_active());
98 void ordered_queue_test()
100 ordered_queue_type q
;
101 BOOST_TEST(q
.empty());
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
)
107 BOOST_TEST(!q
.empty());
108 for (int i
= 0; i
< 20; ++i
, q
.pop())
109 BOOST_TEST_EQ(i
<< 1, q
.top());
110 BOOST_TEST(q
.empty());
113 void beach_line_node_key_test()
115 node_key_type
key(1);
116 BOOST_TEST_EQ(1, key
.left_site());
117 BOOST_TEST_EQ(1, key
.right_site());
119 BOOST_TEST_EQ(2, key
.left_site());
120 BOOST_TEST_EQ(1, key
.right_site());
122 BOOST_TEST_EQ(2, key
.left_site());
123 BOOST_TEST_EQ(3, key
.right_site());
126 void beach_line_node_data_test()
128 node_data_type
node_data(NULL
);
129 BOOST_TEST(node_data
.edge() == NULL
);
130 BOOST_TEST(node_data
.circle_event() == NULL
);
132 node_data
.circle_event(&data
);
133 BOOST_TEST(node_data
.edge() == NULL
);
134 BOOST_TEST(node_data
.circle_event() == &data
);
135 node_data
.edge(&data
);
136 BOOST_TEST(node_data
.edge() == &data
);
137 BOOST_TEST(node_data
.circle_event() == &data
);
146 ordered_queue_test();
147 beach_line_node_key_test();
148 beach_line_node_data_test();
149 return boost::report_errors();