]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/strategies/test_projected_point.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / geometry / test / strategies / test_projected_point.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
6 // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
7
8 // This file was modified by Oracle on 2014.
9 // Modifications copyright (c) 2014, Oracle and/or its affiliates.
10
11 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
12 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
13
14 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
15 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
16
17 // Use, modification and distribution is subject to the Boost Software License,
18 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
19 // http://www.boost.org/LICENSE_1_0.txt)
20
21 #ifndef BOOST_GEOMETRY_TEST_STRATEGIES_TEST_PROJECTED_POINT_HPP
22 #define BOOST_GEOMETRY_TEST_STRATEGIES_TEST_PROJECTED_POINT_HPP
23
24 #include <geometry_test_common.hpp>
25
26 #include <boost/core/ignore_unused.hpp>
27
28 #include <boost/geometry/strategies/cartesian/distance_projected_point.hpp>
29 #include <boost/geometry/strategies/cartesian/distance_projected_point_ax.hpp>
30 #include <boost/geometry/strategies/concepts/distance_concept.hpp>
31
32 #include <boost/geometry/io/wkt/read.hpp>
33
34 #include <boost/geometry/geometries/point.hpp>
35 #include <boost/geometry/geometries/adapted/c_array.hpp>
36 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
37 #include <test_common/test_point.hpp>
38
39 #ifdef HAVE_TTMATH
40 # include <boost/geometry/extensions/contrib/ttmath_stub.hpp>
41 #endif
42
43 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
44 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
45
46
47 template <typename P, typename PS, typename CalculationType>
48 void test_services()
49 {
50 PS p1, p2;
51 bg::assign_values(p1, 0, 0);
52 bg::assign_values(p2, 0, 4);
53
54 P p;
55 bg::assign_values(p, 2, 0);
56
57 CalculationType const sqr_expected = 4;
58 CalculationType const expected = 2;
59
60
61 namespace bgsd = bg::strategy::distance;
62 namespace services = bg::strategy::distance::services;
63
64 {
65 // compile-check if there is a strategy for this type
66 typedef typename services::default_strategy
67 <
68 bg::point_tag, bg::segment_tag, P, PS
69 >::type projected_point_strategy_type;
70
71 typedef typename services::default_strategy
72 <
73 bg::segment_tag, bg::point_tag, PS, P
74 >::type reversed_tags_projected_point_strategy_type;
75
76 boost::ignore_unused<projected_point_strategy_type,
77 reversed_tags_projected_point_strategy_type>();
78 }
79
80 // 1: normal, calculate distance:
81
82 typedef bgsd::projected_point<CalculationType> strategy_type;
83
84 BOOST_CONCEPT_ASSERT( (bg::concepts::PointSegmentDistanceStrategy<strategy_type, P, PS>) );
85
86 typedef typename services::return_type<strategy_type, P, PS>::type return_type;
87
88 strategy_type strategy;
89 return_type result = strategy.apply(p, p1, p2);
90 BOOST_CHECK_CLOSE(result, return_type(expected), 0.001);
91
92 // 2: the strategy should return the same result if we reverse parameters
93 result = strategy.apply(p, p2, p1);
94 BOOST_CHECK_CLOSE(result, return_type(expected), 0.001);
95
96
97 // 3: "comparable" to construct a "comparable strategy" for P1/P2
98 // a "comparable strategy" is a strategy which does not calculate the exact distance, but
99 // which returns results which can be mutually compared (e.g. avoid sqrt)
100
101 // 3a: "comparable_type"
102 typedef typename services::comparable_type<strategy_type>::type comparable_type;
103
104 // 3b: "get_comparable"
105 comparable_type comparable = bgsd::services::get_comparable<strategy_type>::apply(strategy);
106
107 return_type c_result = comparable.apply(p, p1, p2);
108 BOOST_CHECK_CLOSE(c_result, return_type(sqr_expected), 0.001);
109 }
110
111 template <typename T1, typename T2>
112 void test_check_close(T1 const& v1, T2 const& v2, double f)
113 {
114 BOOST_CHECK_CLOSE(v1, v2, f);
115 }
116
117 template <typename T1, typename T2>
118 void test_check_close(bg::strategy::distance::detail::projected_point_ax_result<T1> const& v1,
119 bg::strategy::distance::detail::projected_point_ax_result<T2> const& v2,
120 double f)
121 {
122 BOOST_CHECK_CLOSE(v1.atd, v2.atd, f);
123 BOOST_CHECK_CLOSE(v1.xtd, v2.xtd, f);
124 }
125
126 template <typename P1, typename P2, typename T, typename Strategy, typename ComparableStrategy>
127 void test_2d(std::string const& wkt_p,
128 std::string const& wkt_sp1,
129 std::string const& wkt_sp2,
130 T expected_distance,
131 T expected_comparable_distance,
132 Strategy strategy,
133 ComparableStrategy comparable_strategy)
134 {
135 P1 p;
136 P2 sp1, sp2;
137 bg::read_wkt(wkt_p, p);
138 bg::read_wkt(wkt_sp1, sp1);
139 bg::read_wkt(wkt_sp2, sp2);
140
141 BOOST_CONCEPT_ASSERT
142 (
143 (bg::concepts::PointSegmentDistanceStrategy<Strategy, P1, P2>)
144 );
145 BOOST_CONCEPT_ASSERT
146 (
147 (bg::concepts::PointSegmentDistanceStrategy<ComparableStrategy, P1, P2>)
148 );
149
150 {
151 typedef typename bg::strategy::distance::services::return_type<Strategy, P1, P2>::type return_type;
152 return_type d = strategy.apply(p, sp1, sp2);
153 test_check_close(d, expected_distance, 0.001);
154 }
155
156 // Test combination with the comparable strategy
157 {
158 typedef typename bg::strategy::distance::services::return_type<ComparableStrategy, P1, P2>::type return_type;
159 return_type d = comparable_strategy.apply(p, sp1, sp2);
160 test_check_close(d, expected_comparable_distance, 0.01);
161 }
162
163 }
164
165 template <typename P1, typename P2, typename T>
166 void test_2d(std::string const& wkt_p,
167 std::string const& wkt_sp1,
168 std::string const& wkt_sp2,
169 T expected_distance)
170 {
171 typedef bg::strategy::distance::projected_point<> strategy_type;
172 typedef bg::strategy::distance::projected_point
173 <
174 void,
175 bg::strategy::distance::comparable::pythagoras<>
176 > comparable_strategy_type;
177
178 strategy_type strategy;
179 comparable_strategy_type comparable_strategy;
180
181 T expected_squared_distance = expected_distance * expected_distance;
182 test_2d<P1, P2>(wkt_p, wkt_sp1, wkt_sp2, expected_distance, expected_squared_distance, strategy, comparable_strategy);
183 }
184
185 #endif // BOOST_GEOMETRY_TEST_STRATEGIES_TEST_PROJECTED_POINT_HPP