]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | ||
20effc67 TL |
8 | // This file was modified by Oracle on 2013-2020. |
9 | // Modifications copyright (c) 2013-2020, Oracle and/or its affiliates. | |
7c673cae FG |
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> | |
92f5a8d4 TL |
31 | #include <boost/geometry/algorithms/detail/disjoint/segment_box.hpp> |
32 | ||
20effc67 | 33 | #include <boost/geometry/algorithms/for_each.hpp> |
7c673cae FG |
34 | |
35 | ||
36 | namespace boost { namespace geometry | |
37 | { | |
38 | ||
39 | ||
40 | #ifndef DOXYGEN_NO_DETAIL | |
41 | namespace detail { namespace disjoint | |
42 | { | |
43 | ||
92f5a8d4 TL |
44 | template <typename Geometry1, typename Geometry2, typename Strategy> |
45 | inline bool point_on_border_covered_by(Geometry1 const& geometry1, | |
46 | Geometry2 const& geometry2, | |
47 | Strategy const& strategy) | |
b32b8144 | 48 | { |
92f5a8d4 TL |
49 | typename geometry::point_type<Geometry1>::type pt; |
50 | return geometry::point_on_border(pt, geometry1) | |
51 | && geometry::covered_by(pt, geometry2, strategy); | |
52 | } | |
b32b8144 | 53 | |
7c673cae | 54 | |
b32b8144 FG |
55 | /*! |
56 | \tparam Strategy point_in_geometry strategy | |
57 | */ | |
20effc67 TL |
58 | template <typename Geometry1, typename Geometry2, typename Strategy> |
59 | inline bool rings_containing(Geometry1 const& geometry1, | |
60 | Geometry2 const& geometry2, | |
b32b8144 | 61 | Strategy const& strategy) |
7c673cae | 62 | { |
20effc67 TL |
63 | return geometry::detail::any_range_of(geometry2, [&](auto const& range) |
64 | { | |
1e59de90 | 65 | return point_on_border_covered_by(range, geometry1, strategy); |
20effc67 | 66 | }); |
7c673cae FG |
67 | } |
68 | ||
69 | ||
70 | ||
71 | template <typename Geometry1, typename Geometry2> | |
92f5a8d4 | 72 | struct areal_areal |
7c673cae | 73 | { |
b32b8144 FG |
74 | /*! |
75 | \tparam Strategy relate (segments intersection) strategy | |
76 | */ | |
77 | template <typename Strategy> | |
78 | static inline bool apply(Geometry1 const& geometry1, | |
79 | Geometry2 const& geometry2, | |
80 | Strategy const& strategy) | |
7c673cae | 81 | { |
b32b8144 | 82 | if ( ! disjoint_linear<Geometry1, Geometry2>::apply(geometry1, geometry2, strategy) ) |
7c673cae FG |
83 | { |
84 | return false; | |
85 | } | |
86 | ||
87 | // If there is no intersection of segments, they might located | |
88 | // inside each other | |
89 | ||
90 | // We check that using a point on the border (external boundary), | |
91 | // and see if that is contained in the other geometry. And vice versa. | |
92 | ||
20effc67 TL |
93 | if ( rings_containing(geometry1, geometry2, strategy) |
94 | || rings_containing(geometry2, geometry1, strategy) ) | |
7c673cae FG |
95 | { |
96 | return false; | |
97 | } | |
98 | ||
99 | return true; | |
100 | } | |
101 | }; | |
102 | ||
103 | ||
92f5a8d4 TL |
104 | template <typename Areal, typename Box> |
105 | struct areal_box | |
106 | { | |
107 | /*! | |
108 | \tparam Strategy relate (segments intersection) strategy | |
109 | */ | |
110 | template <typename Strategy> | |
111 | static inline bool apply(Areal const& areal, | |
112 | Box const& box, | |
113 | Strategy const& strategy) | |
114 | { | |
20effc67 TL |
115 | if (! geometry::all_segments_of(areal, [&](auto const& s) |
116 | { | |
1e59de90 | 117 | return disjoint_segment_box::apply(s, box, strategy); |
20effc67 | 118 | }) ) |
92f5a8d4 TL |
119 | { |
120 | return false; | |
121 | } | |
122 | ||
123 | // If there is no intersection of any segment and box, | |
124 | // the box might be located inside areal geometry | |
125 | ||
1e59de90 | 126 | if ( point_on_border_covered_by(box, areal, strategy) ) |
92f5a8d4 TL |
127 | { |
128 | return false; | |
129 | } | |
130 | ||
131 | return true; | |
132 | } | |
92f5a8d4 TL |
133 | }; |
134 | ||
135 | ||
7c673cae FG |
136 | }} // namespace detail::disjoint |
137 | #endif // DOXYGEN_NO_DETAIL | |
138 | ||
139 | ||
140 | ||
141 | ||
142 | #ifndef DOXYGEN_NO_DISPATCH | |
143 | namespace dispatch | |
144 | { | |
145 | ||
146 | ||
147 | template <typename Areal1, typename Areal2> | |
148 | struct disjoint<Areal1, Areal2, 2, areal_tag, areal_tag, false> | |
92f5a8d4 | 149 | : detail::disjoint::areal_areal<Areal1, Areal2> |
7c673cae FG |
150 | {}; |
151 | ||
152 | ||
153 | template <typename Areal, typename Box> | |
154 | struct disjoint<Areal, Box, 2, areal_tag, box_tag, false> | |
92f5a8d4 | 155 | : detail::disjoint::areal_box<Areal, Box> |
7c673cae FG |
156 | {}; |
157 | ||
158 | ||
159 | } // namespace dispatch | |
160 | #endif // DOXYGEN_NO_DISPATCH | |
161 | ||
162 | ||
163 | }} // namespace boost::geometry | |
164 | ||
165 | ||
166 | #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_AREAL_AREAL_HPP |