]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/polygon/test/polygon_set_data_test.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / polygon / test / polygon_set_data_test.cpp
1 // Boost.Polygon library polygon_set_data_test.cpp file
2
3 // Copyright Andrii Sydorchuk 2015.
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
10 #define BOOST_TEST_MODULE POLYGON_SET_DATA_TEST
11 #include <vector>
12
13 #include <boost/mpl/list.hpp>
14 #include <boost/test/test_case_template.hpp>
15
16 #include "boost/polygon/polygon.hpp"
17 using namespace boost::polygon;
18 using namespace boost::polygon::operators;
19
20 typedef boost::mpl::list<int> test_types;
21
22 BOOST_AUTO_TEST_CASE_TEMPLATE(polygon_set_data_test1, T, test_types) {
23 typedef point_data<T> point_type;
24 typedef polygon_data<T> polygon_type;
25 typedef polygon_with_holes_data<T> polygon_with_holes_type;
26 typedef polygon_set_data<T> polygon_set_type;
27
28 polygon_set_type pset;
29 std::vector<point_type> outbox;
30 outbox.push_back(point_type(0, 0));
31 outbox.push_back(point_type(100, 0));
32 outbox.push_back(point_type(100, 100));
33 outbox.push_back(point_type(0, 100));
34 pset.insert_vertex_sequence(outbox.begin(), outbox.end(), COUNTERCLOCKWISE, false);
35 std::vector<point_type> inbox;
36 inbox.push_back(point_type(20, 20));
37 inbox.push_back(point_type(80, 20));
38 inbox.push_back(point_type(80, 80));
39 inbox.push_back(point_type(20, 80));
40 pset.insert_vertex_sequence(inbox.begin(), inbox.end(), COUNTERCLOCKWISE, true);
41
42 BOOST_CHECK(!pset.empty());
43 BOOST_CHECK(!pset.sorted());
44 BOOST_CHECK(pset.dirty());
45 BOOST_CHECK_EQUAL(8, pset.size());
46
47 std::vector<polygon_with_holes_type> vpoly;
48 pset.get(vpoly);
49 BOOST_CHECK_EQUAL(1, vpoly.size());
50
51 polygon_with_holes_type poly = vpoly[0];
52 BOOST_CHECK_EQUAL(5, poly.size());
53 BOOST_CHECK_EQUAL(1, poly.size_holes());
54 }
55
56 BOOST_AUTO_TEST_CASE_TEMPLATE(polygon_set_data_test2, T, test_types) {
57 typedef point_data<T> point_type;
58 typedef polygon_data<T> polygon_type;
59 typedef polygon_with_holes_data<T> polygon_with_holes_type;
60 typedef polygon_set_data<T> polygon_set_type;
61
62 std::vector<point_type> data;
63 data.push_back(point_type(2,0));
64 data.push_back(point_type(4,0));
65 data.push_back(point_type(4,3));
66 data.push_back(point_type(0,3));
67 data.push_back(point_type(0,0));
68 data.push_back(point_type(2,0));
69 data.push_back(point_type(2,1));
70 data.push_back(point_type(1,1));
71 data.push_back(point_type(1,2));
72 data.push_back(point_type(3,2));
73 data.push_back(point_type(3,1));
74 data.push_back(point_type(2,1));
75 data.push_back(point_type(2,0));
76
77 polygon_type polygon;
78 set_points(polygon, data.begin(), data.end());
79
80 polygon_set_type pset;
81 pset.insert(polygon);
82
83 std::vector<polygon_type> traps;
84 get_trapezoids(traps, pset, HORIZONTAL);
85
86 BOOST_CHECK_EQUAL(4, traps.size());
87 }
88
89 BOOST_AUTO_TEST_CASE_TEMPLATE(polygon_set_data_test3, T, test_types) {
90 typedef point_data<T> point_type;
91 typedef polygon_data<T> polygon_type;
92 typedef polygon_with_holes_data<T> polygon_with_holes_type;
93 typedef polygon_set_data<T> polygon_set_type;
94
95 std::vector<point_type> data;
96 data.push_back(point_type(0,0));
97 data.push_back(point_type(6,0));
98 data.push_back(point_type(6,4));
99 data.push_back(point_type(4,6));
100 data.push_back(point_type(0,6));
101 data.push_back(point_type(0,0));
102 data.push_back(point_type(4,4));
103 data.push_back(point_type(5,4));
104
105 polygon_type polygon(data.begin(), data.end());
106 polygon_set_type pset;
107 pset += polygon;
108
109 BOOST_CHECK_EQUAL(32.0, area(polygon));
110 BOOST_CHECK_EQUAL(32.0, area(polygon));
111 }