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
19 #include <boost/geometry/arithmetic/arithmetic.hpp>
20
21 #include <boost/geometry/algorithms/assign.hpp>
22
23 #include <boost/geometry/geometries/point.hpp>
24 #include <boost/geometry/geometries/adapted/c_array.hpp>
25 #include <boost/geometry/geometries/adapted/boost_tuple.hpp>
26 #include <test_common/test_point.hpp>
27
28 BOOST_GEOMETRY_REGISTER_C_ARRAY_CS(cs::cartesian)
BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)29 BOOST_GEOMETRY_REGISTER_BOOST_TUPLE_CS(cs::cartesian)
30
31
32 template <typename P, typename P2>
33 void test_addition()
34 {
35 P p1;
36 bg::assign_values(p1, 1, 2, 3);
37 bg::add_value(p1, 10);
38 BOOST_CHECK(bg::get<0>(p1) == 11);
39 BOOST_CHECK(bg::get<1>(p1) == 12);
40 BOOST_CHECK(bg::get<2>(p1) == 13);
41
42 P2 p2(4, 5, 6);
43 bg::add_point(p1, p2);
44 BOOST_CHECK(bg::get<0>(p1) == 15);
45 BOOST_CHECK(bg::get<1>(p1) == 17);
46 BOOST_CHECK(bg::get<2>(p1) == 19);
47 }
48
49 template <typename P, typename P2>
test_subtraction()50 void test_subtraction()
51 {
52 P p1;
53 bg::assign_values(p1, 1, 2, 3);
54 bg::subtract_value(p1, 10);
55 BOOST_CHECK(bg::get<0>(p1) == -9);
56 BOOST_CHECK(bg::get<1>(p1) == -8);
57 BOOST_CHECK(bg::get<2>(p1) == -7);
58
59 P2 p2(4, 6, 8);
60 bg::subtract_point(p1, p2);
61 BOOST_CHECK(bg::get<0>(p1) == -13);
62 BOOST_CHECK(bg::get<1>(p1) == -14);
63 BOOST_CHECK(bg::get<2>(p1) == -15);
64 }
65
66 template <typename P, typename P2>
test_multiplication()67 void test_multiplication()
68 {
69 P p1;
70 bg::assign_values(p1, 1, 2, 3);
71 bg::multiply_value(p1, 5);
72 BOOST_CHECK(bg::get<0>(p1) == 5);
73 BOOST_CHECK(bg::get<1>(p1) == 10);
74 BOOST_CHECK(bg::get<2>(p1) == 15);
75
76 P2 p2(4, 5, 6);
77 bg::multiply_point(p1, p2);
78 BOOST_CHECK(bg::get<0>(p1) == 20);
79 BOOST_CHECK(bg::get<1>(p1) == 50);
80 BOOST_CHECK(bg::get<2>(p1) == 90);
81 }
82
83 template <typename P, typename P2>
test_division()84 void test_division()
85 {
86 P p1;
87 bg::assign_values(p1, 50, 100, 150);
88 bg::divide_value(p1, 5);
89 BOOST_CHECK(bg::get<0>(p1) == 10);
90 BOOST_CHECK(bg::get<1>(p1) == 20);
91 BOOST_CHECK(bg::get<2>(p1) == 30);
92
93 P2 p2(2, 4, 6);
94 bg::divide_point(p1, p2);
95 BOOST_CHECK(bg::get<0>(p1) == 5);
96 BOOST_CHECK(bg::get<1>(p1) == 5);
97 BOOST_CHECK(bg::get<2>(p1) == 5);
98 }
99
100 template <typename P, typename P2>
test_assign()101 void test_assign()
102 {
103 P p1;
104 P2 p2(12, 34, 56);
105 bg::assign_values(p1, 12, 34, 56);
106 bg::assign_point(p1, p2);
107 BOOST_CHECK(bg::get<0>(p1) == 12);
108 BOOST_CHECK(bg::get<1>(p1) == 34);
109 BOOST_CHECK(bg::get<2>(p1) == 56);
110
111 bg::assign_value(p1, 78);
112 BOOST_CHECK(bg::get<0>(p1) == 78);
113 BOOST_CHECK(bg::get<1>(p1) == 78);
114 BOOST_CHECK(bg::get<2>(p1) == 78);
115 }
116
117
118 template <typename P>
test_all()119 void test_all()
120 {
121 typedef test::test_const_point P2;
122
123 test_addition<P, P2>();
124 test_subtraction<P, P2>();
125 test_multiplication<P, P2>();
126 test_division<P, P2>();
127 test_assign<P, P2>();
128 }
129
130
test_main(int,char * [])131 int test_main(int, char* [])
132 {
133 test_all<int[3]>();
134 test_all<float[3]>();
135 test_all<double[3]>();
136 test_all<test::test_point>();
137 test_all<bg::model::point<int, 3, bg::cs::cartesian> >();
138 test_all<bg::model::point<float, 3, bg::cs::cartesian> >();
139 test_all<bg::model::point<double, 3, bg::cs::cartesian> >();
140
141 return 0;
142 }
143