]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/geometry/include/boost/geometry/algorithms/detail/is_valid/linear.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / geometry / include / boost / geometry / algorithms / detail / is_valid / linear.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2014-2015, Oracle and/or its affiliates.
4
5 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7
8 // Licensed under the Boost Software License version 1.0.
9 // http://www.boost.org/users/license.html
10
11 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_LINEAR_HPP
12 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_LINEAR_HPP
13
14 #include <cstddef>
15
16 #include <boost/range.hpp>
17
18 #include <boost/geometry/core/closure.hpp>
19 #include <boost/geometry/core/point_type.hpp>
20 #include <boost/geometry/core/tags.hpp>
21
22 #include <boost/geometry/util/condition.hpp>
23 #include <boost/geometry/util/range.hpp>
24
25 #include <boost/geometry/algorithms/equals.hpp>
26 #include <boost/geometry/algorithms/validity_failure_type.hpp>
27 #include <boost/geometry/algorithms/detail/check_iterator_range.hpp>
28 #include <boost/geometry/algorithms/detail/is_valid/has_invalid_coordinate.hpp>
29 #include <boost/geometry/algorithms/detail/is_valid/has_spikes.hpp>
30 #include <boost/geometry/algorithms/detail/num_distinct_consecutive_points.hpp>
31
32 #include <boost/geometry/algorithms/dispatch/is_valid.hpp>
33
34
35 namespace boost { namespace geometry
36 {
37
38 #ifndef DOXYGEN_NO_DETAIL
39 namespace detail { namespace is_valid
40 {
41
42
43 template <typename Linestring>
44 struct is_valid_linestring
45 {
46 template <typename VisitPolicy>
47 static inline bool apply(Linestring const& linestring,
48 VisitPolicy& visitor)
49 {
50 if (has_invalid_coordinate<Linestring>::apply(linestring, visitor))
51 {
52 return false;
53 }
54
55 if (boost::size(linestring) < 2)
56 {
57 return visitor.template apply<failure_few_points>();
58 }
59
60 std::size_t num_distinct = detail::num_distinct_consecutive_points
61 <
62 Linestring,
63 3u,
64 true,
65 not_equal_to<typename point_type<Linestring>::type>
66 >::apply(linestring);
67
68 if (num_distinct < 2u)
69 {
70 return
71 visitor.template apply<failure_wrong_topological_dimension>();
72 }
73
74 if (num_distinct == 2u)
75 {
76 return visitor.template apply<no_failure>();
77 }
78 return ! has_spikes<Linestring, closed>::apply(linestring, visitor);
79 }
80 };
81
82
83 }} // namespace detail::is_valid
84 #endif // DOXYGEN_NO_DETAIL
85
86
87
88
89 #ifndef DOXYGEN_NO_DISPATCH
90 namespace dispatch
91 {
92
93
94 // A linestring is a curve.
95 // A curve is 1-dimensional so it has to have at least two distinct
96 // points.
97 // A curve is simple if it does not pass through the same point twice,
98 // with the possible exception of its two endpoints
99 //
100 // There is an option here as to whether spikes are allowed for linestrings;
101 // here we pass this as an additional template parameter: allow_spikes
102 // If allow_spikes is set to true, spikes are allowed, false otherwise.
103 // By default, spikes are disallowed
104 //
105 // Reference: OGC 06-103r4 (6.1.6.1)
106 template <typename Linestring, bool AllowEmptyMultiGeometries>
107 struct is_valid
108 <
109 Linestring, linestring_tag, AllowEmptyMultiGeometries
110 > : detail::is_valid::is_valid_linestring<Linestring>
111 {};
112
113
114 // A MultiLinestring is a MultiCurve
115 // A MultiCurve is simple if all of its elements are simple and the
116 // only intersections between any two elements occur at Points that
117 // are on the boundaries of both elements.
118 //
119 // Reference: OGC 06-103r4 (6.1.8.1; Fig. 9)
120 template <typename MultiLinestring, bool AllowEmptyMultiGeometries>
121 class is_valid
122 <
123 MultiLinestring, multi_linestring_tag, AllowEmptyMultiGeometries
124 >
125 {
126 private:
127 template <typename VisitPolicy>
128 struct per_linestring
129 {
130 per_linestring(VisitPolicy& policy) : m_policy(policy) {}
131
132 template <typename Linestring>
133 inline bool apply(Linestring const& linestring) const
134 {
135 return detail::is_valid::is_valid_linestring
136 <
137 Linestring
138 >::apply(linestring, m_policy);
139 }
140
141 VisitPolicy& m_policy;
142 };
143
144 public:
145 template <typename VisitPolicy>
146 static inline bool apply(MultiLinestring const& multilinestring,
147 VisitPolicy& visitor)
148 {
149 if (BOOST_GEOMETRY_CONDITION(
150 AllowEmptyMultiGeometries && boost::empty(multilinestring)))
151 {
152 return visitor.template apply<no_failure>();
153 }
154
155 return detail::check_iterator_range
156 <
157 per_linestring<VisitPolicy>,
158 false // do not check for empty multilinestring (done above)
159 >::apply(boost::begin(multilinestring),
160 boost::end(multilinestring),
161 per_linestring<VisitPolicy>(visitor));
162 }
163 };
164
165
166 } // namespace dispatch
167 #endif // DOXYGEN_NO_DISPATCH
168
169
170 }} // namespace boost::geometry
171
172
173 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_LINEAR_HPP