comparison DEPENDENCIES/generic/include/boost/geometry/algorithms/overlaps.hpp @ 16:2665513ce2d3

Add boost headers
author Chris Cannam
date Tue, 05 Aug 2014 11:11:38 +0100
parents
children c530137014c0
comparison
equal deleted inserted replaced
15:663ca0da4350 16:2665513ce2d3
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
6
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
9
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
13
14 #ifndef BOOST_GEOMETRY_ALGORITHMS_OVERLAPS_HPP
15 #define BOOST_GEOMETRY_ALGORITHMS_OVERLAPS_HPP
16
17
18 #include <cstddef>
19
20 #include <boost/geometry/core/access.hpp>
21
22 #include <boost/geometry/algorithms/not_implemented.hpp>
23
24 #include <boost/geometry/geometries/concepts/check.hpp>
25
26 namespace boost { namespace geometry
27 {
28
29 #ifndef DOXYGEN_NO_DETAIL
30 namespace detail { namespace overlaps
31 {
32
33 template
34 <
35 std::size_t Dimension,
36 std::size_t DimensionCount
37 >
38 struct box_box_loop
39 {
40 template <typename Box1, typename Box2>
41 static inline void apply(Box1 const& b1, Box2 const& b2,
42 bool& overlaps, bool& one_in_two, bool& two_in_one)
43 {
44 assert_dimension_equal<Box1, Box2>();
45
46 typedef typename coordinate_type<Box1>::type coordinate_type1;
47 typedef typename coordinate_type<Box2>::type coordinate_type2;
48
49 coordinate_type1 const& min1 = get<min_corner, Dimension>(b1);
50 coordinate_type1 const& max1 = get<max_corner, Dimension>(b1);
51 coordinate_type2 const& min2 = get<min_corner, Dimension>(b2);
52 coordinate_type2 const& max2 = get<max_corner, Dimension>(b2);
53
54 // We might use the (not yet accepted) Boost.Interval
55 // submission in the future
56
57 // If:
58 // B1: |-------|
59 // B2: |------|
60 // in any dimension -> no overlap
61 if (max1 <= min2 || min1 >= max2)
62 {
63 overlaps = false;
64 return;
65 }
66
67 // If:
68 // B1: |--------------------|
69 // B2: |-------------|
70 // in all dimensions -> within, then no overlap
71 // B1: |--------------------|
72 // B2: |-------------|
73 // this is "within-touch" -> then no overlap. So use < and >
74 if (min1 < min2 || max1 > max2)
75 {
76 one_in_two = false;
77 }
78 // Same other way round
79 if (min2 < min1 || max2 > max1)
80 {
81 two_in_one = false;
82 }
83
84 box_box_loop
85 <
86 Dimension + 1,
87 DimensionCount
88 >::apply(b1, b2, overlaps, one_in_two, two_in_one);
89 }
90 };
91
92 template
93 <
94 std::size_t DimensionCount
95 >
96 struct box_box_loop<DimensionCount, DimensionCount>
97 {
98 template <typename Box1, typename Box2>
99 static inline void apply(Box1 const& , Box2 const&, bool&, bool&, bool&)
100 {
101 }
102 };
103
104 struct box_box
105 {
106 template <typename Box1, typename Box2>
107 static inline bool apply(Box1 const& b1, Box2 const& b2)
108 {
109 bool overlaps = true;
110 bool within1 = true;
111 bool within2 = true;
112 box_box_loop
113 <
114 0,
115 dimension<Box1>::type::value
116 >::apply(b1, b2, overlaps, within1, within2);
117
118 /*
119 \see http://docs.codehaus.org/display/GEOTDOC/02+Geometry+Relationships#02GeometryRelationships-Overlaps
120 where is stated that "inside" is not an "overlap",
121 this is true and is implemented as such.
122 */
123 return overlaps && ! within1 && ! within2;
124 }
125 };
126
127
128
129 }} // namespace detail::overlaps
130 #endif // DOXYGEN_NO_DETAIL
131
132 //struct not_implemented_for_this_geometry_type : public boost::false_type {};
133
134 #ifndef DOXYGEN_NO_DISPATCH
135 namespace dispatch
136 {
137
138
139 template
140 <
141 typename Geometry1,
142 typename Geometry2,
143 typename Tag1 = typename tag<Geometry1>::type,
144 typename Tag2 = typename tag<Geometry2>::type
145 >
146 struct overlaps: not_implemented<Tag1, Tag2>
147 {};
148
149
150 template <typename Box1, typename Box2>
151 struct overlaps<Box1, Box2, box_tag, box_tag>
152 : detail::overlaps::box_box
153 {};
154
155
156
157
158 } // namespace dispatch
159 #endif // DOXYGEN_NO_DISPATCH
160
161
162 /*!
163 \brief \brief_check2{overlap}
164 \ingroup overlaps
165 \return \return_check2{overlap}
166
167 \qbk{[include reference/algorithms/overlaps.qbk]}
168 */
169 template <typename Geometry1, typename Geometry2>
170 inline bool overlaps(Geometry1 const& geometry1, Geometry2 const& geometry2)
171 {
172 concept::check<Geometry1 const>();
173 concept::check<Geometry2 const>();
174
175 return dispatch::overlaps
176 <
177 Geometry1,
178 Geometry2
179 >::apply(geometry1, geometry2);
180 }
181
182 }} // namespace boost::geometry
183
184 #endif // BOOST_GEOMETRY_ALGORITHMS_OVERLAPS_HPP