// Boost.Geometry (aka GGL, Generic Geometry Library) // Copyright (c) 2007-2011 Barend Gehrels, Amsterdam, the Netherlands. // Copyright (c) 2008-2011 Bruno Lalande, Paris, France. // Copyright (c) 2009-2011 Mateusz Loskot, London, UK. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. // Use, modification and distribution is subject to the Boost Software License, // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_GEOMETRY_ALGORITHMS_DISJOINT_HPP #define BOOST_GEOMETRY_ALGORITHMS_DISJOINT_HPP #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace boost { namespace geometry { #ifndef DOXYGEN_NO_DETAIL namespace detail { namespace disjoint { template struct disjoint_linear { static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2) { typedef typename geometry::point_type::type point_type; typedef overlay::turn_info turn_info; std::deque turns; // Get (and stop on) any intersection disjoint_interrupt_policy policy; geometry::get_turns < false, false, overlay::assign_null_policy >(geometry1, geometry2, turns, policy); if (policy.has_intersections) { return false; } return true; } }; template struct disjoint_segment { static inline bool apply(Segment1 const& segment1, Segment2 const& segment2) { typedef typename point_type::type point_type; segment_intersection_points is = strategy::intersection::relate_cartesian_segments < policies::relate::segments_intersection_points < Segment1, Segment2, segment_intersection_points > >::apply(segment1, segment2); return is.count == 0; } }; template struct general_areal { static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2) { if (! disjoint_linear::apply(geometry1, geometry2)) { return false; } typedef typename geometry::point_type::type point_type; // If there is no intersection of segments, they might located // inside each other point_type p1; geometry::point_on_border(p1, geometry1); if (geometry::within(p1, geometry2)) { return false; } typename geometry::point_type::type p2; geometry::point_on_border(p2, geometry2); if (geometry::within(p2, geometry1)) { return false; } return true; } }; }} // namespace detail::disjoint #endif // DOXYGEN_NO_DETAIL #ifndef DOXYGEN_NO_DISPATCH namespace dispatch { template < typename GeometryTag1, typename GeometryTag2, typename Geometry1, typename Geometry2, std::size_t DimensionCount > struct disjoint : detail::disjoint::general_areal {}; template struct disjoint : detail::disjoint::point_point {}; template struct disjoint : detail::disjoint::box_box {}; template struct disjoint : detail::disjoint::point_box {}; template struct disjoint : detail::disjoint::disjoint_linear {}; template struct disjoint : detail::disjoint::disjoint_segment {}; template struct disjoint : detail::disjoint::disjoint_linear {}; template < typename GeometryTag1, typename GeometryTag2, typename Geometry1, typename Geometry2, std::size_t DimensionCount > struct disjoint_reversed { static inline bool apply(Geometry1 const& g1, Geometry2 const& g2) { return disjoint < GeometryTag2, GeometryTag1, Geometry2, Geometry1, DimensionCount >::apply(g2, g1); } }; } // namespace dispatch #endif // DOXYGEN_NO_DISPATCH /*! \brief \brief_check2{are disjoint} \ingroup disjoint \tparam Geometry1 \tparam_geometry \tparam Geometry2 \tparam_geometry \param geometry1 \param_geometry \param geometry2 \param_geometry \return \return_check2{are disjoint} */ template inline bool disjoint(Geometry1 const& geometry1, Geometry2 const& geometry2) { concept::check_concepts_and_equal_dimensions < Geometry1 const, Geometry2 const >(); return boost::mpl::if_c < reverse_dispatch::type::value, dispatch::disjoint_reversed < typename tag::type, typename tag::type, Geometry1, Geometry2, dimension::type::value >, dispatch::disjoint < typename tag::type, typename tag::type, Geometry1, Geometry2, dimension::type::value > >::type::apply(geometry1, geometry2); } }} // namespace boost::geometry #endif // BOOST_GEOMETRY_ALGORITHMS_DISJOINT_HPP