• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <iostream>
11 #include <string>
12 
13 #define BOOST_GEOMETRY_UNIT_TEST_SECTIONALIZE
14 
15 #include <geometry_test_common.hpp>
16 
17 #include <boost/geometry/algorithms/detail/sections/sectionalize.hpp>
18 #include <boost/geometry/algorithms/detail/sections/range_by_section.hpp>
19 #include <boost/geometry/views/detail/range_type.hpp>
20 #include <boost/geometry/geometries/geometries.hpp>
21 #include <boost/geometry/geometries/point_xy.hpp>
22 #include <boost/geometry/io/wkt/wkt.hpp>
23 #include <boost/geometry/util/condition.hpp>
24 
25 
26 template <int DimensionCount, bool Reverse, typename Geometry>
test_sectionalize(std::string const,Geometry const & geometry,std::size_t section_count)27 void test_sectionalize(std::string const /*caseid*/, Geometry const& geometry, std::size_t section_count)
28 {
29     typedef typename bg::point_type<Geometry>::type point;
30     typedef bg::model::box<point> box;
31     typedef bg::sections<box, DimensionCount> sections;
32 
33     typedef boost::mpl::vector_c<std::size_t, 0> dim2;
34 
35     sections s;
36     bg::sectionalize<Reverse, dim2>(geometry, bg::detail::no_rescale_policy(), s);
37 
38     BOOST_CHECK_EQUAL(s.size(), section_count);
39 
40     typedef typename bg::closeable_view
41         <
42             typename bg::detail::range_type<Geometry>::type const,
43             bg::closure<Geometry>::value
44         >::type cview_type;
45     typedef typename bg::reversible_view
46         <
47             cview_type const,
48             Reverse ? bg::iterate_reverse : bg::iterate_forward
49         >::type view_type;
50     typedef typename boost::range_iterator
51         <
52             view_type const
53         >::type range_iterator;
54 
55     BOOST_FOREACH(typename sections::value_type const& sec, s)
56     {
57         cview_type cview(bg::range_by_section(geometry, sec));
58         view_type view(cview);
59         range_iterator it1 = boost::begin(view) + sec.begin_index;
60         range_iterator it2 = boost::begin(view) + sec.end_index;
61         int count = 0;
62         for (range_iterator it = it1; it != it2; ++it)
63         {
64             count++;
65         }
66         BOOST_CHECK_EQUAL(int(sec.count), count);
67     }
68 }
69 
70 template <typename Geometry, bool Reverse>
test_sectionalize(std::string const & caseid,std::string const & wkt,std::size_t count1)71 void test_sectionalize(std::string const& caseid, std::string const& wkt,
72         std::size_t count1)
73 {
74     Geometry geometry;
75     bg::read_wkt(wkt, geometry);
76     if ( BOOST_GEOMETRY_CONDITION( bg::closure<Geometry>::value == bg::open ) )
77     {
78         geometry.outer().resize(geometry.outer().size() - 1);
79     }
80     //bg::correct(geometry);
81     test_sectionalize<1, Reverse>(caseid + "_d1", geometry, count1);
82 }
83 
84 template <typename P>
test_all()85 void test_all()
86 {
87     std::string const first = "polygon((2.0 1.3, 2.4 1.7, 2.8 1.8, 3.4 1.2, 3.7 1.6,3.4 2.0, 4.1 3.0, 5.3 2.6, 5.4 1.2, 4.9 0.8, 2.9 0.7,2.0 1.3))";
88     test_sectionalize<bg::model::polygon<P>, false>("first", first, 4);
89 
90     test_sectionalize<bg::model::polygon<P, false>, true>("first_reverse",
91         first, 4);
92 
93     test_sectionalize<bg::model::polygon<P, false, true>, false>("first_open",
94         first, 4);
95 
96     test_sectionalize<bg::model::polygon<P, true, false>, true>("first_open_reverse",
97         first, 4);
98 }
99 
test_main(int,char * [])100 int test_main(int, char* [])
101 {
102     test_all<bg::model::d2::point_xy<double> >();
103 
104     return 0;
105 }
106