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