// 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 #include #include #include #include #include #include #include #include #include #include BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) template void test_option(View const& view, std::string const& expected) { bool first = true; std::ostringstream out; typedef typename boost::range_iterator::type iterator; iterator end = boost::end(view); for (iterator it = boost::begin(view); it != end; ++it, first = false) { out << (first ? "" : " ") << bg::dsv(*it); } BOOST_CHECK_EQUAL(out.str(), expected); } template void test_close_reverse(Range const& range, std::string const& expected) { typedef typename bg::reversible_view::type rview; typedef typename bg::closeable_view::type cview; rview view1(range); cview view2(view1); test_option(view2, expected); } template void test_reverse_close(Range const& range, std::string const& expected) { typedef typename bg::closeable_view::type cview; typedef typename bg::reversible_view::type rview; cview view1(range); rview view2(view1); test_option(view2, expected); } template < bg::iterate_direction Direction1, bg::iterate_direction Direction2, typename Range > void test_reverse_reverse(Range const& range, std::string const& expected) { typedef typename bg::reversible_view::type rview1; typedef typename bg::reversible_view::type rview2; rview1 view1(range); rview2 view2(view1); test_option(view2, expected); } template < bg::closure_selector Closure1, bg::closure_selector Closure2, typename Range > void test_close_close(Range const& range, std::string const& expected) { typedef typename bg::closeable_view::type cview1; typedef typename bg::closeable_view::type cview2; cview1 view1(range); cview2 view2(view1); test_option(view2, expected); } template void test_geometry(std::string const& wkt, std::string const& expected_n, std::string const& expected_r, std::string const& closing, std::string const& rclosing ) { std::string expected; Geometry geo; bg::read_wkt(wkt, geo); test_close_reverse(geo, expected_n); test_close_reverse(geo, expected_n + closing); test_close_reverse(geo, expected_r); // 13-12-2010, this case was problematic in MSVC // SOLVED: caused by IMPLICIT constructor! It is now explicit and should be kept like that. test_close_reverse(geo, expected_r + rclosing); test_reverse_close(geo, expected_n); test_reverse_close(geo, expected_n + closing); test_reverse_close(geo, expected_r); // first closed, then reversed: expected = boost::trim_copy(closing + " " + expected_r); test_reverse_close(geo, expected); test_reverse_reverse(geo, expected_n); test_reverse_reverse(geo, expected_n); test_reverse_reverse(geo, expected_r); test_reverse_reverse(geo, expected_r); test_close_close(geo, expected_n); test_close_close(geo, expected_n + closing); test_close_close(geo, expected_n + closing); test_close_close(geo, expected_n + closing + closing); } template void test_all() { test_geometry >( "POLYGON((1 1,1 4,4 4,4 1))", "(1, 1) (1, 4) (4, 4) (4, 1)", "(4, 1) (4, 4) (1, 4) (1, 1)", " (1, 1)", // closing " (4, 1)" // rclosing ); } int test_main(int, char* []) { test_all >(); test_all >(); test_all >(); return 0; }