box.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2014-2017, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  4. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  5. // Licensed under the Boost Software License version 1.0.
  6. // http://www.boost.org/users/license.html
  7. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_BOX_HPP
  8. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_BOX_HPP
  9. #include <cstddef>
  10. #include <boost/core/ignore_unused.hpp>
  11. #include <boost/geometry/core/access.hpp>
  12. #include <boost/geometry/core/tags.hpp>
  13. #include <boost/geometry/core/coordinate_dimension.hpp>
  14. #include <boost/geometry/algorithms/validity_failure_type.hpp>
  15. #include <boost/geometry/algorithms/detail/is_valid/has_invalid_coordinate.hpp>
  16. #include <boost/geometry/algorithms/dispatch/is_valid.hpp>
  17. namespace boost { namespace geometry
  18. {
  19. #ifndef DOXYGEN_NO_DETAIL
  20. namespace detail { namespace is_valid
  21. {
  22. template <typename Box, std::size_t I>
  23. struct has_valid_corners
  24. {
  25. template <typename VisitPolicy>
  26. static inline bool apply(Box const& box, VisitPolicy& visitor)
  27. {
  28. if (math::equals(geometry::get<geometry::min_corner, I-1>(box),
  29. geometry::get<geometry::max_corner, I-1>(box)))
  30. {
  31. return
  32. visitor.template apply<failure_wrong_topological_dimension>();
  33. }
  34. else if (geometry::get<geometry::min_corner, I-1>(box)
  35. >
  36. geometry::get<geometry::max_corner, I-1>(box))
  37. {
  38. return visitor.template apply<failure_wrong_corner_order>();
  39. }
  40. return has_valid_corners<Box, I-1>::apply(box, visitor);
  41. }
  42. };
  43. template <typename Box>
  44. struct has_valid_corners<Box, 0>
  45. {
  46. template <typename VisitPolicy>
  47. static inline bool apply(Box const&, VisitPolicy& visitor)
  48. {
  49. boost::ignore_unused(visitor);
  50. return visitor.template apply<no_failure>();
  51. }
  52. };
  53. template <typename Box>
  54. struct is_valid_box
  55. {
  56. template <typename VisitPolicy, typename Strategy>
  57. static inline bool apply(Box const& box, VisitPolicy& visitor, Strategy const&)
  58. {
  59. return
  60. ! has_invalid_coordinate<Box>::apply(box, visitor)
  61. &&
  62. has_valid_corners<Box, dimension<Box>::value>::apply(box, visitor);
  63. }
  64. };
  65. }} // namespace detail::is_valid
  66. #endif // DOXYGEN_NO_DETAIL
  67. #ifndef DOXYGEN_NO_DISPATCH
  68. namespace dispatch
  69. {
  70. // A box is always simple
  71. // A box is a Polygon, and it satisfies the conditions for Polygon validity.
  72. //
  73. // The only thing we have to check is whether the max corner lies in
  74. // the upper-right quadrant as defined by the min corner
  75. //
  76. // Reference (for polygon validity): OGC 06-103r4 (6.1.11.1)
  77. template <typename Box>
  78. struct is_valid<Box, box_tag>
  79. : detail::is_valid::is_valid_box<Box>
  80. {};
  81. } // namespace dispatch
  82. #endif // DOXYGEN_NO_DISPATCH
  83. }} // namespace boost::geometry
  84. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_BOX_HPP