]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/algorithms/transform.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / transform.cpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
6 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
7
8 // This file was modified by Oracle on 2021.
9 // Modifications copyright (c) 2021, Oracle and/or its affiliates.
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
14
15 // Use, modification and distribution is subject to the Boost Software License,
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
18
19 #include <iostream>
20 #include <sstream>
21
22 #include <boost/variant/variant.hpp>
23
24 #include <geometry_test_common.hpp>
25
26 #include <boost/geometry/algorithms/equals.hpp>
27 #include <boost/geometry/algorithms/make.hpp>
28 #include <boost/geometry/algorithms/transform.hpp>
29 #include <boost/geometry/geometries/geometries.hpp>
30 #include <boost/geometry/geometries/point_xy.hpp>
31 #include <boost/geometry/io/wkt/wkt.hpp>
32 #include <boost/geometry/strategies/strategies.hpp>
33
34 #include <test_common/test_point.hpp>
35
36 template <typename Geometry1, typename Geometry2>
37 void check_transform(Geometry1 const& geometry1,
38 Geometry2 const& expected)
39 {
40 Geometry2 geometry2;
41 BOOST_CHECK(bg::transform(geometry1, geometry2));
42
43 std::ostringstream result_wkt, expected_wkt;
44 result_wkt << bg::wkt(geometry2);
45 expected_wkt << bg::wkt(expected);
46 BOOST_CHECK_EQUAL(result_wkt.str(), expected_wkt.str());
47 }
48
49 template <typename P1, typename P2, typename Value>
50 void test_transform_point(Value value)
51 {
52 P1 p1;
53 bg::set<0>(p1, 1);
54 bg::set<1>(p1, 2);
55 boost::variant<P1> v(p1);
56
57 P2 expected;
58 bg::assign(expected, p1);
59 bg::multiply_value(expected, value);
60
61 check_transform(p1, expected);
62 check_transform(v, expected);
63 }
64
65 template <typename P1, typename P2, typename Value>
66 void test_transform_linestring(Value value)
67 {
68 typedef bg::model::linestring<P1> line1_type;
69 typedef bg::model::linestring<P2> line2_type;
70
71 line1_type line1;
72 line1.push_back(bg::make<P1>(1, 1));
73 line1.push_back(bg::make<P1>(2, 2));
74 boost::variant<line1_type> v(line1);
75
76 line2_type expected;
77 for (auto it = line1.begin(); it != line1.end(); ++it)
78 {
79 P2 new_point;
80 bg::assign(new_point, *it);
81 bg::multiply_value(new_point, value);
82 expected.push_back(new_point);
83 }
84
85 check_transform(line1, expected);
86 check_transform(v, expected);
87 }
88
89
90 template <typename P1, typename P2, typename Value>
91 void test_all(Value value)
92 {
93 test_transform_point<P1, P2>(value);
94 test_transform_linestring<P1, P2>(value);
95 }
96
97 template <typename T, typename DegreeOrRadian>
98 void test_transformations(double phi, double theta, double r)
99 {
100 typedef bg::model::point<T, 3, bg::cs::cartesian> cartesian_type;
101 cartesian_type p;
102
103 // 1: using spherical coordinates
104 {
105 typedef bg::model::point<T, 3, bg::cs::spherical<DegreeOrRadian> > spherical_type;
106 spherical_type sph1;
107 assign_values(sph1, phi, theta, r);
108 BOOST_CHECK(transform(sph1, p));
109
110 spherical_type sph2;
111 BOOST_CHECK(transform(p, sph2));
112
113 BOOST_CHECK_CLOSE(bg::get<0>(sph1), bg::get<0>(sph2), 0.001);
114 BOOST_CHECK_CLOSE(bg::get<1>(sph1), bg::get<1>(sph2), 0.001);
115 }
116
117 // 2: using spherical coordinates on unit sphere
118 {
119 typedef bg::model::point<T, 2, bg::cs::spherical<DegreeOrRadian> > spherical_type;
120 spherical_type sph1, sph2;
121 assign_values(sph1, phi, theta);
122 BOOST_CHECK(transform(sph1, p));
123 BOOST_CHECK(transform(p, sph2));
124
125 BOOST_CHECK_CLOSE(bg::get<0>(sph1), bg::get<0>(sph2), 0.001);
126 BOOST_CHECK_CLOSE(bg::get<1>(sph1), bg::get<1>(sph2), 0.001);
127 }
128 }
129
130 int test_main(int, char* [])
131 {
132 typedef bg::model::d2::point_xy<double > P;
133 test_all<P, P>(1.0);
134 test_all<bg::model::d2::point_xy<int>, bg::model::d2::point_xy<float> >(1.0);
135
136 test_all<bg::model::point<double, 2, bg::cs::spherical<bg::degree> >,
137 bg::model::point<double, 2, bg::cs::spherical<bg::radian> > >(bg::math::d2r<double>());
138 test_all<bg::model::point<double, 2, bg::cs::spherical<bg::radian> >,
139 bg::model::point<double, 2, bg::cs::spherical<bg::degree> > >(bg::math::r2d<double>());
140
141 test_all<bg::model::point<int, 2, bg::cs::spherical<bg::degree> >,
142 bg::model::point<float, 2, bg::cs::spherical<bg::radian> > >(bg::math::d2r<float>());
143
144 test_transformations<float, bg::degree>(4, 52, 1);
145 test_transformations<double, bg::degree>(4, 52, 1);
146
147 test_transformations
148 <
149 float, bg::radian
150 >(3 * bg::math::d2r<float>(), 51 * bg::math::d2r<float>(), 1);
151
152 test_transformations
153 <
154 double, bg::radian
155 >(3 * bg::math::d2r<double>(), 51 * bg::math::d2r<double>(), 1);
156
157 return 0;
158 }