]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | // Unit Test | |
3 | ||
4 | // Copyright (c) 2014, Oracle and/or its affiliates. | |
5 | ||
6 | // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle | |
7 | ||
8 | // Licensed under the Boost Software License version 1.0. | |
9 | // http://www.boost.org/users/license.html | |
10 | ||
11 | #ifndef BOOST_TEST_MODULE | |
12 | #define BOOST_TEST_MODULE test_distance_default_result | |
13 | #endif | |
14 | ||
15 | #include <cstddef> | |
16 | #include <iostream> | |
17 | ||
18 | #include <boost/test/included/unit_test.hpp> | |
19 | ||
20 | #include <boost/mpl/assert.hpp> | |
21 | #include <boost/mpl/if.hpp> | |
22 | #include <boost/type_traits/is_same.hpp> | |
23 | ||
24 | #include <boost/geometry/util/calculation_type.hpp> | |
25 | ||
26 | #include <boost/geometry/geometries/point.hpp> | |
27 | #include <boost/geometry/geometries/segment.hpp> | |
28 | #include <boost/geometry/geometries/box.hpp> | |
29 | ||
30 | #include <boost/geometry/strategies/strategies.hpp> | |
31 | #include <boost/geometry/strategies/default_distance_result.hpp> | |
32 | #include <boost/geometry/strategies/default_comparable_distance_result.hpp> | |
33 | ||
7c673cae FG |
34 | namespace bg = ::boost::geometry; |
35 | ||
36 | ||
37 | template <typename DefaultResult, typename ExpectedResult> | |
38 | struct assert_equal_types | |
39 | { | |
40 | assert_equal_types() | |
41 | { | |
42 | static const bool are_same = | |
43 | boost::is_same<DefaultResult, ExpectedResult>::type::value; | |
44 | ||
45 | BOOST_MPL_ASSERT_MSG((are_same), | |
46 | WRONG_DEFAULT_DISTANCE_RESULT, | |
47 | (types<DefaultResult, ExpectedResult>)); | |
48 | } | |
49 | }; | |
50 | ||
51 | //========================================================================= | |
52 | ||
53 | template | |
54 | < | |
55 | typename Geometry1, | |
56 | typename Geometry2, | |
57 | typename ExpectedResult, | |
58 | typename ExpectedComparableResult | |
59 | > | |
60 | inline void test_distance_result() | |
61 | { | |
62 | typedef typename bg::default_distance_result | |
63 | < | |
64 | Geometry1, Geometry2 | |
65 | >::type result12; | |
66 | ||
67 | typedef typename bg::default_distance_result | |
68 | < | |
69 | Geometry2, Geometry1 | |
70 | >::type result21; | |
71 | ||
72 | typedef typename bg::default_comparable_distance_result | |
73 | < | |
74 | Geometry1, Geometry2 | |
75 | >::type comparable_result12; | |
76 | ||
77 | typedef typename bg::default_comparable_distance_result | |
78 | < | |
79 | Geometry2, Geometry1 | |
80 | >::type comparable_result21; | |
81 | ||
82 | assert_equal_types<result12, ExpectedResult>(); | |
83 | assert_equal_types<result21, ExpectedResult>(); | |
84 | assert_equal_types<comparable_result12, ExpectedComparableResult>(); | |
85 | assert_equal_types<comparable_result21, ExpectedComparableResult>(); | |
86 | } | |
87 | ||
88 | //========================================================================= | |
89 | ||
90 | template | |
91 | < | |
92 | typename CoordinateType1, | |
93 | typename CoordinateType2, | |
94 | std::size_t Dimension, | |
95 | typename CoordinateSystem, | |
96 | typename ExpectedResult, | |
97 | typename ExpectedComparableResult = ExpectedResult | |
98 | > | |
99 | struct test_distance_result_segment | |
100 | { | |
101 | test_distance_result_segment() | |
102 | { | |
103 | typedef typename bg::model::point | |
104 | < | |
105 | CoordinateType1, Dimension, CoordinateSystem | |
106 | > point1; | |
107 | ||
108 | typedef typename bg::model::point | |
109 | < | |
110 | CoordinateType2, Dimension, CoordinateSystem | |
111 | > point2; | |
112 | ||
113 | typedef typename bg::model::segment<point1> segment1; | |
114 | typedef typename bg::model::segment<point2> segment2; | |
115 | ||
116 | test_distance_result | |
117 | < | |
118 | point1, point2, ExpectedResult, ExpectedComparableResult | |
119 | >(); | |
120 | ||
121 | test_distance_result | |
122 | < | |
123 | point1, segment2, ExpectedResult, ExpectedComparableResult | |
124 | >(); | |
125 | ||
126 | test_distance_result | |
127 | < | |
128 | point2, segment1, ExpectedResult, ExpectedComparableResult | |
129 | >(); | |
130 | } | |
131 | }; | |
132 | ||
133 | //========================================================================= | |
134 | ||
135 | template | |
136 | < | |
137 | typename CoordinateType1, | |
138 | typename CoordinateType2, | |
139 | std::size_t Dimension, | |
140 | typename ExpectedResult, | |
141 | typename ExpectedComparableResult = ExpectedResult | |
142 | > | |
143 | struct test_distance_result_box | |
144 | { | |
145 | test_distance_result_box() | |
146 | { | |
147 | typedef typename bg::model::point | |
148 | < | |
149 | CoordinateType1, Dimension, bg::cs::cartesian | |
150 | > point1; | |
151 | ||
152 | typedef typename bg::model::point | |
153 | < | |
154 | CoordinateType2, Dimension, bg::cs::cartesian | |
155 | > point2; | |
156 | ||
157 | typedef typename bg::model::box<point1> box1; | |
158 | typedef typename bg::model::box<point2> box2; | |
159 | ||
160 | test_distance_result | |
161 | < | |
162 | point1, box2, ExpectedResult, ExpectedComparableResult | |
163 | >(); | |
164 | ||
165 | test_distance_result | |
166 | < | |
167 | point2, box1, ExpectedResult, ExpectedComparableResult | |
168 | >(); | |
169 | ||
170 | test_distance_result | |
171 | < | |
172 | box1, box2, ExpectedResult, ExpectedComparableResult | |
173 | >(); | |
174 | } | |
175 | }; | |
176 | ||
177 | //========================================================================= | |
178 | ||
179 | template <std::size_t D, typename CoordinateSystem> | |
180 | inline void test_segment_all() | |
181 | { | |
7c673cae FG |
182 | typedef typename boost::mpl::if_ |
183 | < | |
184 | typename boost::is_same<CoordinateSystem, bg::cs::cartesian>::type, | |
185 | double, | |
186 | float | |
187 | >::type float_return_type; | |
188 | ||
189 | test_distance_result_segment<short, short, D, CoordinateSystem, double>(); | |
190 | test_distance_result_segment<int, int, D, CoordinateSystem, double>(); | |
191 | test_distance_result_segment<int, long, D, CoordinateSystem, double>(); | |
192 | test_distance_result_segment<long, long, D, CoordinateSystem, double>(); | |
193 | ||
194 | test_distance_result_segment<int, float, D, CoordinateSystem, float_return_type>(); | |
195 | test_distance_result_segment<float, float, D, CoordinateSystem, float_return_type>(); | |
196 | ||
197 | test_distance_result_segment<int, double, D, CoordinateSystem, double>(); | |
198 | test_distance_result_segment<double, int, D, CoordinateSystem, double>(); | |
199 | test_distance_result_segment<float, double, D, CoordinateSystem, double>(); | |
200 | test_distance_result_segment<double, float, D, CoordinateSystem, double>(); | |
201 | test_distance_result_segment<double, double, D, CoordinateSystem, double>(); | |
7c673cae FG |
202 | } |
203 | ||
204 | //========================================================================= | |
205 | ||
206 | template <std::size_t D> | |
207 | inline void test_box_all() | |
208 | { | |
7c673cae FG |
209 | typedef bg::util::detail::default_integral::type default_integral; |
210 | ||
211 | test_distance_result_box<short, short, D, double, default_integral>(); | |
212 | test_distance_result_box<int, int, D, double, default_integral>(); | |
213 | test_distance_result_box<int, long, D, double, default_integral>(); | |
214 | test_distance_result_box<long, long, D, double, default_integral>(); | |
215 | ||
216 | test_distance_result_box<int, float, D, double>(); | |
217 | test_distance_result_box<float, float, D, double>(); | |
218 | ||
219 | test_distance_result_box<int, double, D, double>(); | |
220 | test_distance_result_box<double, int, D, double>(); | |
221 | test_distance_result_box<float, double, D, double>(); | |
222 | test_distance_result_box<double, float, D, double>(); | |
223 | test_distance_result_box<double, double, D, double>(); | |
7c673cae FG |
224 | } |
225 | ||
226 | //========================================================================= | |
227 | ||
228 | BOOST_AUTO_TEST_CASE( test_point_point_or_point_segment ) | |
229 | { | |
230 | test_segment_all<2, bg::cs::cartesian>(); | |
231 | test_segment_all<3, bg::cs::cartesian>(); | |
232 | test_segment_all<4, bg::cs::cartesian>(); | |
233 | test_segment_all<2, bg::cs::spherical_equatorial<bg::degree> >(); | |
234 | } | |
235 | ||
236 | BOOST_AUTO_TEST_CASE( test_point_box_or_box ) | |
237 | { | |
238 | test_box_all<2>(); | |
239 | test_box_all<3>(); | |
240 | test_box_all<4>(); | |
241 | } |