1// Boost.Geometry (aka GGL, Generic Geometry Library)
2// Unit Test
3
4// Copyright (c) 2012 Barend Gehrels, Amsterdam, the Netherlands.
5// Copyright (c) 2012 Bruno Lalande, Paris, France.
6// Copyright (c) 2012 Mateusz Loskot, London, UK.
7
8// This file was modified by Oracle on 2021.
9// Modifications copyright (c) 2021, Oracle and/or its affiliates.
10// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
11
12// Use, modification and distribution is subject to the Boost Software License,
13// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
14// http://www.boost.org/LICENSE_1_0.txt)
15
16
17#include <geometry_test_common.hpp>
18
19#include <boost/geometry/geometries/geometries.hpp>
20#include <boost/geometry/util/calculation_type.hpp>
21
22template <typename G1, typename G2>
23inline std::string helper()
24{
25 std::string result;
26 result += typeid(typename bg::coordinate_type<G1>::type).name();
27 result += "/";
28 result += typeid(typename bg::coordinate_type<G2>::type).name();
29 return result;
30}
31
32template <typename G1, typename G2, typename G3>
33inline std::string helper3()
34{
35 std::string result;
36 result += typeid(typename bg::coordinate_type<G1>::type).name();
37 result += "/";
38 result += typeid(typename bg::coordinate_type<G2>::type).name();
39 result += "/";
40 result += typeid(typename bg::coordinate_type<G3>::type).name();
41 return result;
42}
43
44template
45<
46 typename G1,
47 typename G2,
48 typename DefaultFP,
49 typename DefaultInt,
50 typename ExpectedType
51>
52void test()
53{
54 typedef typename bg::util::calculation_type::geometric::binary
55 <
56 G1,
57 G2,
58 void,
59 DefaultFP,
60 DefaultInt
61 >::type type;
62
63 std::string const caption = helper<G1, G2>();
64
65 BOOST_CHECK_MESSAGE((std::is_same<type, ExpectedType>::value),
66 "Failure, types do not agree;"
67 << " input: " << caption
68 << " defaults: " << typeid(DefaultFP).name()
69 << "/" << typeid(DefaultInt).name()
70 << " expected: " << typeid(ExpectedType).name()
71 << " detected: " << typeid(type).name()
72 );
73}
74
75template
76<
77 typename G1,
78 typename G2,
79 typename CalculationType,
80 typename ExpectedType
81>
82void test_with_calculation_type()
83{
84 typedef typename bg::util::calculation_type::geometric::binary
85 <
86 G1,
87 G2,
88 CalculationType,
89 double,
90 int
91 >::type type;
92
93 std::string const caption = helper<G1, G2>();
94
95 BOOST_CHECK_MESSAGE((std::is_same<type, ExpectedType>::value),
96 "Failure, types do not agree;"
97 << " input: " << caption
98 << " calculation type: " << typeid(CalculationType).name()
99 << " expected: " << typeid(ExpectedType).name()
100 << " detected: " << typeid(type).name()
101 );
102}
103
104template
105<
106 typename Geometry,
107 typename DefaultFP,
108 typename DefaultInt,
109 typename ExpectedType
110>
111void test_unary()
112{
113 typedef typename bg::util::calculation_type::geometric::unary
114 <
115 Geometry,
116 void,
117 DefaultFP,
118 DefaultInt
119 >::type type;
120
121 BOOST_CHECK_MESSAGE((std::is_same<type, ExpectedType>::value),
122 "Failure, types do not agree;"
123 << " input: " << typeid(typename bg::coordinate_type<Geometry>::type).name()
124 << " defaults: " << typeid(DefaultFP).name()
125 << "/" << typeid(DefaultInt).name()
126 << " expected: " << typeid(ExpectedType).name()
127 << " detected: " << typeid(type).name()
128 );
129}
130
131
132template
133<
134 typename G1,
135 typename G2,
136 typename G3,
137 typename DefaultFP,
138 typename DefaultInt,
139 typename ExpectedType
140>
141void test_ternary()
142{
143 typedef typename bg::util::calculation_type::geometric::ternary
144 <
145 G1,
146 G2,
147 G3,
148 void,
149 DefaultFP,
150 DefaultInt
151 >::type type;
152
153 std::string const caption = helper3<G1, G2, G3>();
154
155 BOOST_CHECK_MESSAGE((std::is_same<type, ExpectedType>::value),
156 "Failure, types do not agree;"
157 << " input: " << caption
158 << " defaults: " << typeid(DefaultFP).name()
159 << "/" << typeid(DefaultInt).name()
160 << " expected: " << typeid(ExpectedType).name()
161 << " detected: " << typeid(type).name()
162 );
163}
164
165
166struct user_defined {};
167
168int test_main(int, char* [])
169{
170 using namespace boost::geometry;
171 typedef model::point<double, 2, cs::cartesian> d;
172 typedef model::point<float, 2, cs::cartesian> f;
173 typedef model::point<int, 2, cs::cartesian> i;
174 typedef model::point<char, 2, cs::cartesian> c;
175 typedef model::point<short int, 2, cs::cartesian> s;
176 typedef model::point<long long, 2, cs::cartesian> ll;
177 typedef model::point<user_defined, 2, cs::cartesian> u;
178
179 // Calculation type "void" so
180 test<f, f, double, int, double>();
181 test<d, d, double, int, double>();
182 test<f, d, double, int, double>();
183
184 // FP/int mixed
185 test<i, f, double, int, double>();
186 test<s, f, double, short int, double>();
187
188 // integers
189 test<s, s, double, short int, short int>();
190 test<i, i, double, int, int>();
191 test<c, i, double, int, int>();
192 test<c, c, double, char, char>();
193 test<c, c, double, int, int>();
194 test<i, i, double, long long, long long>();
195
196 // Even if we specify "int" as default-calculation-type, it should never go downwards.
197 // So it will select "long long"
198 test<ll, ll, double, int, long long>();
199
200 // user defined
201 test<u, i, double, char, user_defined>();
202 test<u, d, double, double, user_defined>();
203
204 test_with_calculation_type<i, i, double, double>();
205 test_with_calculation_type<u, u, double, double>();
206
207 test_unary<i, double, int, int>();
208 test_unary<u, double, double, user_defined>();
209 test_ternary<u, u, u, double, double, user_defined>();
210
211 return 0;
212}
213

source code of boost/libs/geometry/test/util/calculation_type.cpp