is_valid.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // Boost.Geometry Index
  2. //
  3. // n-dimensional Indexable validity check
  4. //
  5. // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland.
  6. //
  7. // This file was modified by Oracle on 2020-2021.
  8. // Modifications copyright (c) 2020-2021 Oracle and/or its affiliates.
  9. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  10. //
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_IS_VALID_HPP
  15. #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_IS_VALID_HPP
  16. #include <cstddef>
  17. #include <boost/geometry/core/access.hpp>
  18. #include <boost/geometry/core/coordinate_dimension.hpp>
  19. #include <boost/geometry/core/static_assert.hpp>
  20. namespace boost { namespace geometry { namespace index { namespace detail {
  21. namespace dispatch {
  22. template <typename Box,
  23. std::size_t Dimension = geometry::dimension<Box>::value>
  24. struct is_valid_box
  25. {
  26. static inline bool apply(Box const& b)
  27. {
  28. return is_valid_box<Box, Dimension - 1>::apply(b) &&
  29. ( get<min_corner, Dimension - 1>(b) <= get<max_corner, Dimension - 1>(b) );
  30. }
  31. };
  32. template <typename Box>
  33. struct is_valid_box<Box, 1>
  34. {
  35. static inline bool apply(Box const& b)
  36. {
  37. return get<min_corner, 0>(b) <= get<max_corner, 0>(b);
  38. }
  39. };
  40. template <typename Indexable,
  41. typename Tag = typename geometry::tag<Indexable>::type>
  42. struct is_valid
  43. {
  44. BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
  45. "Not implemented for this Indexable type.",
  46. Indexable, Tag);
  47. };
  48. template <typename Indexable>
  49. struct is_valid<Indexable, point_tag>
  50. {
  51. static inline bool apply(Indexable const&)
  52. {
  53. return true;
  54. }
  55. };
  56. template <typename Indexable>
  57. struct is_valid<Indexable, box_tag>
  58. {
  59. static inline bool apply(Indexable const& b)
  60. {
  61. return dispatch::is_valid_box<Indexable>::apply(b);
  62. }
  63. };
  64. template <typename Indexable>
  65. struct is_valid<Indexable, segment_tag>
  66. {
  67. static inline bool apply(Indexable const&)
  68. {
  69. return true;
  70. }
  71. };
  72. } // namespace dispatch
  73. template <typename Indexable>
  74. inline bool is_valid(Indexable const& b)
  75. {
  76. // CONSIDER: detection of NaNs
  77. // e.g. by comparison of b with copy of b
  78. return dispatch::is_valid<Indexable>::apply(b);
  79. }
  80. }}}} // namespace boost::geometry::index::detail
  81. #endif // BOOST_GEOMETRY_DETAIL_INDEX_ALGORITHMS_IS_VALID_HPP