1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
8 // Use, modification and distribution is subject to the Boost Software License,
9 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10 // http://www.boost.org/LICENSE_1_0.txt)
13 #include <geometry_test_common.hpp>
15 #include <boost/geometry/geometries/geometries.hpp>
16 #include <boost/geometry/util/calculation_type.hpp>
18 template <typename G1, typename G2>
19 inline std::string helper()
22 result += typeid(typename bg::coordinate_type<G1>::type).name();
24 result += typeid(typename bg::coordinate_type<G2>::type).name();
28 template <typename G1, typename G2, typename G3>
29 inline std::string helper3()
32 result += typeid(typename bg::coordinate_type<G1>::type).name();
34 result += typeid(typename bg::coordinate_type<G2>::type).name();
36 result += typeid(typename bg::coordinate_type<G3>::type).name();
50 typedef typename bg::util::calculation_type::geometric::binary
59 std::string const caption = helper<G1, G2>();
61 BOOST_CHECK_MESSAGE((boost::is_same<type, ExpectedType>::type::value),
62 "Failure, types do not agree;"
63 << " input: " << caption
64 << " defaults: " << typeid(DefaultFP).name()
65 << "/" << typeid(DefaultInt).name()
66 << " expected: " << typeid(ExpectedType).name()
67 << " detected: " << typeid(type).name()
75 typename CalculationType,
78 void test_with_calculation_type()
80 typedef typename bg::util::calculation_type::geometric::binary
89 std::string const caption = helper<G1, G2>();
91 BOOST_CHECK_MESSAGE((boost::is_same<type, ExpectedType>::type::value),
92 "Failure, types do not agree;"
93 << " input: " << caption
94 << " calculation type: " << typeid(CalculationType).name()
95 << " expected: " << typeid(ExpectedType).name()
96 << " detected: " << typeid(type).name()
105 typename ExpectedType
109 typedef typename bg::util::calculation_type::geometric::unary
117 BOOST_CHECK_MESSAGE((boost::is_same<type, ExpectedType>::type::value),
118 "Failure, types do not agree;"
119 << " input: " << typeid(typename bg::coordinate_type<Geometry>::type).name()
120 << " defaults: " << typeid(DefaultFP).name()
121 << "/" << typeid(DefaultInt).name()
122 << " expected: " << typeid(ExpectedType).name()
123 << " detected: " << typeid(type).name()
135 typename ExpectedType
139 typedef typename bg::util::calculation_type::geometric::ternary
149 std::string const caption = helper3<G1, G2, G3>();
151 BOOST_CHECK_MESSAGE((boost::is_same<type, ExpectedType>::type::value),
152 "Failure, types do not agree;"
153 << " input: " << caption
154 << " defaults: " << typeid(DefaultFP).name()
155 << "/" << typeid(DefaultInt).name()
156 << " expected: " << typeid(ExpectedType).name()
157 << " detected: " << typeid(type).name()
162 struct user_defined {};
164 int test_main(int, char* [])
166 using namespace boost::geometry;
167 typedef model::point<double, 2, cs::cartesian> d;
168 typedef model::point<float, 2, cs::cartesian> f;
169 typedef model::point<int, 2, cs::cartesian> i;
170 typedef model::point<char, 2, cs::cartesian> c;
171 typedef model::point<short int, 2, cs::cartesian> s;
172 typedef model::point<boost::long_long_type, 2, cs::cartesian> ll;
173 typedef model::point<user_defined, 2, cs::cartesian> u;
175 // Calculation type "void" so
176 test<f, f, double, int, double>();
177 test<d, d, double, int, double>();
178 test<f, d, double, int, double>();
181 test<i, f, double, int, double>();
182 test<s, f, double, short int, double>();
185 test<s, s, double, short int, short int>();
186 test<i, i, double, int, int>();
187 test<c, i, double, int, int>();
188 test<c, c, double, char, char>();
189 test<c, c, double, int, int>();
190 test<i, i, double, boost::long_long_type, boost::long_long_type>();
192 // Even if we specify "int" as default-calculation-type, it should never go downwards.
193 // So it will select "long long"
194 test<ll, ll, double, int, boost::long_long_type>();
197 test<u, i, double, char, user_defined>();
198 test<u, d, double, double, user_defined>();
200 test_with_calculation_type<i, i, double, double>();
201 test_with_calculation_type<u, u, double, double>();
203 test_unary<i, double, int, int>();
204 test_unary<u, double, double, user_defined>();
205 test_ternary<u, u, u, double, double, user_defined>();