Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:03

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
0004 // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
0005 // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
0006 // Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland.
0007 
0008 // This file was modified by Oracle on 2013-2022.
0009 // Modifications copyright (c) 2013-2022, Oracle and/or its affiliates.
0010 
0011 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0012 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
0013 
0014 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
0015 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
0016 
0017 // Use, modification and distribution is subject to the Boost Software License,
0018 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0019 // http://www.boost.org/LICENSE_1_0.txt)
0020 
0021 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_AREAL_AREAL_HPP
0022 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_AREAL_AREAL_HPP
0023 
0024 #include <boost/geometry/core/point_type.hpp>
0025 
0026 #include <boost/geometry/algorithms/detail/covered_by/implementation.hpp>
0027 #include <boost/geometry/algorithms/detail/for_each_range.hpp>
0028 #include <boost/geometry/algorithms/detail/point_on_border.hpp>
0029 
0030 #include <boost/geometry/algorithms/detail/disjoint/linear_linear.hpp>
0031 #include <boost/geometry/algorithms/detail/disjoint/segment_box.hpp>
0032 
0033 #include <boost/geometry/geometries/helper_geometry.hpp>
0034 
0035 #include <boost/geometry/algorithms/for_each.hpp>
0036 
0037 
0038 namespace boost { namespace geometry
0039 {
0040 
0041 
0042 #ifndef DOXYGEN_NO_DETAIL
0043 namespace detail { namespace disjoint
0044 {
0045 
0046 template <typename Geometry1, typename Geometry2, typename Strategy>
0047 inline bool point_on_border_covered_by(Geometry1 const& geometry1,
0048                                        Geometry2 const& geometry2,
0049                                        Strategy const& strategy)
0050 {
0051     using point_type = typename geometry::point_type<Geometry1>::type;
0052     typename helper_geometry<point_type>::type pt;
0053     return geometry::point_on_border(pt, geometry1)
0054         && geometry::covered_by(pt, geometry2, strategy);
0055 }
0056 
0057 
0058 /*!
0059 \tparam Strategy point_in_geometry strategy
0060 */
0061 template <typename Geometry1, typename Geometry2, typename Strategy>
0062 inline bool rings_containing(Geometry1 const& geometry1,
0063                              Geometry2 const& geometry2,
0064                              Strategy const& strategy)
0065 {
0066     return geometry::detail::any_range_of(geometry2, [&](auto const& range)
0067     {
0068         return point_on_border_covered_by(range, geometry1, strategy);
0069     });
0070 }
0071 
0072 
0073 
0074 template <typename Geometry1, typename Geometry2>
0075 struct areal_areal
0076 {
0077     /*!
0078     \tparam Strategy relate (segments intersection) strategy
0079     */
0080     template <typename Strategy>
0081     static inline bool apply(Geometry1 const& geometry1,
0082                              Geometry2 const& geometry2,
0083                              Strategy const& strategy)
0084     {
0085         if ( ! disjoint_linear<Geometry1, Geometry2>::apply(geometry1, geometry2, strategy) )
0086         {
0087             return false;
0088         }
0089 
0090         // If there is no intersection of segments, they might located
0091         // inside each other
0092 
0093         // We check that using a point on the border (external boundary),
0094         // and see if that is contained in the other geometry. And vice versa.
0095 
0096         if ( rings_containing(geometry1, geometry2, strategy)
0097           || rings_containing(geometry2, geometry1, strategy) )
0098         {
0099             return false;
0100         }
0101 
0102         return true;
0103     }
0104 };
0105 
0106 
0107 template <typename Areal, typename Box>
0108 struct areal_box
0109 {
0110     /*!
0111     \tparam Strategy relate (segments intersection) strategy
0112     */
0113     template <typename Strategy>
0114     static inline bool apply(Areal const& areal,
0115                              Box const& box,
0116                              Strategy const& strategy)
0117     {
0118         if (! geometry::all_segments_of(areal, [&](auto const& s)
0119               {
0120                   return disjoint_segment_box::apply(s, box, strategy);
0121               }) )
0122         {
0123             return false;
0124         }
0125 
0126         // If there is no intersection of any segment and box,
0127         // the box might be located inside areal geometry
0128 
0129         if ( point_on_border_covered_by(box, areal, strategy) )
0130         {
0131             return false;
0132         }
0133 
0134         return true;
0135     }
0136 };
0137 
0138 
0139 }} // namespace detail::disjoint
0140 #endif // DOXYGEN_NO_DETAIL
0141 
0142 
0143 
0144 
0145 #ifndef DOXYGEN_NO_DISPATCH
0146 namespace dispatch
0147 {
0148 
0149 
0150 template <typename Areal1, typename Areal2>
0151 struct disjoint<Areal1, Areal2, 2, areal_tag, areal_tag, false>
0152     : detail::disjoint::areal_areal<Areal1, Areal2>
0153 {};
0154 
0155 
0156 template <typename Areal, typename Box>
0157 struct disjoint<Areal, Box, 2, areal_tag, box_tag, false>
0158     : detail::disjoint::areal_box<Areal, Box>
0159 {};
0160 
0161 
0162 } // namespace dispatch
0163 #endif // DOXYGEN_NO_DISPATCH
0164 
0165 
0166 }} // namespace boost::geometry
0167 
0168 
0169 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_AREAL_AREAL_HPP