has_nan_coordinate.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Boost.Geometry
  2. // Copyright (c) 2015 Oracle and/or its affiliates.
  3. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  4. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  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. #ifndef BOOST_GEOMETRY_UTIL_HAS_NAN_COORDINATE_HPP
  9. #define BOOST_GEOMETRY_UTIL_HAS_NAN_COORDINATE_HPP
  10. #include <cstddef>
  11. #include <boost/type_traits/is_floating_point.hpp>
  12. #include <boost/geometry/core/access.hpp>
  13. #include <boost/geometry/core/coordinate_dimension.hpp>
  14. #include <boost/geometry/core/coordinate_type.hpp>
  15. #include <boost/math/special_functions/fpclassify.hpp>
  16. namespace boost { namespace geometry
  17. {
  18. #ifndef DOXYGEN_NO_DETAIL
  19. namespace detail
  20. {
  21. struct isnan
  22. {
  23. template <typename T>
  24. static inline bool apply(T const& t)
  25. {
  26. return boost::math::isnan(t);
  27. }
  28. };
  29. template
  30. <
  31. typename Point,
  32. typename Predicate,
  33. bool Enable,
  34. std::size_t I = 0,
  35. std::size_t N = geometry::dimension<Point>::value
  36. >
  37. struct has_coordinate_with_property
  38. {
  39. static bool apply(Point const& point)
  40. {
  41. return Predicate::apply(geometry::get<I>(point))
  42. || has_coordinate_with_property
  43. <
  44. Point, Predicate, Enable, I+1, N
  45. >::apply(point);
  46. }
  47. };
  48. template <typename Point, typename Predicate, std::size_t I, std::size_t N>
  49. struct has_coordinate_with_property<Point, Predicate, false, I, N>
  50. {
  51. static inline bool apply(Point const&)
  52. {
  53. return false;
  54. }
  55. };
  56. template <typename Point, typename Predicate, std::size_t N>
  57. struct has_coordinate_with_property<Point, Predicate, true, N, N>
  58. {
  59. static bool apply(Point const& )
  60. {
  61. return false;
  62. }
  63. };
  64. } // namespace detail
  65. #endif // DOXYGEN_NO_DETAIL
  66. template <typename Point>
  67. bool has_nan_coordinate(Point const& point)
  68. {
  69. return detail::has_coordinate_with_property
  70. <
  71. Point,
  72. detail::isnan,
  73. boost::is_floating_point
  74. <
  75. typename coordinate_type<Point>::type
  76. >::value
  77. >::apply(point);
  78. }
  79. }} // namespace boost::geometry
  80. #endif // BOOST_GEOMETRY_UTIL_HAS_NAN_COORDINATE_HPP