is_valid.hpp 2.1 KB

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