]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/core/ring.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / test / core / ring.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
6 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
7
8 // This file was modified by Oracle on 2014.
9 // Modifications copyright (c) 2014 Oracle and/or its affiliates.
10
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12
13 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
14 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
15
16 // Use, modification and distribution is subject to the Boost Software License,
17 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
18 // http://www.boost.org/LICENSE_1_0.txt)
19
20
21 #include <geometry_test_common.hpp>
22
23
24 // To be tested:
25 #include <boost/geometry/core/ring_type.hpp>
26 #include <boost/geometry/core/exterior_ring.hpp>
27 #include <boost/geometry/core/interior_rings.hpp>
28
29 // For geometries:
30 #include <boost/geometry/core/cs.hpp>
31 #include <boost/geometry/geometries/point.hpp>
32 #include <boost/geometry/geometries/polygon.hpp>
33
34
35 #include <boost/geometry/io/wkt/read.hpp>
36
37
38 template <typename Poly>
39 void test_order_closure(bg::order_selector expected_order, bg::closure_selector exptected_closure)
40 {
41 bg::order_selector order = bg::point_order<Poly>::value;
42 bg::closure_selector closure = bg::closure<Poly>::value;
43
44 BOOST_CHECK_EQUAL(order, expected_order);
45 BOOST_CHECK_EQUAL(closure, exptected_closure);
46 }
47
48
49 template <typename P>
50 void test_ring(std::string const& wkt,
51 std::size_t expected_main_count,
52 std::size_t expected_interior_ring_count,
53 std::size_t expected_first_interior_count)
54 {
55 typedef bg::model::polygon<P> the_polygon;
56 typedef typename bg::ring_type<the_polygon>::type the_ring;
57 typedef typename bg::interior_return_type<the_polygon const>::type the_interior;
58
59 the_polygon poly;
60 bg::read_wkt(wkt, poly);
61
62 the_ring ext = bg::exterior_ring(poly);
63 the_interior rings = bg::interior_rings(poly);
64
65 BOOST_CHECK_EQUAL(bg::num_interior_rings(poly), expected_interior_ring_count);
66 BOOST_CHECK_EQUAL(boost::size(rings), expected_interior_ring_count);
67 BOOST_CHECK_EQUAL(boost::size(ext), expected_main_count);
68 if (boost::size(rings))
69 {
70 BOOST_CHECK_EQUAL(boost::size(rings.front()), expected_first_interior_count);
71 }
72 }
73
74
75 template <typename P>
76 void test_all()
77 {
78 test_ring<P>("POLYGON((0 0,0 3,3 3,3 0,0 0),(1 1,1 2,2 2,2 1,1 1))", 5, 1, 5);
79 test_ring<P>("POLYGON((0 0,0 3,3 3,3 0,0 0),(1 1,2 2,2 1,1 1),(1 1,1 2,2 2,1 1))", 5, 2, 4);
80 test_ring<P>("POLYGON((0 0,0 3,3 3,3 0,0 0))", 5, 0, 0);
81
82 test_order_closure< bg::model::polygon<P, true, true> >(bg::clockwise, bg::closed);
83 test_order_closure< bg::model::polygon<P, true, false> >(bg::clockwise, bg::open);
84 test_order_closure< bg::model::polygon<P, false, true> >(bg::counterclockwise, bg::closed);
85 test_order_closure< bg::model::polygon<P, false, false> >(bg::counterclockwise, bg::open);
86
87 test_order_closure< bg::model::polygon<P> *>(bg::clockwise, bg::closed);
88 test_order_closure< bg::model::polygon<P> &>(bg::clockwise, bg::closed);
89 test_order_closure< bg::model::polygon<P> const>(bg::clockwise, bg::closed);
90 test_order_closure< bg::model::polygon<P> *&>(bg::clockwise, bg::closed);
91 test_order_closure< const bg::model::polygon<P> *>(bg::clockwise, bg::closed);
92 }
93
94
95 int test_main(int, char* [])
96 {
97 test_all<bg::model::point<double, 2, bg::cs::cartesian> >();
98 return 0;
99 }