Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-09-18 08:43:12

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