1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
6 // Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
8 // This file was modified by Oracle on 2013-2017.
9 // Modifications copyright (c) 2013-2017, Oracle and/or its affiliates.
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
14 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
15 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
17 // Use, modification and distribution is subject to the Boost Software License,
18 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
19 // http://www.boost.org/LICENSE_1_0.txt)
21 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_BOX_BOX_HPP
22 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_BOX_BOX_HPP
26 #include <boost/geometry/core/access.hpp>
27 #include <boost/geometry/core/tags.hpp>
29 #include <boost/geometry/algorithms/dispatch/disjoint.hpp>
31 #include <boost/geometry/util/normalize_spheroidal_coordinates.hpp>
32 #include <boost/geometry/util/select_most_precise.hpp>
35 namespace boost { namespace geometry
38 #ifndef DOXYGEN_NO_DETAIL
39 namespace detail { namespace disjoint
44 typename Box1, typename Box2,
45 std::size_t Dimension = 0,
46 std::size_t DimensionCount = dimension<Box1>::value,
47 typename CSTag = typename tag_cast
49 typename cs_tag<Box1>::type,
55 template <typename Strategy>
56 static inline bool apply(Box1 const& box1, Box2 const& box2, Strategy const&)
58 return apply(box1, box2);
61 static inline bool apply(Box1 const& box1, Box2 const& box2)
63 if (get<max_corner, Dimension>(box1) < get<min_corner, Dimension>(box2))
67 if (get<min_corner, Dimension>(box1) > get<max_corner, Dimension>(box2))
74 Dimension + 1, DimensionCount
80 template <typename Box1, typename Box2, std::size_t DimensionCount, typename CSTag>
81 struct box_box<Box1, Box2, DimensionCount, DimensionCount, CSTag>
83 static inline bool apply(Box1 const& , Box2 const& )
90 template <typename Box1, typename Box2, std::size_t DimensionCount>
91 struct box_box<Box1, Box2, 0, DimensionCount, spherical_tag>
93 template <typename Strategy>
94 static inline bool apply(Box1 const& box1, Box2 const& box2, Strategy const&)
96 return apply(box1, box2);
99 static inline bool apply(Box1 const& box1, Box2 const& box2)
101 typedef typename geometry::select_most_precise
103 typename coordinate_type<Box1>::type,
104 typename coordinate_type<Box2>::type
106 typedef typename coordinate_system<Box1>::type::units units_t;
107 typedef math::detail::constants_on_spheroid<calc_t, units_t> constants;
109 calc_t const b1_min = get<min_corner, 0>(box1);
110 calc_t const b1_max = get<max_corner, 0>(box1);
111 calc_t const b2_min = get<min_corner, 0>(box2);
112 calc_t const b2_max = get<max_corner, 0>(box2);
114 // min <= max <=> diff >= 0
115 calc_t const diff1 = b1_max - b1_min;
116 calc_t const diff2 = b2_max - b2_min;
118 // check the intersection if neither box cover the whole globe
119 if (diff1 < constants::period() && diff2 < constants::period())
121 // calculate positive longitude translation with b1_min as origin
122 calc_t const diff_min = math::longitude_distance_unsigned<units_t>(b1_min, b2_min);
123 calc_t const b2_min_transl = b1_min + diff_min; // always right of b1_min
125 if (b2_min_transl > b1_max // b2_min right of b1_max
126 && b2_min_transl - constants::period() + diff2 < b1_min) // b2_max left of b1_min
136 >::apply(box1, box2);
142 \brief Internal utility function to detect if boxes are disjoint
143 \note Is used from other algorithms, declared separately
144 to avoid circular references
146 template <typename Box1, typename Box2>
147 inline bool disjoint_box_box(Box1 const& box1, Box2 const& box2)
149 return box_box<Box1, Box2>::apply(box1, box2);
153 }} // namespace detail::disjoint
154 #endif // DOXYGEN_NO_DETAIL
157 #ifndef DOXYGEN_NO_DISPATCH
162 template <typename Box1, typename Box2, std::size_t DimensionCount>
163 struct disjoint<Box1, Box2, DimensionCount, box_tag, box_tag, false>
164 : detail::disjoint::box_box<Box1, Box2, 0, DimensionCount>
168 } // namespace dispatch
169 #endif // DOXYGEN_NO_DISPATCH
172 }} // namespace boost::geometry
175 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_BOX_BOX_HPP