Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/geometry/algorithms/disjoint.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 // Copyright (c) 2013 Adam Wulkiewicz, Lodz, Poland. | |
| 7 | |
| 8 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library | |
| 9 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. | |
| 10 | |
| 11 // Use, modification and distribution is subject to the Boost Software License, | |
| 12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
| 13 // http://www.boost.org/LICENSE_1_0.txt) | |
| 14 | |
| 15 #ifndef BOOST_GEOMETRY_ALGORITHMS_DISJOINT_HPP | |
| 16 #define BOOST_GEOMETRY_ALGORITHMS_DISJOINT_HPP | |
| 17 | |
| 18 #include <cstddef> | |
| 19 #include <deque> | |
| 20 | |
| 21 #include <boost/mpl/if.hpp> | |
| 22 #include <boost/range.hpp> | |
| 23 | |
| 24 #include <boost/static_assert.hpp> | |
| 25 | |
| 26 #include <boost/geometry/core/access.hpp> | |
| 27 #include <boost/geometry/core/coordinate_dimension.hpp> | |
| 28 #include <boost/geometry/core/reverse_dispatch.hpp> | |
| 29 | |
| 30 #include <boost/geometry/algorithms/detail/disjoint.hpp> | |
| 31 #include <boost/geometry/algorithms/detail/for_each_range.hpp> | |
| 32 #include <boost/geometry/algorithms/detail/point_on_border.hpp> | |
| 33 #include <boost/geometry/algorithms/detail/overlay/get_turns.hpp> | |
| 34 #include <boost/geometry/algorithms/within.hpp> | |
| 35 | |
| 36 #include <boost/geometry/geometries/concepts/check.hpp> | |
| 37 | |
| 38 #include <boost/geometry/util/math.hpp> | |
| 39 | |
| 40 | |
| 41 namespace boost { namespace geometry | |
| 42 { | |
| 43 | |
| 44 | |
| 45 #ifndef DOXYGEN_NO_DETAIL | |
| 46 namespace detail { namespace disjoint | |
| 47 { | |
| 48 | |
| 49 template<typename Geometry> | |
| 50 struct check_each_ring_for_within | |
| 51 { | |
| 52 bool has_within; | |
| 53 Geometry const& m_geometry; | |
| 54 | |
| 55 inline check_each_ring_for_within(Geometry const& g) | |
| 56 : has_within(false) | |
| 57 , m_geometry(g) | |
| 58 {} | |
| 59 | |
| 60 template <typename Range> | |
| 61 inline void apply(Range const& range) | |
| 62 { | |
| 63 typename geometry::point_type<Range>::type p; | |
| 64 geometry::point_on_border(p, range); | |
| 65 if (geometry::within(p, m_geometry)) | |
| 66 { | |
| 67 has_within = true; | |
| 68 } | |
| 69 } | |
| 70 }; | |
| 71 | |
| 72 template <typename FirstGeometry, typename SecondGeometry> | |
| 73 inline bool rings_containing(FirstGeometry const& geometry1, | |
| 74 SecondGeometry const& geometry2) | |
| 75 { | |
| 76 check_each_ring_for_within<FirstGeometry> checker(geometry1); | |
| 77 geometry::detail::for_each_range(geometry2, checker); | |
| 78 return checker.has_within; | |
| 79 } | |
| 80 | |
| 81 | |
| 82 struct assign_disjoint_policy | |
| 83 { | |
| 84 // We want to include all points: | |
| 85 static bool const include_no_turn = true; | |
| 86 static bool const include_degenerate = true; | |
| 87 static bool const include_opposite = true; | |
| 88 | |
| 89 // We don't assign extra info: | |
| 90 template | |
| 91 < | |
| 92 typename Info, | |
| 93 typename Point1, | |
| 94 typename Point2, | |
| 95 typename IntersectionInfo, | |
| 96 typename DirInfo | |
| 97 > | |
| 98 static inline void apply(Info& , Point1 const& , Point2 const&, | |
| 99 IntersectionInfo const&, DirInfo const&) | |
| 100 {} | |
| 101 }; | |
| 102 | |
| 103 | |
| 104 template <typename Geometry1, typename Geometry2> | |
| 105 struct disjoint_linear | |
| 106 { | |
| 107 static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2) | |
| 108 { | |
| 109 typedef typename geometry::point_type<Geometry1>::type point_type; | |
| 110 | |
| 111 typedef overlay::turn_info<point_type> turn_info; | |
| 112 std::deque<turn_info> turns; | |
| 113 | |
| 114 // Specify two policies: | |
| 115 // 1) Stop at any intersection | |
| 116 // 2) In assignment, include also degenerate points (which are normally skipped) | |
| 117 disjoint_interrupt_policy policy; | |
| 118 geometry::get_turns | |
| 119 < | |
| 120 false, false, | |
| 121 assign_disjoint_policy | |
| 122 >(geometry1, geometry2, turns, policy); | |
| 123 if (policy.has_intersections) | |
| 124 { | |
| 125 return false; | |
| 126 } | |
| 127 | |
| 128 return true; | |
| 129 } | |
| 130 }; | |
| 131 | |
| 132 template <typename Segment1, typename Segment2> | |
| 133 struct disjoint_segment | |
| 134 { | |
| 135 static inline bool apply(Segment1 const& segment1, Segment2 const& segment2) | |
| 136 { | |
| 137 typedef typename point_type<Segment1>::type point_type; | |
| 138 | |
| 139 segment_intersection_points<point_type> is | |
| 140 = strategy::intersection::relate_cartesian_segments | |
| 141 < | |
| 142 policies::relate::segments_intersection_points | |
| 143 < | |
| 144 Segment1, | |
| 145 Segment2, | |
| 146 segment_intersection_points<point_type> | |
| 147 > | |
| 148 >::apply(segment1, segment2); | |
| 149 | |
| 150 return is.count == 0; | |
| 151 } | |
| 152 }; | |
| 153 | |
| 154 template <typename Geometry1, typename Geometry2> | |
| 155 struct general_areal | |
| 156 { | |
| 157 static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2) | |
| 158 { | |
| 159 if (! disjoint_linear<Geometry1, Geometry2>::apply(geometry1, geometry2)) | |
| 160 { | |
| 161 return false; | |
| 162 } | |
| 163 | |
| 164 // If there is no intersection of segments, they might located | |
| 165 // inside each other | |
| 166 if (rings_containing(geometry1, geometry2) | |
| 167 || rings_containing(geometry2, geometry1)) | |
| 168 { | |
| 169 return false; | |
| 170 } | |
| 171 | |
| 172 return true; | |
| 173 } | |
| 174 }; | |
| 175 | |
| 176 template <typename Segment, typename Box> | |
| 177 struct disjoint_segment_box | |
| 178 { | |
| 179 static inline bool apply(Segment const& segment, Box const& box) | |
| 180 { | |
| 181 typedef typename point_type<Segment>::type point_type; | |
| 182 point_type p0, p1; | |
| 183 geometry::detail::assign_point_from_index<0>(segment, p0); | |
| 184 geometry::detail::assign_point_from_index<1>(segment, p1); | |
| 185 | |
| 186 return ! detail::disjoint::segment_box_intersection<point_type, Box>::apply(p0, p1, box); | |
| 187 } | |
| 188 }; | |
| 189 | |
| 190 template <typename Linestring, typename Box> | |
| 191 struct disjoint_linestring_box | |
| 192 { | |
| 193 static inline bool apply(Linestring const& linestring, Box const& box) | |
| 194 { | |
| 195 typedef typename ::boost::range_value<Linestring>::type point_type; | |
| 196 typedef typename ::boost::range_const_iterator<Linestring>::type const_iterator; | |
| 197 typedef typename ::boost::range_size<Linestring>::type size_type; | |
| 198 | |
| 199 const size_type count = ::boost::size(linestring); | |
| 200 | |
| 201 if ( count == 0 ) | |
| 202 return false; | |
| 203 else if ( count == 1 ) | |
| 204 return detail::disjoint::point_box<point_type, Box, 0, dimension<point_type>::value> | |
| 205 ::apply(*::boost::begin(linestring), box); | |
| 206 else | |
| 207 { | |
| 208 const_iterator it0 = ::boost::begin(linestring); | |
| 209 const_iterator it1 = ::boost::begin(linestring) + 1; | |
| 210 const_iterator last = ::boost::end(linestring); | |
| 211 | |
| 212 for ( ; it1 != last ; ++it0, ++it1 ) | |
| 213 { | |
| 214 if ( detail::disjoint::segment_box_intersection<point_type, Box>::apply(*it0, *it1, box) ) | |
| 215 return false; | |
| 216 } | |
| 217 return true; | |
| 218 } | |
| 219 } | |
| 220 }; | |
| 221 | |
| 222 }} // namespace detail::disjoint | |
| 223 #endif // DOXYGEN_NO_DETAIL | |
| 224 | |
| 225 | |
| 226 #ifndef DOXYGEN_NO_DISPATCH | |
| 227 namespace dispatch | |
| 228 { | |
| 229 | |
| 230 | |
| 231 template | |
| 232 < | |
| 233 typename Geometry1, typename Geometry2, | |
| 234 std::size_t DimensionCount = dimension<Geometry1>::type::value, | |
| 235 typename Tag1 = typename tag<Geometry1>::type, | |
| 236 typename Tag2 = typename tag<Geometry2>::type, | |
| 237 bool Reverse = reverse_dispatch<Geometry1, Geometry2>::type::value | |
| 238 > | |
| 239 struct disjoint | |
| 240 : detail::disjoint::general_areal<Geometry1, Geometry2> | |
| 241 {}; | |
| 242 | |
| 243 | |
| 244 // If reversal is needed, perform it | |
| 245 template | |
| 246 < | |
| 247 typename Geometry1, typename Geometry2, | |
| 248 std::size_t DimensionCount, | |
| 249 typename Tag1, typename Tag2 | |
| 250 > | |
| 251 struct disjoint<Geometry1, Geometry2, DimensionCount, Tag1, Tag2, true> | |
| 252 : disjoint<Geometry2, Geometry1, DimensionCount, Tag2, Tag1, false> | |
| 253 { | |
| 254 static inline bool apply(Geometry1 const& g1, Geometry2 const& g2) | |
| 255 { | |
| 256 return disjoint | |
| 257 < | |
| 258 Geometry2, Geometry1, | |
| 259 DimensionCount, | |
| 260 Tag2, Tag1 | |
| 261 >::apply(g2, g1); | |
| 262 } | |
| 263 }; | |
| 264 | |
| 265 | |
| 266 template <typename Point1, typename Point2, std::size_t DimensionCount, bool Reverse> | |
| 267 struct disjoint<Point1, Point2, DimensionCount, point_tag, point_tag, Reverse> | |
| 268 : detail::disjoint::point_point<Point1, Point2, 0, DimensionCount> | |
| 269 {}; | |
| 270 | |
| 271 | |
| 272 template <typename Box1, typename Box2, std::size_t DimensionCount, bool Reverse> | |
| 273 struct disjoint<Box1, Box2, DimensionCount, box_tag, box_tag, Reverse> | |
| 274 : detail::disjoint::box_box<Box1, Box2, 0, DimensionCount> | |
| 275 {}; | |
| 276 | |
| 277 | |
| 278 template <typename Point, typename Box, std::size_t DimensionCount, bool Reverse> | |
| 279 struct disjoint<Point, Box, DimensionCount, point_tag, box_tag, Reverse> | |
| 280 : detail::disjoint::point_box<Point, Box, 0, DimensionCount> | |
| 281 {}; | |
| 282 | |
| 283 template <typename Point, typename Ring, std::size_t DimensionCount, bool Reverse> | |
| 284 struct disjoint<Point, Ring, DimensionCount, point_tag, ring_tag, Reverse> | |
| 285 : detail::disjoint::reverse_covered_by<Point, Ring> | |
| 286 {}; | |
| 287 | |
| 288 template <typename Point, typename Polygon, std::size_t DimensionCount, bool Reverse> | |
| 289 struct disjoint<Point, Polygon, DimensionCount, point_tag, polygon_tag, Reverse> | |
| 290 : detail::disjoint::reverse_covered_by<Point, Polygon> | |
| 291 {}; | |
| 292 | |
| 293 template <typename Linestring1, typename Linestring2, bool Reverse> | |
| 294 struct disjoint<Linestring1, Linestring2, 2, linestring_tag, linestring_tag, Reverse> | |
| 295 : detail::disjoint::disjoint_linear<Linestring1, Linestring2> | |
| 296 {}; | |
| 297 | |
| 298 template <typename Segment1, typename Segment2, bool Reverse> | |
| 299 struct disjoint<Segment1, Segment2, 2, segment_tag, segment_tag, Reverse> | |
| 300 : detail::disjoint::disjoint_segment<Segment1, Segment2> | |
| 301 {}; | |
| 302 | |
| 303 template <typename Linestring, typename Segment, bool Reverse> | |
| 304 struct disjoint<Linestring, Segment, 2, linestring_tag, segment_tag, Reverse> | |
| 305 : detail::disjoint::disjoint_linear<Linestring, Segment> | |
| 306 {}; | |
| 307 | |
| 308 template <typename Segment, typename Box, std::size_t DimensionCount, bool Reverse> | |
| 309 struct disjoint<Segment, Box, DimensionCount, segment_tag, box_tag, Reverse> | |
| 310 : detail::disjoint::disjoint_segment_box<Segment, Box> | |
| 311 {}; | |
| 312 | |
| 313 template <typename Linestring, typename Box, std::size_t DimensionCount, bool Reverse> | |
| 314 struct disjoint<Linestring, Box, DimensionCount, linestring_tag, box_tag, Reverse> | |
| 315 : detail::disjoint::disjoint_linestring_box<Linestring, Box> | |
| 316 {}; | |
| 317 | |
| 318 } // namespace dispatch | |
| 319 #endif // DOXYGEN_NO_DISPATCH | |
| 320 | |
| 321 | |
| 322 | |
| 323 /*! | |
| 324 \brief \brief_check2{are disjoint} | |
| 325 \ingroup disjoint | |
| 326 \tparam Geometry1 \tparam_geometry | |
| 327 \tparam Geometry2 \tparam_geometry | |
| 328 \param geometry1 \param_geometry | |
| 329 \param geometry2 \param_geometry | |
| 330 \return \return_check2{are disjoint} | |
| 331 | |
| 332 \qbk{[include reference/algorithms/disjoint.qbk]} | |
| 333 */ | |
| 334 template <typename Geometry1, typename Geometry2> | |
| 335 inline bool disjoint(Geometry1 const& geometry1, | |
| 336 Geometry2 const& geometry2) | |
| 337 { | |
| 338 concept::check_concepts_and_equal_dimensions | |
| 339 < | |
| 340 Geometry1 const, | |
| 341 Geometry2 const | |
| 342 >(); | |
| 343 | |
| 344 return dispatch::disjoint<Geometry1, Geometry2>::apply(geometry1, geometry2); | |
| 345 } | |
| 346 | |
| 347 | |
| 348 }} // namespace boost::geometry | |
| 349 | |
| 350 | |
| 351 #endif // BOOST_GEOMETRY_ALGORITHMS_DISJOINT_HPP |
