]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/algorithms/detail/disjoint/areal_areal.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / geometry / algorithms / detail / disjoint / areal_areal.hpp
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
6 // Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland.
7
8 // This file was modified by Oracle on 2013-2017.
9 // Modifications copyright (c) 2013-2017, Oracle and/or its affiliates.
10
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
13
14 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
15 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
16
17 // Use, modification and distribution is subject to the Boost Software License,
18 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
19 // http://www.boost.org/LICENSE_1_0.txt)
20
21 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_AREAL_AREAL_HPP
22 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_AREAL_AREAL_HPP
23
24 #include <boost/geometry/core/point_type.hpp>
25
26 #include <boost/geometry/algorithms/covered_by.hpp>
27 #include <boost/geometry/algorithms/detail/for_each_range.hpp>
28 #include <boost/geometry/algorithms/detail/point_on_border.hpp>
29
30 #include <boost/geometry/algorithms/detail/disjoint/linear_linear.hpp>
31
32
33 namespace boost { namespace geometry
34 {
35
36
37 #ifndef DOXYGEN_NO_DETAIL
38 namespace detail { namespace disjoint
39 {
40
41
42 template <typename Geometry, typename Tag = typename tag<Geometry>::type>
43 struct check_each_ring_for_within_call_covered_by
44 {
45 /*!
46 \tparam Strategy point_in_geometry strategy
47 */
48 template <typename Point, typename Strategy>
49 static inline bool apply(Point const& p, Geometry const& g, Strategy const& strategy)
50 {
51 return geometry::covered_by(p, g, strategy);
52 }
53 };
54
55 template <typename Geometry>
56 struct check_each_ring_for_within_call_covered_by<Geometry, box_tag>
57 {
58 template <typename Point, typename Strategy>
59 static inline bool apply(Point const& p, Geometry const& g, Strategy const& )
60 {
61 return geometry::covered_by(p, g);
62 }
63 };
64
65
66 /*!
67 \tparam Strategy point_in_geometry strategy
68 */
69 template<typename Geometry, typename Strategy>
70 struct check_each_ring_for_within
71 {
72 bool not_disjoint;
73 Geometry const& m_geometry;
74 Strategy const& m_strategy;
75
76 inline check_each_ring_for_within(Geometry const& g,
77 Strategy const& strategy)
78 : not_disjoint(false)
79 , m_geometry(g)
80 , m_strategy(strategy)
81 {}
82
83 template <typename Range>
84 inline void apply(Range const& range)
85 {
86 typename point_type<Range>::type pt;
87 not_disjoint = not_disjoint
88 || ( geometry::point_on_border(pt, range)
89 && check_each_ring_for_within_call_covered_by
90 <
91 Geometry
92 >::apply(pt, m_geometry, m_strategy) );
93 }
94 };
95
96
97 /*!
98 \tparam Strategy point_in_geometry strategy
99 */
100 template <typename FirstGeometry, typename SecondGeometry, typename Strategy>
101 inline bool rings_containing(FirstGeometry const& geometry1,
102 SecondGeometry const& geometry2,
103 Strategy const& strategy)
104 {
105 check_each_ring_for_within
106 <
107 FirstGeometry, Strategy
108 > checker(geometry1, strategy);
109 geometry::detail::for_each_range(geometry2, checker);
110 return checker.not_disjoint;
111 }
112
113
114
115 template <typename Geometry1, typename Geometry2>
116 struct general_areal
117 {
118 /*!
119 \tparam Strategy relate (segments intersection) strategy
120 */
121 template <typename Strategy>
122 static inline bool apply(Geometry1 const& geometry1,
123 Geometry2 const& geometry2,
124 Strategy const& strategy)
125 {
126 if ( ! disjoint_linear<Geometry1, Geometry2>::apply(geometry1, geometry2, strategy) )
127 {
128 return false;
129 }
130
131 // If there is no intersection of segments, they might located
132 // inside each other
133
134 // We check that using a point on the border (external boundary),
135 // and see if that is contained in the other geometry. And vice versa.
136
137 if ( rings_containing(geometry1, geometry2,
138 strategy.template get_point_in_geometry_strategy<Geometry2, Geometry1>())
139 || rings_containing(geometry2, geometry1,
140 strategy.template get_point_in_geometry_strategy<Geometry1, Geometry2>()) )
141 {
142 return false;
143 }
144
145 return true;
146 }
147 };
148
149
150 }} // namespace detail::disjoint
151 #endif // DOXYGEN_NO_DETAIL
152
153
154
155
156 #ifndef DOXYGEN_NO_DISPATCH
157 namespace dispatch
158 {
159
160
161 template <typename Areal1, typename Areal2>
162 struct disjoint<Areal1, Areal2, 2, areal_tag, areal_tag, false>
163 : detail::disjoint::general_areal<Areal1, Areal2>
164 {};
165
166
167 template <typename Areal, typename Box>
168 struct disjoint<Areal, Box, 2, areal_tag, box_tag, false>
169 : detail::disjoint::general_areal<Areal, Box>
170 {};
171
172
173 } // namespace dispatch
174 #endif // DOXYGEN_NO_DISPATCH
175
176
177 }} // namespace boost::geometry
178
179
180 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_AREAL_AREAL_HPP