• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Boost.Geometry
2 // Unit Test
3 
4 // Copyright (c) 2017, Oracle and/or its affiliates.
5 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
6 
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 
11 
12 #ifndef BOOST_GEOMETRY_TEST_SRS_CHECK_GEOMETRY_HPP
13 #define BOOST_GEOMETRY_TEST_SRS_CHECK_GEOMETRY_HPP
14 
15 
16 #include <geometry_test_common.hpp>
17 
18 #include <boost/geometry/core/access.hpp>
19 #include <boost/geometry/core/coordinate_type.hpp>
20 #include <boost/geometry/core/tag.hpp>
21 #include <boost/geometry/core/tags.hpp>
22 
23 #include <boost/geometry/io/wkt/read.hpp>
24 
25 #include <boost/geometry/views/detail/indexed_point_view.hpp>
26 
27 #include <boost/range/begin.hpp>
28 #include <boost/range/end.hpp>
29 #include <boost/range/size.hpp>
30 #include <boost/range/value_type.hpp>
31 
32 
33 namespace test
34 {
35 
36 struct check_point
37 {
38     template <typename Point, typename T>
applytest::check_point39     static void apply(Point const& point1, Point const& point2, T tol)
40     {
41         typename bg::coordinate_type<Point>::type
42             x1 = bg::get<0>(point1),
43             y1 = bg::get<1>(point1),
44             x2 = bg::get<0>(point2),
45             y2 = bg::get<1>(point2);
46 
47         BOOST_CHECK_CLOSE(x1, x2, tol);
48         BOOST_CHECK_CLOSE(y1, y2, tol);
49     }
50 };
51 
52 template <typename Policy = check_point>
53 struct check_range
54 {
55     template <typename Range, typename T>
applytest::check_range56     static void apply(Range const& range1, Range const& range2, T tol)
57     {
58         size_t range1_count = boost::size(range1);
59         size_t range2_count = boost::size(range2);
60         BOOST_CHECK_EQUAL(range1_count, range2_count);
61         if (range1_count == range2_count)
62         {
63             apply(boost::begin(range1), boost::end(range1),
64                   boost::begin(range2), tol);
65         }
66     }
67     template <typename It, typename T>
applytest::check_range68     static void apply(It first1, It last1, It first2, T tol)
69     {
70         for ( ; first1 != last1 ; ++first1, ++first2)
71             Policy::apply(*first1, *first2, tol);
72     }
73 };
74 
75 
76 template <typename Geometry, typename Tag = typename bg::tag<Geometry>::type>
77 struct check_geometry_impl
78 {};
79 
80 template <typename Point>
81 struct check_geometry_impl<Point, bg::point_tag>
82     : check_point
83 {};
84 
85 template <typename Segment>
86 struct check_geometry_impl<Segment, bg::segment_tag>
87 {
88     template <typename T>
applytest::check_geometry_impl89     static void apply(Segment const& g1, Segment const& g2, T tol)
90     {
91         bg::detail::indexed_point_view<Segment const, 0> p1(g1);
92         bg::detail::indexed_point_view<Segment const, 1> p2(g1);
93         bg::detail::indexed_point_view<Segment const, 0> q1(g2);
94         bg::detail::indexed_point_view<Segment const, 1> q2(g2);
95 
96         check_point::apply(p1, q1, tol);
97         check_point::apply(p2, q2, tol);
98     }
99 };
100 
101 template <typename MultiPoint>
102 struct check_geometry_impl<MultiPoint, bg::multi_point_tag>
103     : check_range<>
104 {};
105 
106 template <typename Linestring>
107 struct check_geometry_impl<Linestring, bg::linestring_tag>
108     : check_range<>
109 {};
110 
111 template <typename MultiLinestring>
112 struct check_geometry_impl<MultiLinestring, bg::multi_linestring_tag>
113     : check_range< check_range<> >
114 {};
115 
116 template <typename Ring>
117 struct check_geometry_impl<Ring, bg::ring_tag>
118     : check_range<>
119 {};
120 
121 template <typename Polygon>
122 struct check_geometry_impl<Polygon, bg::polygon_tag>
123 {
124     template <typename T>
applytest::check_geometry_impl125     static void apply(Polygon const& g1, Polygon const& g2, T tol)
126     {
127         check_range<>::apply(bg::exterior_ring(g1), bg::exterior_ring(g2), tol);
128         check_range< check_range<> >::apply(bg::interior_rings(g1), bg::interior_rings(g2), tol);
129     }
130 };
131 
132 template <typename MultiPolygon>
133 struct check_geometry_impl<MultiPolygon, bg::multi_polygon_tag>
134     : check_range
135         <
136             check_geometry_impl
137                 <
138                     typename boost::range_value<MultiPolygon>::type,
139                     bg::polygon_tag
140                 >
141         >
142 {};
143 
144 
145 template <typename Geometry, typename T>
check_geometry(Geometry const & g1,Geometry const & g2,T tol)146 inline void check_geometry(Geometry const& g1, Geometry const& g2, T tol)
147 {
148     check_geometry_impl<Geometry>::apply(g1, g2, tol);
149 }
150 
151 template <typename Geometry, typename T>
check_geometry(Geometry const & g1,std::string const & wkt2,T tol)152 inline void check_geometry(Geometry const& g1, std::string const& wkt2, T tol)
153 {
154     Geometry g2;
155     bg::read_wkt(wkt2, g2);
156     check_geometry_impl<Geometry>::apply(g1, g2, tol);
157 }
158 
159 } // namespace test
160 
161 
162 #endif // BOOST_GEOMETRY_TEST_SRS_CHECK_GEOMETRY_HPP
163