]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/geometry/index/detail/algorithms/intersection_content.hpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / boost / geometry / index / detail / algorithms / intersection_content.hpp
CommitLineData
7c673cae
FG
1// Boost.Geometry Index
2//
3// boxes union/intersection area/volume
4//
92f5a8d4
TL
5// Copyright (c) 2011-2018 Adam Wulkiewicz, Lodz, Poland.
6//
1e59de90
TL
7// This file was modified by Oracle on 2019-2021.
8// Modifications copyright (c) 2019-2021 Oracle and/or its affiliates.
92f5a8d4 9// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7c673cae
FG
10//
11// Use, modification and distribution is subject to the Boost Software License,
12// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13// http://www.boost.org/LICENSE_1_0.txt)
14
15#ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_INTERSECTION_CONTENT_HPP
16#define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_INTERSECTION_CONTENT_HPP
17
b32b8144
FG
18#include <boost/geometry/algorithms/detail/disjoint/box_box.hpp>
19#include <boost/geometry/algorithms/detail/overlay/intersection_box_box.hpp>
20
7c673cae
FG
21#include <boost/geometry/index/detail/algorithms/content.hpp>
22
1e59de90
TL
23#include <boost/geometry/strategies/default_strategy.hpp>
24#include <boost/geometry/strategies/disjoint.hpp>
25
7c673cae
FG
26namespace boost { namespace geometry { namespace index { namespace detail {
27
92f5a8d4
TL
28// Util to distinguish between default and non-default index strategy
29template <typename Box, typename Strategy>
1e59de90 30inline bool disjoint_box_box(Box const& box1, Box const& box2, Strategy const& s)
92f5a8d4 31{
1e59de90 32 return geometry::detail::disjoint::disjoint_box_box(box1, box2, s);
92f5a8d4
TL
33}
34
35template <typename Box>
36inline bool disjoint_box_box(Box const& box1, Box const& box2, default_strategy const& )
37{
38 typedef typename strategy::disjoint::services::default_strategy<Box, Box>::type strategy_type;
39 return geometry::detail::disjoint::disjoint_box_box(box1, box2, strategy_type());
40}
41
7c673cae 42/**
92f5a8d4 43 * \brief Compute the area, volume, ... of the intersection of b1 and b2
7c673cae 44 */
92f5a8d4
TL
45template <typename Box, typename Strategy>
46inline typename default_content_result<Box>::type intersection_content(Box const& box1, Box const& box2, Strategy const& strategy)
7c673cae 47{
92f5a8d4
TL
48 bool const intersects = ! index::detail::disjoint_box_box(box1, box2, strategy);
49
50 // NOTE: the code below may be inconsistent with the disjoint_box_box()
51 // however intersection_box_box checks if the boxes intersect on the fly so it should be ok
52 // but this also means that disjoint_box_box() is probably not needed
b32b8144
FG
53
54 if ( intersects )
7c673cae
FG
55 {
56 Box box_intersection;
b32b8144
FG
57 bool const ok = geometry::detail::intersection::intersection_box_box
58 <
59 0, geometry::dimension<Box>::value
60 >::apply(box1, box2, 0, box_intersection, 0);
61 if ( ok )
62 {
63 return index::detail::content(box_intersection);
64 }
7c673cae
FG
65 }
66 return 0;
67}
68
92f5a8d4
TL
69template <typename Box>
70inline typename default_content_result<Box>::type intersection_content(Box const& box1, Box const& box2)
71{
72 return intersection_content(box1, box2, default_strategy());
73}
74
7c673cae
FG
75}}}} // namespace boost::geometry::index::detail
76
77#endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_INTERSECTION_CONTENT_HPP