]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
3 | // Copyright (c) 2012 Barend Gehrels, Amsterdam, the Netherlands. | |
4 | // Copyright (c) 2012 Bruno Lalande, Paris, France. | |
5 | // Copyright (c) 2012 Mateusz Loskot, London, UK. | |
6 | ||
20effc67 TL |
7 | // This file was modified by Oracle on 2018-2020. |
8 | // Modifications copyright (c) 2018-2020, Oracle and/or its affiliates. | |
92f5a8d4 TL |
9 | |
10 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle | |
11 | ||
7c673cae FG |
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 | #ifndef BOOST_GEOMETRY_UTIL_CALCULATION_TYPE_HPP | |
17 | #define BOOST_GEOMETRY_UTIL_CALCULATION_TYPE_HPP | |
18 | ||
20effc67 | 19 | |
92f5a8d4 | 20 | #include <boost/static_assert.hpp> |
7c673cae FG |
21 | |
22 | #include <boost/geometry/util/select_coordinate_type.hpp> | |
23 | #include <boost/geometry/util/select_most_precise.hpp> | |
24 | ||
25 | ||
26 | namespace boost { namespace geometry | |
27 | { | |
28 | ||
29 | namespace util | |
30 | { | |
31 | ||
32 | namespace detail | |
33 | { | |
34 | ||
35 | struct default_integral | |
36 | { | |
20effc67 | 37 | typedef long long type; |
7c673cae FG |
38 | }; |
39 | ||
40 | /*! | |
41 | \details Selects the most appropriate: | |
42 | - if calculation type is specified (not void), that one is used | |
20effc67 | 43 | - else if type is non-fundamental (user defined e.g. Boost.Multiprecision), that one |
7c673cae FG |
44 | - else if type is floating point, the specified default FP is used |
45 | - else it is integral and the specified default integral is used | |
46 | */ | |
47 | template | |
48 | < | |
49 | typename Type, | |
50 | typename CalculationType, | |
51 | typename DefaultFloatingPointCalculationType, | |
52 | typename DefaultIntegralCalculationType | |
53 | > | |
54 | struct calculation_type | |
55 | { | |
56 | BOOST_STATIC_ASSERT(( | |
20effc67 | 57 | std::is_fundamental |
7c673cae FG |
58 | < |
59 | DefaultFloatingPointCalculationType | |
20effc67 | 60 | >::value |
7c673cae FG |
61 | )); |
62 | BOOST_STATIC_ASSERT(( | |
20effc67 | 63 | std::is_fundamental |
7c673cae FG |
64 | < |
65 | DefaultIntegralCalculationType | |
20effc67 | 66 | >::value |
7c673cae FG |
67 | )); |
68 | ||
69 | ||
20effc67 | 70 | typedef std::conditional_t |
7c673cae | 71 | < |
20effc67 TL |
72 | std::is_void<CalculationType>::value, |
73 | std::conditional_t | |
7c673cae | 74 | < |
20effc67 | 75 | std::is_floating_point<Type>::value, |
7c673cae FG |
76 | typename select_most_precise |
77 | < | |
78 | DefaultFloatingPointCalculationType, | |
79 | Type | |
80 | >::type, | |
81 | typename select_most_precise | |
82 | < | |
83 | DefaultIntegralCalculationType, | |
84 | Type | |
85 | >::type | |
20effc67 | 86 | >, |
7c673cae | 87 | CalculationType |
20effc67 | 88 | > type; |
7c673cae FG |
89 | }; |
90 | ||
91 | } // namespace detail | |
92 | ||
93 | ||
94 | namespace calculation_type | |
95 | { | |
96 | ||
97 | namespace geometric | |
98 | { | |
99 | ||
100 | template | |
101 | < | |
102 | typename Geometry, | |
103 | typename CalculationType, | |
104 | typename DefaultFloatingPointCalculationType = double, | |
105 | typename DefaultIntegralCalculationType = detail::default_integral::type | |
106 | > | |
107 | struct unary | |
108 | { | |
109 | typedef typename detail::calculation_type | |
110 | < | |
111 | typename geometry::coordinate_type<Geometry>::type, | |
112 | CalculationType, | |
113 | DefaultFloatingPointCalculationType, | |
114 | DefaultIntegralCalculationType | |
115 | >::type type; | |
116 | }; | |
117 | ||
118 | template | |
119 | < | |
120 | typename Geometry1, | |
121 | typename Geometry2, | |
122 | typename CalculationType, | |
123 | typename DefaultFloatingPointCalculationType = double, | |
124 | typename DefaultIntegralCalculationType = detail::default_integral::type | |
125 | > | |
126 | struct binary | |
127 | { | |
128 | typedef typename detail::calculation_type | |
129 | < | |
130 | typename select_coordinate_type<Geometry1, Geometry2>::type, | |
131 | CalculationType, | |
132 | DefaultFloatingPointCalculationType, | |
133 | DefaultIntegralCalculationType | |
134 | >::type type; | |
135 | }; | |
136 | ||
137 | ||
138 | /*! | |
139 | \brief calculation type (ternary, for three geometry types) | |
140 | */ | |
141 | template | |
142 | < | |
143 | typename Geometry1, | |
144 | typename Geometry2, | |
145 | typename Geometry3, | |
146 | typename CalculationType, | |
147 | typename DefaultFloatingPointCalculationType = double, | |
148 | typename DefaultIntegralCalculationType = detail::default_integral::type | |
149 | > | |
150 | struct ternary | |
151 | { | |
152 | typedef typename detail::calculation_type | |
153 | < | |
154 | typename select_most_precise | |
155 | < | |
156 | typename coordinate_type<Geometry1>::type, | |
157 | typename select_coordinate_type | |
158 | < | |
159 | Geometry2, | |
160 | Geometry3 | |
161 | >::type | |
162 | >::type, | |
163 | CalculationType, | |
164 | DefaultFloatingPointCalculationType, | |
165 | DefaultIntegralCalculationType | |
166 | >::type type; | |
167 | }; | |
168 | ||
169 | }} // namespace calculation_type::geometric | |
170 | ||
171 | } // namespace util | |
172 | ||
173 | }} // namespace boost::geometry | |
174 | ||
175 | ||
176 | #endif // BOOST_GEOMETRY_UTIL_CALCULATION_TYPE_HPP |