Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Boost.Geometry Index
0002 //
0003 // boxes union/intersection area/volume
0004 //
0005 // Copyright (c) 2011-2018 Adam Wulkiewicz, Lodz, Poland.
0006 //
0007 // This file was modified by Oracle on 2019-2021.
0008 // Modifications copyright (c) 2019-2021 Oracle and/or its affiliates.
0009 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0010 //
0011 // Use, modification and distribution is subject to the Boost Software License,
0012 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0013 // http://www.boost.org/LICENSE_1_0.txt)
0014 
0015 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_INTERSECTION_CONTENT_HPP
0016 #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_INTERSECTION_CONTENT_HPP
0017 
0018 #include <boost/geometry/algorithms/detail/disjoint/box_box.hpp>
0019 #include <boost/geometry/algorithms/detail/intersection/box_box_implementation.hpp>
0020 
0021 #include <boost/geometry/index/detail/algorithms/content.hpp>
0022 
0023 #include <boost/geometry/strategies/default_strategy.hpp>
0024 #include <boost/geometry/strategies/disjoint.hpp>
0025 
0026 namespace boost { namespace geometry { namespace index { namespace detail {
0027 
0028 // Util to distinguish between default and non-default index strategy
0029 template <typename Box, typename Strategy>
0030 inline bool disjoint_box_box(Box const& box1, Box const& box2, Strategy const& s)
0031 {
0032     return geometry::detail::disjoint::disjoint_box_box(box1, box2, s);
0033 }
0034 
0035 template <typename Box>
0036 inline bool disjoint_box_box(Box const& box1, Box const& box2, default_strategy const& )
0037 {
0038     typedef typename strategy::disjoint::services::default_strategy<Box, Box>::type strategy_type;
0039     return geometry::detail::disjoint::disjoint_box_box(box1, box2, strategy_type());
0040 }
0041 
0042 /**
0043  * \brief Compute the area, volume, ... of the intersection of b1 and b2
0044  */
0045 template <typename Box, typename Strategy>
0046 inline typename default_content_result<Box>::type intersection_content(Box const& box1, Box const& box2, Strategy const& strategy)
0047 {
0048     bool const intersects = ! index::detail::disjoint_box_box(box1, box2, strategy);
0049 
0050     // NOTE: the code below may be inconsistent with the disjoint_box_box()
0051     // however intersection_box_box checks if the boxes intersect on the fly so it should be ok
0052     // but this also means that disjoint_box_box() is probably not needed
0053 
0054     if ( intersects )
0055     {
0056         Box box_intersection;
0057         bool const ok = geometry::detail::intersection::intersection_box_box
0058                             <
0059                                 0, geometry::dimension<Box>::value
0060                             >::apply(box1, box2, 0, box_intersection, 0);
0061         if ( ok )
0062         {
0063             return index::detail::content(box_intersection);
0064         }
0065     }
0066     return 0;
0067 }
0068 
0069 template <typename Box>
0070 inline typename default_content_result<Box>::type intersection_content(Box const& box1, Box const& box2)
0071 {
0072     return intersection_content(box1, box2, default_strategy());
0073 }
0074 
0075 }}}} // namespace boost::geometry::index::detail
0076 
0077 #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_INTERSECTION_CONTENT_HPP