// Boost.Geometry (aka GGL, Generic Geometry Library) // Unit Test // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands. // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #include #include #define BOOST_GEOMETRY_UNIT_TEST_SECTIONALIZE #include #include #include #include #include #include #include #include template void test_sectionalize(std::string const /*caseid*/, Geometry const& geometry, std::size_t section_count) { typedef typename bg::point_type::type point; typedef bg::model::box box; typedef bg::sections sections; typedef boost::mpl::vector_c dim2; sections s; bg::sectionalize(geometry, bg::detail::no_rescale_policy(), s); BOOST_CHECK_EQUAL(s.size(), section_count); typedef typename bg::closeable_view < typename bg::detail::range_type::type const, bg::closure::value >::type cview_type; typedef typename bg::reversible_view < cview_type const, Reverse ? bg::iterate_reverse : bg::iterate_forward >::type view_type; typedef typename boost::range_iterator < view_type const >::type range_iterator; BOOST_FOREACH(typename sections::value_type const& sec, s) { cview_type cview(bg::range_by_section(geometry, sec)); view_type view(cview); range_iterator it1 = boost::begin(view) + sec.begin_index; range_iterator it2 = boost::begin(view) + sec.end_index; int count = 0; for (range_iterator it = it1; it != it2; ++it) { count++; } BOOST_CHECK_EQUAL(int(sec.count), count); } } template void test_sectionalize(std::string const& caseid, std::string const& wkt, std::size_t count1) { Geometry geometry; bg::read_wkt(wkt, geometry); if ( BOOST_GEOMETRY_CONDITION( bg::closure::value == bg::open ) ) { geometry.outer().resize(geometry.outer().size() - 1); } //bg::correct(geometry); test_sectionalize<1, Reverse>(caseid + "_d1", geometry, count1); } template void test_all() { 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))"; test_sectionalize, false>("first", first, 4); test_sectionalize, true>("first_reverse", first, 4); test_sectionalize, false>("first_open", first, 4); test_sectionalize, true>("first_open_reverse", first, 4); } int test_main(int, char* []) { test_all >(); return 0; }