1 // Boost.Geometry (aka GGL, Generic Geometry Library)
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.
7 // This file was modified by Oracle on 2014.
8 // Modifications copyright (c) 2014 Oracle and/or its affiliates.
10 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
11 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
13 // Use, modification and distribution is subject to the Boost Software License,
14 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
17 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
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/detail/relate/relate.hpp>
33 namespace boost { namespace geometry
36 #ifndef DOXYGEN_NO_DETAIL
37 namespace detail { namespace overlaps
42 std::size_t Dimension,
43 std::size_t DimensionCount
47 template <typename Box1, typename Box2>
48 static inline void apply(Box1 const& b1, Box2 const& b2,
49 bool& overlaps, bool& one_in_two, bool& two_in_one)
51 assert_dimension_equal<Box1, Box2>();
53 typedef typename coordinate_type<Box1>::type coordinate_type1;
54 typedef typename coordinate_type<Box2>::type coordinate_type2;
56 coordinate_type1 const& min1 = get<min_corner, Dimension>(b1);
57 coordinate_type1 const& max1 = get<max_corner, Dimension>(b1);
58 coordinate_type2 const& min2 = get<min_corner, Dimension>(b2);
59 coordinate_type2 const& max2 = get<max_corner, Dimension>(b2);
61 // We might use the (not yet accepted) Boost.Interval
62 // submission in the future
67 // in any dimension -> no overlap
68 if (max1 <= min2 || min1 >= max2)
75 // B1: |--------------------|
76 // B2: |-------------|
77 // in all dimensions -> within, then no overlap
78 // B1: |--------------------|
79 // B2: |-------------|
80 // this is "within-touch" -> then no overlap. So use < and >
81 if (min1 < min2 || max1 > max2)
85 // Same other way round
86 if (min2 < min1 || max2 > max1)
95 >::apply(b1, b2, overlaps, one_in_two, two_in_one);
101 std::size_t DimensionCount
103 struct box_box_loop<DimensionCount, DimensionCount>
105 template <typename Box1, typename Box2>
106 static inline void apply(Box1 const& , Box2 const&, bool&, bool&, bool&)
113 template <typename Box1, typename Box2>
114 static inline bool apply(Box1 const& b1, Box2 const& b2)
116 bool overlaps = true;
122 dimension<Box1>::type::value
123 >::apply(b1, b2, overlaps, within1, within2);
126 \see http://docs.codehaus.org/display/GEOTDOC/02+Geometry+Relationships#02GeometryRelationships-Overlaps
127 where is stated that "inside" is not an "overlap",
128 this is true and is implemented as such.
130 return overlaps && ! within1 && ! within2;
134 }} // namespace detail::overlaps
135 #endif // DOXYGEN_NO_DETAIL
137 //struct not_implemented_for_this_geometry_type : public boost::false_type {};
139 #ifndef DOXYGEN_NO_DISPATCH
148 typename Tag1 = typename tag<Geometry1>::type,
149 typename Tag2 = typename tag<Geometry2>::type
152 : detail::relate::relate_base
154 detail::relate::static_mask_overlaps_type,
161 template <typename Box1, typename Box2>
162 struct overlaps<Box1, Box2, box_tag, box_tag>
163 : detail::overlaps::box_box
166 } // namespace dispatch
167 #endif // DOXYGEN_NO_DISPATCH
171 \brief \brief_check2{overlap}
173 \tparam Geometry1 \tparam_geometry
174 \tparam Geometry2 \tparam_geometry
175 \param geometry1 \param_geometry
176 \param geometry2 \param_geometry
177 \return \return_check2{overlap}
179 \qbk{[include reference/algorithms/overlaps.qbk]}
181 template <typename Geometry1, typename Geometry2>
182 inline bool overlaps(Geometry1 const& geometry1, Geometry2 const& geometry2)
184 concept::check<Geometry1 const>();
185 concept::check<Geometry2 const>();
187 return dispatch::overlaps
191 >::apply(geometry1, geometry2);
194 }} // namespace boost::geometry
196 #endif // BOOST_GEOMETRY_ALGORITHMS_OVERLAPS_HPP