1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
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
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
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)
22 #include <boost/variant/variant.hpp>
24 #include <geometry_test_common.hpp>
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>
34 #include <test_common/test_point.hpp>
36 template <typename Geometry1
, typename Geometry2
>
37 void check_transform(Geometry1
const& geometry1
,
38 Geometry2
const& expected
)
41 BOOST_CHECK(bg::transform(geometry1
, geometry2
));
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());
49 template <typename P1
, typename P2
, typename Value
>
50 void test_transform_point(Value value
)
55 boost::variant
<P1
> v(p1
);
58 bg::assign(expected
, p1
);
59 bg::multiply_value(expected
, value
);
61 check_transform(p1
, expected
);
62 check_transform(v
, expected
);
65 template <typename P1
, typename P2
, typename Value
>
66 void test_transform_linestring(Value value
)
68 typedef bg::model::linestring
<P1
> line1_type
;
69 typedef bg::model::linestring
<P2
> line2_type
;
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
);
77 for (auto it
= line1
.begin(); it
!= line1
.end(); ++it
)
80 bg::assign(new_point
, *it
);
81 bg::multiply_value(new_point
, value
);
82 expected
.push_back(new_point
);
85 check_transform(line1
, expected
);
86 check_transform(v
, expected
);
90 template <typename P1
, typename P2
, typename Value
>
91 void test_all(Value value
)
93 test_transform_point
<P1
, P2
>(value
);
94 test_transform_linestring
<P1
, P2
>(value
);
97 template <typename T
, typename DegreeOrRadian
>
98 void test_transformations(double phi
, double theta
, double r
)
100 typedef bg::model::point
<T
, 3, bg::cs::cartesian
> cartesian_type
;
103 // 1: using spherical coordinates
105 typedef bg::model::point
<T
, 3, bg::cs::spherical
<DegreeOrRadian
> > spherical_type
;
107 assign_values(sph1
, phi
, theta
, r
);
108 BOOST_CHECK(transform(sph1
, p
));
111 BOOST_CHECK(transform(p
, sph2
));
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);
117 // 2: using spherical coordinates on unit sphere
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
));
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);
130 int test_main(int, char* [])
132 typedef bg::model::d2::point_xy
<double > P
;
134 test_all
<bg::model::d2::point_xy
<int>, bg::model::d2::point_xy
<float> >(1.0);
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>());
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>());
144 test_transformations
<float, bg::degree
>(4, 52, 1);
145 test_transformations
<double, bg::degree
>(4, 52, 1);
150 >(3 * bg::math::d2r
<float>(), 51 * bg::math::d2r
<float>(), 1);
155 >(3 * bg::math::d2r
<double>(), 51 * bg::math::d2r
<double>(), 1);