]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/index/detail/algorithms/is_valid.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / geometry / index / detail / algorithms / is_valid.hpp
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.
8 // Modifications copyright (c) 2020 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
15 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_IS_VALID_HPP
16 #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_IS_VALID_HPP
17
18 #include <cstddef>
19
20 #include <boost/geometry/core/access.hpp>
21 #include <boost/geometry/core/static_assert.hpp>
22
23 namespace boost { namespace geometry { namespace index { namespace detail {
24
25 namespace dispatch {
26
27 template <typename Box,
28 std::size_t Dimension = geometry::dimension<Box>::value>
29 struct is_valid_box
30 {
31 static inline bool apply(Box const& b)
32 {
33 return is_valid_box<Box, Dimension - 1>::apply(b) &&
34 ( get<min_corner, Dimension - 1>(b) <= get<max_corner, Dimension - 1>(b) );
35 }
36 };
37
38 template <typename Box>
39 struct is_valid_box<Box, 1>
40 {
41 static inline bool apply(Box const& b)
42 {
43 return get<min_corner, 0>(b) <= get<max_corner, 0>(b);
44 }
45 };
46
47 template <typename Indexable,
48 typename Tag = typename geometry::tag<Indexable>::type>
49 struct is_valid
50 {
51 BOOST_GEOMETRY_STATIC_ASSERT_FALSE(
52 "Not implemented for this Indexable type.",
53 Indexable, Tag);
54 };
55
56 template <typename Indexable>
57 struct is_valid<Indexable, point_tag>
58 {
59 static inline bool apply(Indexable const&)
60 {
61 return true;
62 }
63 };
64
65 template <typename Indexable>
66 struct is_valid<Indexable, box_tag>
67 {
68 static inline bool apply(Indexable const& b)
69 {
70 return dispatch::is_valid_box<Indexable>::apply(b);
71 }
72 };
73
74 template <typename Indexable>
75 struct is_valid<Indexable, segment_tag>
76 {
77 static inline bool apply(Indexable const&)
78 {
79 return true;
80 }
81 };
82
83 } // namespace dispatch
84
85 template <typename Indexable>
86 inline bool is_valid(Indexable const& b)
87 {
88 // CONSIDER: detection of NaNs
89 // e.g. by comparison of b with copy of b
90
91 return dispatch::is_valid<Indexable>::apply(b);
92 }
93
94 }}}} // namespace boost::geometry::index::detail
95
96 #endif // BOOST_GEOMETRY_DETAIL_INDEX_ALGORITHMS_IS_VALID_HPP