]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/strategies/test_projected_point.hpp
import quincy beta 17.1.0
[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 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
40 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
41
42
43 template <typename P, typename PS, typename CalculationType>
44 void test_services()
45 {
46 PS p1, p2;
47 bg::assign_values(p1, 0, 0);
48 bg::assign_values(p2, 0, 4);
49
50 P p;
51 bg::assign_values(p, 2, 0);
52
53 CalculationType const sqr_expected = 4;
54 CalculationType const expected = 2;
55
56
57 namespace bgsd = bg::strategy::distance;
58 namespace services = bg::strategy::distance::services;
59
60 {
61 // compile-check if there is a strategy for this type
62 typedef typename services::default_strategy
63 <
64 bg::point_tag, bg::segment_tag, P, PS
65 >::type projected_point_strategy_type;
66
67 typedef typename services::default_strategy
68 <
69 bg::segment_tag, bg::point_tag, PS, P
70 >::type reversed_tags_projected_point_strategy_type;
71
72 boost::ignore_unused<projected_point_strategy_type,
73 reversed_tags_projected_point_strategy_type>();
74 }
75
76 // 1: normal, calculate distance:
77
78 typedef bgsd::projected_point<CalculationType> strategy_type;
79
80 BOOST_CONCEPT_ASSERT( (bg::concepts::PointSegmentDistanceStrategy<strategy_type, P, PS>) );
81
82 typedef typename services::return_type<strategy_type, P, PS>::type return_type;
83
84 strategy_type strategy;
85 return_type result = strategy.apply(p, p1, p2);
86 BOOST_CHECK_CLOSE(result, return_type(expected), 0.001);
87
88 // 2: the strategy should return the same result if we reverse parameters
89 result = strategy.apply(p, p2, p1);
90 BOOST_CHECK_CLOSE(result, return_type(expected), 0.001);
91
92
93 // 3: "comparable" to construct a "comparable strategy" for P1/P2
94 // a "comparable strategy" is a strategy which does not calculate the exact distance, but
95 // which returns results which can be mutually compared (e.g. avoid sqrt)
96
97 // 3a: "comparable_type"
98 typedef typename services::comparable_type<strategy_type>::type comparable_type;
99
100 // 3b: "get_comparable"
101 comparable_type comparable = bgsd::services::get_comparable<strategy_type>::apply(strategy);
102
103 return_type c_result = comparable.apply(p, p1, p2);
104 BOOST_CHECK_CLOSE(c_result, return_type(sqr_expected), 0.001);
105 }
106
107 template <typename T1, typename T2>
108 void test_check_close(T1 const& v1, T2 const& v2, double f)
109 {
110 BOOST_CHECK_CLOSE(v1, v2, f);
111 }
112
113 template <typename T1, typename T2>
114 void test_check_close(bg::strategy::distance::detail::projected_point_ax_result<T1> const& v1,
115 bg::strategy::distance::detail::projected_point_ax_result<T2> const& v2,
116 double f)
117 {
118 BOOST_CHECK_CLOSE(v1.atd, v2.atd, f);
119 BOOST_CHECK_CLOSE(v1.xtd, v2.xtd, f);
120 }
121
122 template <typename P1, typename P2, typename T, typename Strategy, typename ComparableStrategy>
123 void test_2d(std::string const& wkt_p,
124 std::string const& wkt_sp1,
125 std::string const& wkt_sp2,
126 T expected_distance,
127 T expected_comparable_distance,
128 Strategy strategy,
129 ComparableStrategy comparable_strategy)
130 {
131 P1 p;
132 P2 sp1, sp2;
133 bg::read_wkt(wkt_p, p);
134 bg::read_wkt(wkt_sp1, sp1);
135 bg::read_wkt(wkt_sp2, sp2);
136
137 BOOST_CONCEPT_ASSERT
138 (
139 (bg::concepts::PointSegmentDistanceStrategy<Strategy, P1, P2>)
140 );
141 BOOST_CONCEPT_ASSERT
142 (
143 (bg::concepts::PointSegmentDistanceStrategy<ComparableStrategy, P1, P2>)
144 );
145
146 {
147 typedef typename bg::strategy::distance::services::return_type<Strategy, P1, P2>::type return_type;
148 return_type d = strategy.apply(p, sp1, sp2);
149 test_check_close(d, expected_distance, 0.001);
150 }
151
152 // Test combination with the comparable strategy
153 {
154 typedef typename bg::strategy::distance::services::return_type<ComparableStrategy, P1, P2>::type return_type;
155 return_type d = comparable_strategy.apply(p, sp1, sp2);
156 test_check_close(d, expected_comparable_distance, 0.01);
157 }
158
159 }
160
161 template <typename P1, typename P2, typename T>
162 void test_2d(std::string const& wkt_p,
163 std::string const& wkt_sp1,
164 std::string const& wkt_sp2,
165 T expected_distance)
166 {
167 typedef bg::strategy::distance::projected_point<> strategy_type;
168 typedef bg::strategy::distance::projected_point
169 <
170 void,
171 bg::strategy::distance::comparable::pythagoras<>
172 > comparable_strategy_type;
173
174 strategy_type strategy;
175 comparable_strategy_type comparable_strategy;
176
177 T expected_squared_distance = expected_distance * expected_distance;
178 test_2d<P1, P2>(wkt_p, wkt_sp1, wkt_sp2, expected_distance, expected_squared_distance, strategy, comparable_strategy);
179 }
180
181 #endif // BOOST_GEOMETRY_TEST_STRATEGIES_TEST_PROJECTED_POINT_HPP