// Boost.Geometry // Unit Test // Copyright (c) 2017, Oracle and/or its affiliates. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle // 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) #ifndef BOOST_GEOMETRY_TEST_SRS_CHECK_GEOMETRY_HPP #define BOOST_GEOMETRY_TEST_SRS_CHECK_GEOMETRY_HPP #include #include #include #include #include #include #include #include #include #include #include namespace test { struct check_point { template static void apply(Point const& point1, Point const& point2, T tol) { typename bg::coordinate_type::type x1 = bg::get<0>(point1), y1 = bg::get<1>(point1), x2 = bg::get<0>(point2), y2 = bg::get<1>(point2); BOOST_CHECK_CLOSE(x1, x2, tol); BOOST_CHECK_CLOSE(y1, y2, tol); } }; template struct check_range { template static void apply(Range const& range1, Range const& range2, T tol) { size_t range1_count = boost::size(range1); size_t range2_count = boost::size(range2); BOOST_CHECK_EQUAL(range1_count, range2_count); if (range1_count == range2_count) { apply(boost::begin(range1), boost::end(range1), boost::begin(range2), tol); } } template static void apply(It first1, It last1, It first2, T tol) { for ( ; first1 != last1 ; ++first1, ++first2) Policy::apply(*first1, *first2, tol); } }; template ::type> struct check_geometry_impl {}; template struct check_geometry_impl : check_point {}; template struct check_geometry_impl { template static void apply(Segment const& g1, Segment const& g2, T tol) { bg::detail::indexed_point_view p1(g1); bg::detail::indexed_point_view p2(g1); bg::detail::indexed_point_view q1(g2); bg::detail::indexed_point_view q2(g2); check_point::apply(p1, q1, tol); check_point::apply(p2, q2, tol); } }; template struct check_geometry_impl : check_range<> {}; template struct check_geometry_impl : check_range<> {}; template struct check_geometry_impl : check_range< check_range<> > {}; template struct check_geometry_impl : check_range<> {}; template struct check_geometry_impl { template static void apply(Polygon const& g1, Polygon const& g2, T tol) { check_range<>::apply(bg::exterior_ring(g1), bg::exterior_ring(g2), tol); check_range< check_range<> >::apply(bg::interior_rings(g1), bg::interior_rings(g2), tol); } }; template struct check_geometry_impl : check_range < check_geometry_impl < typename boost::range_value::type, bg::polygon_tag > > {}; template inline void check_geometry(Geometry const& g1, Geometry const& g2, T tol) { check_geometry_impl::apply(g1, g2, tol); } template inline void check_geometry(Geometry const& g1, std::string const& wkt2, T tol) { Geometry g2; bg::read_wkt(wkt2, g2); check_geometry_impl::apply(g1, g2, tol); } } // namespace test #endif // BOOST_GEOMETRY_TEST_SRS_CHECK_GEOMETRY_HPP