]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | // Boost.Geometry |
2 | ||
3 | // Copyright (c) 2021 Barend Gehrels, Amsterdam, the Netherlands. | |
4 | ||
5 | // Use, modification and distribution is subject to the Boost Software License, | |
6 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
7 | // http://www.boost.org/LICENSE_1_0.txt) | |
8 | ||
9 | #ifndef BOOST_GEOMETRY_CORE_COORDINATE_PROMOTION_HPP | |
10 | #define BOOST_GEOMETRY_CORE_COORDINATE_PROMOTION_HPP | |
11 | ||
12 | #include <boost/geometry/core/coordinate_type.hpp> | |
13 | ||
14 | // TODO: move this to a future headerfile implementing traits for these types | |
15 | #include <boost/rational.hpp> | |
16 | #include <boost/multiprecision/cpp_bin_float.hpp> | |
17 | #include <boost/multiprecision/cpp_int.hpp> | |
18 | ||
19 | namespace boost { namespace geometry | |
20 | { | |
21 | ||
22 | namespace traits | |
23 | { | |
24 | ||
25 | // todo | |
26 | ||
27 | } // namespace traits | |
28 | ||
29 | /*! | |
30 | \brief Meta-function converting, if necessary, to "a floating point" type | |
31 | \details | |
32 | - if input type is integer, type is double | |
33 | - else type is input type | |
34 | \ingroup utility | |
35 | */ | |
36 | // TODO: replace with, or call, promoted_to_floating_point | |
37 | template <typename T, typename PromoteIntegerTo = double> | |
38 | struct promote_floating_point | |
39 | { | |
40 | typedef std::conditional_t | |
41 | < | |
42 | std::is_integral<T>::value, | |
43 | PromoteIntegerTo, | |
44 | T | |
45 | > type; | |
46 | }; | |
47 | ||
48 | // TODO: replace with promoted_to_floating_point | |
49 | template <typename Geometry> | |
50 | struct fp_coordinate_type | |
51 | { | |
52 | typedef typename promote_floating_point | |
53 | < | |
54 | typename coordinate_type<Geometry>::type | |
55 | >::type type; | |
56 | }; | |
57 | ||
58 | namespace detail | |
59 | { | |
60 | ||
61 | // Promote any integral type to double. Floating point | |
62 | // and other user defined types stay as they are, unless specialized. | |
63 | // TODO: we shold add a coordinate_promotion traits for promotion to | |
64 | // floating point or (larger) integer types. | |
65 | template <typename Type> | |
66 | struct promoted_to_floating_point | |
67 | { | |
68 | using type = std::conditional_t | |
69 | < | |
70 | std::is_integral<Type>::value, double, Type | |
71 | >; | |
72 | }; | |
73 | ||
74 | // Boost.Rational goes to double | |
75 | template <typename T> | |
76 | struct promoted_to_floating_point<boost::rational<T>> | |
77 | { | |
78 | using type = double; | |
79 | }; | |
80 | ||
81 | // Any Boost.Multiprecision goes to double (for example int128_t), | |
82 | // unless specialized | |
83 | template <typename Backend> | |
84 | struct promoted_to_floating_point<boost::multiprecision::number<Backend>> | |
85 | { | |
86 | using type = double; | |
87 | }; | |
88 | ||
89 | // Boost.Multiprecision binary floating point numbers are used as FP. | |
90 | template <unsigned Digits> | |
91 | struct promoted_to_floating_point | |
92 | < | |
93 | boost::multiprecision::number | |
94 | < | |
95 | boost::multiprecision::cpp_bin_float<Digits> | |
96 | > | |
97 | > | |
98 | { | |
99 | using type = boost::multiprecision::number | |
100 | < | |
101 | boost::multiprecision::cpp_bin_float<Digits> | |
102 | >; | |
103 | }; | |
104 | ||
105 | } | |
106 | ||
107 | ||
108 | }} // namespace boost::geometry | |
109 | ||
110 | ||
111 | #endif // BOOST_GEOMETRY_CORE_COORDINATE_PROMOTION_HPP |