has_nan_coordinate.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Boost.Geometry
  2. // Copyright (c) 2015-2020 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 <type_traits>
  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. std::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