1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
7 // This file was modified by Oracle on 2014, 2015.
8 // Modifications copyright (c) 2014-2015 Oracle and/or its affiliates.
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
15 // Use, modification and distribution is subject to the Boost Software License,
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
19 #ifndef BOOST_GEOMETRY_ALGORITHMS_OVERLAPS_HPP
20 #define BOOST_GEOMETRY_ALGORITHMS_OVERLAPS_HPP
25 #include <boost/geometry/core/access.hpp>
27 #include <boost/geometry/algorithms/not_implemented.hpp>
29 #include <boost/geometry/geometries/concepts/check.hpp>
31 #include <boost/geometry/algorithms/relate.hpp>
32 #include <boost/geometry/algorithms/detail/relate/relate_impl.hpp>
35 namespace boost { namespace geometry
38 #ifndef DOXYGEN_NO_DETAIL
39 namespace detail { namespace overlaps
44 std::size_t Dimension,
45 std::size_t DimensionCount
49 template <typename Box1, typename Box2>
50 static inline void apply(Box1 const& b1, Box2 const& b2,
51 bool& overlaps, bool& one_in_two, bool& two_in_one)
53 assert_dimension_equal<Box1, Box2>();
55 typedef typename coordinate_type<Box1>::type coordinate_type1;
56 typedef typename coordinate_type<Box2>::type coordinate_type2;
58 coordinate_type1 const& min1 = get<min_corner, Dimension>(b1);
59 coordinate_type1 const& max1 = get<max_corner, Dimension>(b1);
60 coordinate_type2 const& min2 = get<min_corner, Dimension>(b2);
61 coordinate_type2 const& max2 = get<max_corner, Dimension>(b2);
63 // We might use the (not yet accepted) Boost.Interval
64 // submission in the future
69 // in any dimension -> no overlap
70 if (max1 <= min2 || min1 >= max2)
77 // B1: |--------------------|
78 // B2: |-------------|
79 // in all dimensions -> within, then no overlap
80 // B1: |--------------------|
81 // B2: |-------------|
82 // this is "within-touch" -> then no overlap. So use < and >
83 if (min1 < min2 || max1 > max2)
88 // Same other way round
89 if (min2 < min1 || max2 > max1)
98 >::apply(b1, b2, overlaps, one_in_two, two_in_one);
104 std::size_t DimensionCount
106 struct box_box_loop<DimensionCount, DimensionCount>
108 template <typename Box1, typename Box2>
109 static inline void apply(Box1 const& , Box2 const&, bool&, bool&, bool&)
116 template <typename Box1, typename Box2>
117 static inline bool apply(Box1 const& b1, Box2 const& b2)
119 bool overlaps = true;
125 dimension<Box1>::type::value
126 >::apply(b1, b2, overlaps, within1, within2);
129 \see http://docs.codehaus.org/display/GEOTDOC/02+Geometry+Relationships#02GeometryRelationships-Overlaps
130 where is stated that "inside" is not an "overlap",
131 this is true and is implemented as such.
133 return overlaps && ! within1 && ! within2;
137 }} // namespace detail::overlaps
138 #endif // DOXYGEN_NO_DETAIL
140 //struct not_implemented_for_this_geometry_type : public boost::false_type {};
142 #ifndef DOXYGEN_NO_DISPATCH
151 typename Tag1 = typename tag<Geometry1>::type,
152 typename Tag2 = typename tag<Geometry2>::type
155 : detail::relate::relate_impl
157 detail::de9im::static_mask_overlaps_type,
164 template <typename Box1, typename Box2>
165 struct overlaps<Box1, Box2, box_tag, box_tag>
166 : detail::overlaps::box_box
169 } // namespace dispatch
170 #endif // DOXYGEN_NO_DISPATCH
174 \brief \brief_check2{overlap}
176 \tparam Geometry1 \tparam_geometry
177 \tparam Geometry2 \tparam_geometry
178 \param geometry1 \param_geometry
179 \param geometry2 \param_geometry
180 \return \return_check2{overlap}
182 \qbk{[include reference/algorithms/overlaps.qbk]}
184 template <typename Geometry1, typename Geometry2>
185 inline bool overlaps(Geometry1 const& geometry1, Geometry2 const& geometry2)
187 concepts::check<Geometry1 const>();
188 concepts::check<Geometry2 const>();
190 return dispatch::overlaps
194 >::apply(geometry1, geometry2);
197 }} // namespace boost::geometry
199 #endif // BOOST_GEOMETRY_ALGORITHMS_OVERLAPS_HPP