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