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 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
9 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
10 
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)
14 
15 
16 #include <geometry_test_common.hpp>
17 
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>
21 
22 
23 #include <boost/geometry/algorithms/make.hpp>
24 #include <boost/geometry/algorithms/transform.hpp>
25 
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>
29 
30 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)31 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
32 
33 
34 template <typename P, typename T>
35 void check_inverse(P const& p, T const& trans)
36 {
37     typedef typename bg::coordinate_type<P>::type coordinate_type;
38     const std::size_t dim = bg::dimension<P>::value;
39 
40     bg::strategy::transform::inverse_transformer<coordinate_type, dim, dim> inverse(trans);
41 
42     P i;
43     bg::transform(p, i, inverse);
44 
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);
47 }
48 
49 template <typename P>
test_all()50 void test_all()
51 {
52     typedef typename bg::coordinate_type<P>::type coordinate_type;
53     const std::size_t dim = bg::dimension<P>::value;
54 
55     P p;
56     bg::assign_values(p, 1, 1);
57 
58     {
59         bg::strategy::transform::translate_transformer<coordinate_type, dim, dim> trans(1, 1);
60         P tp;
61         bg::transform(p, tp, trans);
62 
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);
65 
66         check_inverse(tp, trans);
67     }
68 
69     {
70         bg::strategy::transform::scale_transformer<coordinate_type, dim, dim> trans(10, 10);
71         P tp;
72         bg::transform(p, tp, trans);
73 
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);
76 
77         check_inverse(tp, trans);
78     }
79 
80     {
81         bg::strategy::transform::rotate_transformer<bg::degree, double, dim, dim> trans(90.0);
82         P tp;
83         bg::transform(p, tp, trans);
84 
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);
88     }
89 
90     {
91         // Map from 0,0,2,2 to 0,0,500,500
92         bg::strategy::transform::map_transformer<coordinate_type, dim, dim, false> trans
93             (
94                 0.0, 0.0, 2.0, 2.0, 500, 500
95             );
96         P tp;
97         bg::transform(p, tp, trans);
98 
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);
101 
102         check_inverse(tp, trans);
103     }
104 }
105 
test_main(int,char * [])106 int test_main(int, char* [])
107 {
108     //test_all<int[2]>();
109     //test_all<float[2]>();
110     //test_all<double[2]>();
111 
112     test_all<boost::tuple<float, float> >();
113 
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> >();
117 
118     return 0;
119 }
120