1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2019 Tinko Bartels
5
6 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
7 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
8
9 // Use, modification and distribution is subject to the Boost Software License,
10 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
12
13
14 #include <geometry_test_common.hpp>
15
16 #include <boost/geometry/strategies/transform/matrix_transformers.hpp>
17 #include <boost/geometry/algorithms/transform.hpp>
18 #include <boost/geometry/geometries/point.hpp>
19
20 template <typename coordinate_type>
test_all()21 void test_all()
22 {
23 typedef bg::model::point<coordinate_type, 2, bg::cs::cartesian> point_2d;
24 typedef bg::model::point<coordinate_type, 3, bg::cs::cartesian> point_3d;
25 typedef bg::model::point<coordinate_type, 4, bg::cs::cartesian> point_4d;
26
27 point_2d p2d;
28 point_3d p3d;
29 point_4d p4d;
30
31 bg::assign_values(p2d, 3, 5);
32
33 boost::qvm::mat<coordinate_type, 5, 3> mat24;
34 boost::qvm::A<0, 0>(mat24) = 1; boost::qvm::A<0, 1>(mat24) = 0; boost::qvm::A<0, 2>(mat24) = 0;
35 boost::qvm::A<1, 0>(mat24) = 0; boost::qvm::A<1, 1>(mat24) = 1; boost::qvm::A<1, 2>(mat24) = 0;
36 boost::qvm::A<2, 0>(mat24) = 1; boost::qvm::A<2, 1>(mat24) = -1; boost::qvm::A<2, 2>(mat24) = 0;
37 boost::qvm::A<3, 0>(mat24) = -1; boost::qvm::A<3, 1>(mat24) = 1; boost::qvm::A<3, 2>(mat24) = 0;
38 boost::qvm::A<4, 0>(mat24) = 0; boost::qvm::A<4, 1>(mat24) = 0; boost::qvm::A<4, 2>(mat24) = 1;
39 bg::strategy::transform::matrix_transformer<coordinate_type, 2, 4> trans24(mat24);
40 bg::transform(p2d, p4d, trans24);
41
42 BOOST_CHECK_CLOSE(double(bg::get<0>(p4d)), 3.0, 0.001);
43 BOOST_CHECK_CLOSE(double(bg::get<1>(p4d)), 5.0, 0.001);
44 BOOST_CHECK_CLOSE(double(bg::get<2>(p4d)), -2.0, 0.001);
45 BOOST_CHECK_CLOSE(double(bg::get<3>(p4d)), 2.0, 0.001);
46
47 bg::strategy::transform::scale_transformer<coordinate_type, 4, 4> scale44(2);
48 bg::transform(p4d, p4d, scale44);
49
50 BOOST_CHECK_CLOSE(double(bg::get<0>(p4d)), 6.0, 0.001);
51 BOOST_CHECK_CLOSE(double(bg::get<1>(p4d)), 10.0, 0.001);
52 BOOST_CHECK_CLOSE(double(bg::get<2>(p4d)), -4.0, 0.001);
53 BOOST_CHECK_CLOSE(double(bg::get<3>(p4d)), 4.0, 0.001);
54
55 boost::qvm::mat<coordinate_type, 4, 5> mat43;
56 boost::qvm::A<0, 0>(mat43) = 0 ; boost::qvm::A<0, 1>(mat43) = 0; boost::qvm::A<0, 2>(mat43) = 0.5; boost::qvm::A<0, 3>(mat43) = 0 ; boost::qvm::A<0, 4>(mat43) = 0;
57 boost::qvm::A<1, 0>(mat43) = 0.5; boost::qvm::A<1, 1>(mat43) = 0; boost::qvm::A<1, 2>(mat43) = 0 ; boost::qvm::A<1, 3>(mat43) = 0 ; boost::qvm::A<1, 4>(mat43) = 0;
58 boost::qvm::A<2, 0>(mat43) = 0 ; boost::qvm::A<2, 1>(mat43) = 0; boost::qvm::A<2, 2>(mat43) = 0 ; boost::qvm::A<2, 3>(mat43) = 0.5; boost::qvm::A<2, 4>(mat43) = 0;
59 boost::qvm::A<3, 0>(mat43) = 0 ; boost::qvm::A<3, 1>(mat43) = 0; boost::qvm::A<3, 2>(mat43) = 0 ; boost::qvm::A<3, 3>(mat43) = 0 ; boost::qvm::A<3, 4>(mat43) = 1;
60 bg::strategy::transform::matrix_transformer<coordinate_type, 4, 3> trans43(mat43);
61 bg::transform(p4d, p3d, trans43);
62
63 BOOST_CHECK_CLOSE(double(bg::get<0>(p3d)), -2.0, 0.001);
64 BOOST_CHECK_CLOSE(double(bg::get<1>(p3d)), 3.0, 0.001);
65 BOOST_CHECK_CLOSE(double(bg::get<2>(p3d)), 2.0, 0.001);
66
67 bg::strategy::transform::matrix_transformer<coordinate_type, 3, 3> trans33(1, 0, 0, 0,
68 0, 0, 1, 0,
69 0, 1, 0, 0,
70 0, 0, 0, 1);
71 bg::transform(p3d, p3d, trans33);
72
73 BOOST_CHECK_CLOSE(double(bg::get<0>(p3d)), -2.0, 0.001);
74 BOOST_CHECK_CLOSE(double(bg::get<1>(p3d)), 2.0, 0.001);
75 BOOST_CHECK_CLOSE(double(bg::get<2>(p3d)), 3.0, 0.001);
76
77 boost::qvm::mat<coordinate_type, 3, 4> mat32;
78 boost::qvm::A<0, 0>(mat32) = 1; boost::qvm::A<0, 1>(mat32) = 1; boost::qvm::A<0, 2>(mat32) = 1; boost::qvm::A<0, 3>(mat32) = 0;
79 boost::qvm::A<1, 0>(mat32) = -1; boost::qvm::A<1, 1>(mat32) = 0; boost::qvm::A<1, 2>(mat32) = 1; boost::qvm::A<1, 3>(mat32) = 0;
80 boost::qvm::A<2, 0>(mat32) = 0; boost::qvm::A<2, 1>(mat32) = 0; boost::qvm::A<2, 2>(mat32) = 0; boost::qvm::A<2, 3>(mat32) = 1;
81
82 bg::strategy::transform::matrix_transformer<coordinate_type, 3, 2> trans32(mat32);
83 bg::transform(p3d, p2d, trans32);
84
85 BOOST_CHECK_CLOSE(double(bg::get<0>(p2d)), 3.0, 0.001);
86 BOOST_CHECK_CLOSE(double(bg::get<1>(p2d)), 5.0, 0.001);
87
88 bg::strategy::transform::matrix_transformer<coordinate_type, 2, 2>
89 trans_composed(
90 trans32.matrix() * trans33.matrix() * trans43.matrix() * scale44.matrix() * trans24.matrix());
91 bg::transform(p2d, p2d, trans_composed);
92
93 BOOST_CHECK_CLOSE(double(bg::get<0>(p2d)), 3.0, 0.001);
94 BOOST_CHECK_CLOSE(double(bg::get<1>(p2d)), 5.0, 0.001);
95 }
96
test_main(int,char * [])97 int test_main(int, char* [])
98 {
99 test_all<float>();
100 test_all<double>();
101
102 return 0;
103 }
104