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 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
9 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
19 #include <geometry_test_common.hpp>
21 #include <boost/geometry/algorithms/equals.hpp>
22 #include <boost/geometry/algorithms/make.hpp>
23 #include <boost/geometry/algorithms/transform.hpp>
24 #include <boost/geometry/geometries/geometries.hpp>
25 #include <boost/geometry/geometries/point_xy.hpp>
26 #include <boost/geometry/io/wkt/wkt.hpp>
27 #include <boost/geometry/strategies/strategies.hpp>
28 #include <boost/variant/variant.hpp>
30 #include <test_common/test_point.hpp>
32 template <typename Geometry1
, typename Geometry2
>
33 void check_transform(Geometry1
const& geometry1
,
34 Geometry2
const& expected
)
37 BOOST_CHECK(bg::transform(geometry1
, geometry2
));
39 std::ostringstream result_wkt
, expected_wkt
;
40 result_wkt
<< bg::wkt(geometry2
);
41 expected_wkt
<< bg::wkt(expected
);
42 BOOST_CHECK_EQUAL(result_wkt
.str(), expected_wkt
.str());
45 template <typename P1
, typename P2
, typename Value
>
46 void test_transform_point(Value value
)
51 boost::variant
<P1
> v(p1
);
54 bg::assign(expected
, p1
);
55 bg::multiply_value(expected
, value
);
57 check_transform(p1
, expected
);
58 check_transform(v
, expected
);
61 template <typename P1
, typename P2
, typename Value
>
62 void test_transform_linestring(Value value
)
64 typedef bg::model::linestring
<P1
> line1_type
;
65 typedef bg::model::linestring
<P2
> line2_type
;
68 line1
.push_back(bg::make
<P1
>(1, 1));
69 line1
.push_back(bg::make
<P1
>(2, 2));
70 boost::variant
<line1_type
> v(line1
);
73 for (BOOST_AUTO(p
, line1
.begin()); p
!= line1
.end(); ++p
)
76 bg::assign(new_point
, *p
);
77 bg::multiply_value(new_point
, value
);
78 expected
.push_back(new_point
);
81 check_transform(line1
, expected
);
82 check_transform(v
, expected
);
86 template <typename P1
, typename P2
, typename Value
>
87 void test_all(Value value
)
89 test_transform_point
<P1
, P2
>(value
);
90 test_transform_linestring
<P1
, P2
>(value
);
93 template <typename T
, typename DegreeOrRadian
>
94 void test_transformations(double phi
, double theta
, double r
)
96 typedef bg::model::point
<T
, 3, bg::cs::cartesian
> cartesian_type
;
99 // 1: using spherical coordinates
101 typedef bg::model::point
<T
, 3, bg::cs::spherical
<DegreeOrRadian
> > spherical_type
;
103 assign_values(sph1
, phi
, theta
, r
);
104 BOOST_CHECK(transform(sph1
, p
));
107 BOOST_CHECK(transform(p
, sph2
));
109 BOOST_CHECK_CLOSE(bg::get
<0>(sph1
), bg::get
<0>(sph2
), 0.001);
110 BOOST_CHECK_CLOSE(bg::get
<1>(sph1
), bg::get
<1>(sph2
), 0.001);
113 // 2: using spherical coordinates on unit sphere
115 typedef bg::model::point
<T
, 2, bg::cs::spherical
<DegreeOrRadian
> > spherical_type
;
116 spherical_type sph1
, sph2
;
117 assign_values(sph1
, phi
, theta
);
118 BOOST_CHECK(transform(sph1
, p
));
119 BOOST_CHECK(transform(p
, sph2
));
121 BOOST_CHECK_CLOSE(bg::get
<0>(sph1
), bg::get
<0>(sph2
), 0.001);
122 BOOST_CHECK_CLOSE(bg::get
<1>(sph1
), bg::get
<1>(sph2
), 0.001);
126 int test_main(int, char* [])
128 typedef bg::model::d2::point_xy
<double > P
;
130 test_all
<bg::model::d2::point_xy
<int>, bg::model::d2::point_xy
<float> >(1.0);
132 test_all
<bg::model::point
<double, 2, bg::cs::spherical
<bg::degree
> >,
133 bg::model::point
<double, 2, bg::cs::spherical
<bg::radian
> > >(bg::math::d2r
<double>());
134 test_all
<bg::model::point
<double, 2, bg::cs::spherical
<bg::radian
> >,
135 bg::model::point
<double, 2, bg::cs::spherical
<bg::degree
> > >(bg::math::r2d
<double>());
137 test_all
<bg::model::point
<int, 2, bg::cs::spherical
<bg::degree
> >,
138 bg::model::point
<float, 2, bg::cs::spherical
<bg::radian
> > >(bg::math::d2r
<float>());
140 test_transformations
<float, bg::degree
>(4, 52, 1);
141 test_transformations
<double, bg::degree
>(4, 52, 1);
146 >(3 * bg::math::d2r
<float>(), 51 * bg::math::d2r
<float>(), 1);
151 >(3 * bg::math::d2r
<double>(), 51 * bg::math::d2r
<double>(), 1);
153 #if defined(HAVE_TTMATH)
154 typedef bg::model::d2::point_xy
<ttmath_big
> PT
;
156 test_transformations
<ttmath_big
, bg::degree
>(4, 52, 1);
159 ttmath_big
, bg::radian
160 >(3 * bg::math::d2r
<ttmath_big
>(), 51 * bg::math::d2r
<ttmath_big
>(), 1);