1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2014-2015, Oracle and/or its affiliates.
5 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8 // Licensed under the Boost Software License version 1.0.
9 // http://www.boost.org/users/license.html
11 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_BOX_HPP
12 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_BOX_HPP
16 #include <boost/core/ignore_unused.hpp>
18 #include <boost/geometry/core/access.hpp>
19 #include <boost/geometry/core/tags.hpp>
20 #include <boost/geometry/core/coordinate_dimension.hpp>
22 #include <boost/geometry/algorithms/validity_failure_type.hpp>
23 #include <boost/geometry/algorithms/detail/is_valid/has_invalid_coordinate.hpp>
24 #include <boost/geometry/algorithms/dispatch/is_valid.hpp>
27 namespace boost { namespace geometry
31 #ifndef DOXYGEN_NO_DETAIL
32 namespace detail { namespace is_valid
35 template <typename Box, std::size_t I>
36 struct has_valid_corners
38 template <typename VisitPolicy>
39 static inline bool apply(Box const& box, VisitPolicy& visitor)
41 if (math::equals(geometry::get<geometry::min_corner, I-1>(box),
42 geometry::get<geometry::max_corner, I-1>(box)))
45 visitor.template apply<failure_wrong_topological_dimension>();
47 else if (geometry::get<geometry::min_corner, I-1>(box)
49 geometry::get<geometry::max_corner, I-1>(box))
51 return visitor.template apply<failure_wrong_corner_order>();
53 return has_valid_corners<Box, I-1>::apply(box, visitor);
58 template <typename Box>
59 struct has_valid_corners<Box, 0>
61 template <typename VisitPolicy>
62 static inline bool apply(Box const&, VisitPolicy& visitor)
64 boost::ignore_unused(visitor);
66 return visitor.template apply<no_failure>();
71 template <typename Box>
74 template <typename VisitPolicy>
75 static inline bool apply(Box const& box, VisitPolicy& visitor)
78 ! has_invalid_coordinate<Box>::apply(box, visitor)
80 has_valid_corners<Box, dimension<Box>::value>::apply(box, visitor);
84 }} // namespace detail::is_valid
85 #endif // DOXYGEN_NO_DETAIL
89 #ifndef DOXYGEN_NO_DISPATCH
94 // A box is always simple
95 // A box is a Polygon, and it satisfies the conditions for Polygon validity.
97 // The only thing we have to check is whether the max corner lies in
98 // the upper-right quadrant as defined by the min corner
100 // Reference (for polygon validity): OGC 06-103r4 (6.1.11.1)
101 template <typename Box>
102 struct is_valid<Box, box_tag>
103 : detail::is_valid::is_valid_box<Box>
107 } // namespace dispatch
108 #endif // DOXYGEN_NO_DISPATCH
112 }} // namespace boost::geometry
115 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_BOX_HPP