Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:23

0001 // Boost.Geometry
0002 
0003 // Copyright (c) 2021 Barend Gehrels, Amsterdam, the Netherlands.
0004 
0005 // Use, modification and distribution is subject to the Boost Software License,
0006 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0007 // http://www.boost.org/LICENSE_1_0.txt)
0008 
0009 #ifndef BOOST_GEOMETRY_CORE_COORDINATE_PROMOTION_HPP
0010 #define BOOST_GEOMETRY_CORE_COORDINATE_PROMOTION_HPP
0011 
0012 #include <boost/geometry/core/coordinate_type.hpp>
0013 
0014 // TODO: move this to a future headerfile implementing traits for these types
0015 #include <boost/rational.hpp>
0016 #include <boost/multiprecision/cpp_bin_float.hpp>
0017 #include <boost/multiprecision/cpp_int.hpp>
0018 
0019 namespace boost { namespace geometry
0020 {
0021 
0022 namespace traits
0023 {
0024 
0025 // todo
0026 
0027 } // namespace traits
0028 
0029 /*!
0030     \brief Meta-function converting, if necessary, to "a floating point" type
0031     \details
0032         - if input type is integer, type is double
0033         - else type is input type
0034     \ingroup utility
0035  */
0036 // TODO: replace with, or call, promoted_to_floating_point
0037 template <typename T, typename PromoteIntegerTo = double>
0038 struct promote_floating_point
0039 {
0040     typedef std::conditional_t
0041         <
0042             std::is_integral<T>::value,
0043             PromoteIntegerTo,
0044             T
0045         > type;
0046 };
0047 
0048 // TODO: replace with promoted_to_floating_point
0049 template <typename Geometry>
0050 struct fp_coordinate_type
0051 {
0052     typedef typename promote_floating_point
0053         <
0054             typename coordinate_type<Geometry>::type
0055         >::type type;
0056 };
0057 
0058 namespace detail
0059 {
0060 
0061 // Promote any integral type to double. Floating point
0062 // and other user defined types stay as they are, unless specialized.
0063 // TODO: we shold add a coordinate_promotion traits for promotion to
0064 // floating point or (larger) integer types.
0065 template <typename Type>
0066 struct promoted_to_floating_point
0067 {
0068     using type = std::conditional_t
0069         <
0070             std::is_integral<Type>::value, double, Type
0071         >;
0072 };
0073 
0074 // Boost.Rational goes to double
0075 template <typename T>
0076 struct promoted_to_floating_point<boost::rational<T>>
0077 {
0078     using type = double;
0079 };
0080 
0081 // Any Boost.Multiprecision goes to double (for example int128_t),
0082 // unless specialized
0083 template <typename Backend>
0084 struct promoted_to_floating_point<boost::multiprecision::number<Backend>>
0085 {
0086     using type = double;
0087 };
0088 
0089 // Boost.Multiprecision binary floating point numbers are used as FP.
0090 template <unsigned Digits>
0091 struct promoted_to_floating_point
0092     <
0093         boost::multiprecision::number
0094             <
0095                 boost::multiprecision::cpp_bin_float<Digits>
0096             >
0097     >
0098 {
0099     using type = boost::multiprecision::number
0100         <
0101             boost::multiprecision::cpp_bin_float<Digits>
0102         >;
0103 };
0104 
0105 }
0106 
0107 
0108 }} // namespace boost::geometry
0109 
0110 
0111 #endif // BOOST_GEOMETRY_CORE_COORDINATE_PROMOTION_HPP