]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/test/strategies/transformer.cpp
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)
16 #include <geometry_test_common.hpp>
18 #include <boost/geometry/strategies/transform/inverse_transformer.hpp>
19 #include <boost/geometry/strategies/transform/map_transformer.hpp>
20 #include <boost/geometry/strategies/transform/matrix_transformers.hpp>
23 #include <boost/geometry/algorithms/make.hpp>
24 #include <boost/geometry/algorithms/transform.hpp>
26 #include <boost/geometry/geometries/point.hpp>
27 #include <boost/geometry/geometries/adapted/c_array.hpp>
28 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
30 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian
)
31 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian
)
34 template <typename P
, typename T
>
35 void check_inverse(P
const& p
, T
const& trans
)
37 typedef typename
bg::coordinate_type
<P
>::type coordinate_type
;
38 const std::size_t dim
= bg::dimension
<P
>::value
;
40 bg::strategy::transform::inverse_transformer
<coordinate_type
, dim
, dim
> inverse(trans
);
43 bg::transform(p
, i
, inverse
);
45 BOOST_CHECK_CLOSE(double(bg::get
<0>(i
)), 1.0, 0.001);
46 BOOST_CHECK_CLOSE(double(bg::get
<1>(i
)), 1.0, 0.001);
52 typedef typename
bg::coordinate_type
<P
>::type coordinate_type
;
53 const std::size_t dim
= bg::dimension
<P
>::value
;
56 bg::assign_values(p
, 1, 1);
59 bg::strategy::transform::translate_transformer
<coordinate_type
, dim
, dim
> trans(1, 1);
61 bg::transform(p
, tp
, trans
);
63 BOOST_CHECK_CLOSE(double(bg::get
<0>(tp
)), 2.0, 0.001);
64 BOOST_CHECK_CLOSE(double(bg::get
<1>(tp
)), 2.0, 0.001);
66 check_inverse(tp
, trans
);
70 bg::strategy::transform::scale_transformer
<coordinate_type
, dim
, dim
> trans(10, 10);
72 bg::transform(p
, tp
, trans
);
74 BOOST_CHECK_CLOSE(double(bg::get
<0>(tp
)), 10.0, 0.001);
75 BOOST_CHECK_CLOSE(double(bg::get
<1>(tp
)), 10.0, 0.001);
77 check_inverse(tp
, trans
);
81 bg::strategy::transform::rotate_transformer
<bg::degree
, double, dim
, dim
> trans(90.0);
83 bg::transform(p
, tp
, trans
);
85 BOOST_CHECK_CLOSE(double(bg::get
<0>(tp
)), 1.0, 0.001);
86 BOOST_CHECK_CLOSE(double(bg::get
<1>(tp
)), -1.0, 0.001);
87 check_inverse(tp
, trans
);
91 // Map from 0,0,2,2 to 0,0,500,500
92 bg::strategy::transform::map_transformer
<coordinate_type
, dim
, dim
, false> trans
94 0.0, 0.0, 2.0, 2.0, 500, 500
97 bg::transform(p
, tp
, trans
);
99 BOOST_CHECK_CLOSE(double(bg::get
<0>(tp
)), 250.0, 0.001);
100 BOOST_CHECK_CLOSE(double(bg::get
<1>(tp
)), 250.0, 0.001);
102 check_inverse(tp
, trans
);
106 int test_main(int, char* [])
108 //test_all<int[2]>();
109 //test_all<float[2]>();
110 //test_all<double[2]>();
112 test_all
<boost::tuple
<float, float> >();
114 //test_all<point<int, 2, cs::cartesian> >();
115 test_all
<bg::model::point
<float, 2, bg::cs::cartesian
> >();
116 test_all
<bg::model::point
<double, 2, bg::cs::cartesian
> >();