diff options
Diffstat (limited to 'boost/geometry/util')
-rw-r--r-- | boost/geometry/util/bare_type.hpp | 38 | ||||
-rw-r--r-- | boost/geometry/util/math.hpp | 56 |
2 files changed, 93 insertions, 1 deletions
diff --git a/boost/geometry/util/bare_type.hpp b/boost/geometry/util/bare_type.hpp new file mode 100644 index 0000000000..1b49de6436 --- /dev/null +++ b/boost/geometry/util/bare_type.hpp @@ -0,0 +1,38 @@ +// Boost.Geometry (aka GGL, Generic Geometry Library) + +// Copyright (c) 2012 Barend Gehrels, Amsterdam, the Netherlands. +// Copyright (c) 2012 Bruno Lalande, Paris, France. +// Copyright (c) 2012 Mateusz Loskot, London, UK. + +// Use, modification and distribution is subject to the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_GEOMETRY_UTIL_BARE_TYPE_HPP +#define BOOST_GEOMETRY_UTIL_BARE_TYPE_HPP + +#include <boost/type_traits.hpp> + + +namespace boost { namespace geometry +{ + +namespace util +{ + +template <typename T> +struct bare_type +{ + typedef typename boost::remove_const + < + typename boost::remove_pointer<T>::type + >::type type; +}; + + +} // namespace util + +}} // namespace boost::geometry + + +#endif // BOOST_GEOMETRY_UTIL_BARE_TYPE_HPP diff --git a/boost/geometry/util/math.hpp b/boost/geometry/util/math.hpp index edfa961b15..95cbdf2ce4 100644 --- a/boost/geometry/util/math.hpp +++ b/boost/geometry/util/math.hpp @@ -44,11 +44,43 @@ struct equals template <typename Type> struct equals<Type, true> { + static inline Type get_max(Type const& a, Type const& b, Type const& c) + { + return (std::max)((std::max)(a, b), c); + } + static inline bool apply(Type const& a, Type const& b) { + if (a == b) + { + return true; + } + // See http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.17, // FUTURE: replace by some boost tool or boost::test::close_at_tolerance - return std::abs(a - b) <= std::numeric_limits<Type>::epsilon() * std::abs(a); + return std::abs(a - b) <= std::numeric_limits<Type>::epsilon() * get_max(std::abs(a), std::abs(b), 1.0); + } +}; + +template <typename Type, bool IsFloatingPoint> +struct smaller +{ + static inline bool apply(Type const& a, Type const& b) + { + return a < b; + } +}; + +template <typename Type> +struct smaller<Type, true> +{ + static inline bool apply(Type const& a, Type const& b) + { + if (equals<Type, true>::apply(a, b)) + { + return false; + } + return a < b; } }; @@ -116,6 +148,28 @@ inline bool equals_with_epsilon(T1 const& a, T2 const& b) >::apply(a, b); } +template <typename T1, typename T2> +inline bool smaller(T1 const& a, T2 const& b) +{ + typedef typename select_most_precise<T1, T2>::type select_type; + return detail::smaller + < + select_type, + boost::is_floating_point<select_type>::type::value + >::apply(a, b); +} + +template <typename T1, typename T2> +inline bool larger(T1 const& a, T2 const& b) +{ + typedef typename select_most_precise<T1, T2>::type select_type; + return detail::smaller + < + select_type, + boost::is_floating_point<select_type>::type::value + >::apply(b, a); +} + double const d2r = geometry::math::pi<double>() / 180.0; |