]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/views/box_view.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / test / views / box_view.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands.
5
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9
10 #include <algorithm>
11 #include <iterator>
12 #include <sstream>
13 #include <string>
14
15 #include <geometry_test_common.hpp>
16
17 #include <boost/geometry/geometries/geometries.hpp>
18 #include <boost/geometry/geometries/point_xy.hpp>
19 #include <boost/geometry/views/box_view.hpp>
20 #include <boost/geometry/io/wkt/read.hpp>
21
22
23
24 template <typename Box, bool Reverse>
25 void test_geometry(std::string const& wkt, std::string const& expected,
26 bg::order_selector expected_order)
27 {
28
29 Box box;
30 bg::read_wkt(wkt, box);
31
32 typedef bg::box_view<Box, Reverse> view_type;
33 view_type range(box);
34
35 {
36 std::ostringstream out;
37 for (typename boost::range_iterator<view_type>::type it = boost::begin(range);
38 it != boost::end(range); ++it)
39 {
40 out << " " << bg::get<0>(*it) << bg::get<1>(*it);
41 }
42 BOOST_CHECK_EQUAL(out.str(), expected);
43 }
44
45 {
46 // Check forward/backward behaviour
47 typename boost::range_iterator<view_type>::type it = boost::begin(range);
48 it++;
49 it--;
50 // Not verified further, same as segment
51 }
52
53 {
54 // Check random access behaviour
55 int const n = boost::size(range);
56 BOOST_CHECK_EQUAL(n, 5);
57 }
58
59 // Check Boost.Range concept
60 BOOST_CONCEPT_ASSERT( (boost::RandomAccessRangeConcept<view_type>) );
61
62 // Check order
63 bg::order_selector order = bg::point_order<view_type>::value;
64 BOOST_CHECK_EQUAL(order, expected_order);
65 }
66
67
68 template <typename P>
69 void test_all()
70 {
71 test_geometry<bg::model::box<P>, true> ("polygon((1 1,2 2))", " 11 12 22 21 11", bg::clockwise);
72 test_geometry<bg::model::box<P>, false>("polygon((1 1,2 2))", " 11 21 22 12 11", bg::counterclockwise);
73 test_geometry<bg::model::box<P>, true> ("polygon((3 3,5 5))", " 33 35 55 53 33", bg::clockwise);
74 }
75
76
77 int test_main(int, char* [])
78 {
79 test_all<bg::model::d2::point_xy<double> >();
80 return 0;
81 }