// Boost.Geometry // Unit Test // Copyright (c) 2014-2015 Adam Wulkiewicz, Lodz, Poland. // 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 typedef std::pair pt_pair_t; BOOST_GEOMETRY_REGISTER_POINT_2D(pt_pair_t, float, bg::cs::cartesian, first, second) BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian) template void test_default() { typedef bg::model::multi_point

mpt; typedef bg::model::linestring

ls; typedef bg::model::multi_linestring mls; typedef bg::model::ring

ring; typedef bg::model::polygon

poly; typedef bg::model::multi_polygon mpoly; // multi_point() mpt mptd; BOOST_CHECK(bg::num_points(mptd) == 0); // linestring() ls lsd; BOOST_CHECK(bg::num_points(lsd) == 0); // multi_linestring() mls mlsd; BOOST_CHECK(bg::num_points(mlsd) == 0); // ring() ring rd; BOOST_CHECK(bg::num_points(rd) == 0); // polygon() poly pd; BOOST_CHECK(bg::num_points(pd) == 0); // multi_polygon() mpoly mpd; BOOST_CHECK(bg::num_points(mpd) == 0); } template void test_boost_assign_2d() { typedef bg::model::multi_point

mpt; typedef bg::model::linestring

ls; typedef bg::model::ring

ring; // using Boost.Assign mpt mpt2 = boost::assign::list_of(P(0, 0))(P(1, 0)); BOOST_CHECK(bg::num_points(mpt2) == 2); mpt2 = boost::assign::list_of(P(0, 0))(P(1, 0)); BOOST_CHECK(bg::num_points(mpt2) == 2); // using Boost.Assign ls ls2 = boost::assign::list_of(P(0, 0))(P(1, 0))(P(1, 1)); BOOST_CHECK(bg::num_points(ls2) == 3); ls2 = boost::assign::list_of(P(0, 0))(P(1, 0))(P(1, 1)); BOOST_CHECK(bg::num_points(ls2) == 3); // using Boost.Assign ring r2 = boost::assign::list_of(P(0, 0))(P(0, 1))(P(1, 1))(P(1, 0))(P(0, 0)); BOOST_CHECK(bg::num_points(r2) == 5); r2 = boost::assign::list_of(P(0, 0))(P(0, 1))(P(1, 1))(P(1, 0))(P(0, 0)); BOOST_CHECK(bg::num_points(r2) == 5); } void test_boost_assign_pair_2d() { typedef std::pair pt; test_boost_assign_2d(); typedef bg::model::multi_point mpt; // using Boost.Assign mpt mpt2 = boost::assign::pair_list_of(0, 0)(1, 0); BOOST_CHECK(bg::num_points(mpt2) == 2); mpt2 = boost::assign::pair_list_of(0, 0)(1, 0); BOOST_CHECK(bg::num_points(mpt2) == 2); } void test_boost_assign_tuple_2d() { typedef boost::tuple pt; test_boost_assign_2d(); typedef bg::model::multi_point mpt; // using Boost.Assign mpt mpt2 = boost::assign::tuple_list_of(0, 0)(1, 0); BOOST_CHECK(bg::num_points(mpt2) == 2); mpt2 = boost::assign::tuple_list_of(0, 0)(1, 0); BOOST_CHECK(bg::num_points(mpt2) == 2); } template void test_initializer_list_2d() { #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) typedef bg::model::multi_point

mpt; typedef bg::model::linestring

ls; typedef bg::model::multi_linestring mls; typedef bg::model::ring

ring; typedef bg::model::polygon

poly; typedef bg::model::multi_polygon mpoly; // multi_point(initializer_list) mpt mpt1 = {{0, 0}, {1, 0}, {2, 0}}; BOOST_CHECK(bg::num_geometries(mpt1) == 3); BOOST_CHECK(bg::num_points(mpt1) == 3); // multi_point::operator=(initializer_list) mpt1 = {{0, 0}, {1, 0}, {2, 0}, {3, 0}}; BOOST_CHECK(bg::num_points(mpt1) == 4); // linestring(initializer_list) ls ls1 = {{0, 0}, {1, 0}, {2, 0}}; BOOST_CHECK(bg::num_geometries(ls1) == 1); BOOST_CHECK(bg::num_points(ls1) == 3); // linestring::operator=(initializer_list) ls1 = {{0, 0}, {1, 0}, {2, 0}, {3, 0}}; BOOST_CHECK(bg::num_points(ls1) == 4); // multi_linestring(initializer_list) mls mls1 = {{{0, 0}, {1, 0}, {2, 0}}, {{3, 0}, {4, 0}}}; BOOST_CHECK(bg::num_geometries(mls1) == 2); BOOST_CHECK(bg::num_points(mls1) == 5); // multi_linestring::operator=(initializer_list) mls1 = {{{0, 0}, {1, 0}, {2, 0}}, {{3, 0}, {4, 0}, {5, 0}}}; BOOST_CHECK(bg::num_points(mls1) == 6); // ring(initializer_list) ring r1 = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; BOOST_CHECK(bg::num_geometries(r1) == 1); BOOST_CHECK(bg::num_points(r1) == 5); // ring::operator=(initializer_list) r1 = {{0, 0}, {0, 1}, {1, 2}, {2, 1}, {1, 0}, {0, 0}}; BOOST_CHECK(bg::num_points(r1) == 6); // polygon(initializer_list) poly p1 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}, {{1, 1}, {2, 1}, {2, 2}, {1, 2}, {1, 1}}}; BOOST_CHECK(bg::num_geometries(p1) == 1); BOOST_CHECK(bg::num_points(p1) == 10); BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 1); // polygon::operator=(initializer_list) p1 = {{{0, 0}, {0, 8}, {8, 9}, {9, 8}, {8, 0}, {0, 0}}, {{1, 1}, {2, 1}, {2, 2}, {1, 2}, {1, 1}}}; BOOST_CHECK(bg::num_points(p1) == 11); BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 1); p1 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}}; BOOST_CHECK(bg::num_points(p1) == 5); BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 0); // polygon(initializer_list) poly p2 = {{{0, 0}, {0, 9}, {9, 9}, {9, 0}, {0, 0}}}; BOOST_CHECK(bg::num_geometries(p2) == 1); BOOST_CHECK(bg::num_points(p2) == 5); BOOST_CHECK(boost::size(bg::interior_rings(p1)) == 0); // polygon::operator=(initializer_list) p2 = {{{0, 0}, {0, 8}, {8, 9}, {9, 8}, {8, 0}, {0, 0}}}; BOOST_CHECK(bg::num_points(p2) == 6); // multi_polygon(initializer_list) mpoly mp1 = {{{{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}}, {{{2, 2}, {2, 3}, {3, 3}, {3, 2}, {2, 2}}}}; BOOST_CHECK(bg::num_geometries(mp1) == 2); BOOST_CHECK(bg::num_points(mp1) == 10); // multi_polygon::operator=(initializer_list) mp1 = {{{{0, 0}, {0, 1}, {1, 2}, {2, 1}, {1, 0}, {0, 0}}}, {{{2, 2}, {2, 3}, {3, 3}, {3, 2}, {2, 2}}}}; BOOST_CHECK(bg::num_points(mp1) == 11); #endif } template void test_all_2d() { test_default

(); test_boost_assign_2d

(); test_initializer_list_2d

(); } template struct test_point { test_point(T = T(), T = T()) {} }; template struct test_range { test_range() {} template test_range(It, It) {} #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) test_range(std::initializer_list) {} //test_range & operator=(std::initializer_list) { return *this; } #endif }; void test_sanity_check() { typedef test_point P; typedef test_range

R; typedef std::vector

V; #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST) && !defined(BOOST_NO_CXX11_UNIFIED_INITIALIZATION_SYNTAX) { R r = {{1, 1},{2, 2},{3, 3}}; r = {{1, 1},{2, 2},{3, 3}}; V v = {{1, 1},{2, 2},{3, 3}}; v = {{1, 1},{2, 2},{3, 3}}; } #endif { R r = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3)); r = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3)); V v = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3)); //v = boost::assign::list_of(P(1, 1))(P(2, 2))(P(3, 3)); v.empty(); } } int test_main(int, char* []) { test_all_2d< bg::model::point >(); test_all_2d< bg::model::d2::point_xy >(); test_boost_assign_pair_2d(); test_boost_assign_tuple_2d(); test_sanity_check(); return 0; }