1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2015 Barend Gehrels, Amsterdam, the Netherlands.
5 // This file was modified by Oracle on 2015, 2017.
6 // Modifications copyright (c) 2015-2017, Oracle and/or its affiliates.
8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
14 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_SECTIONS_FUNCTIONS_HPP
15 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_SECTIONS_FUNCTIONS_HPP
18 #include <boost/geometry/core/access.hpp>
19 #include <boost/geometry/algorithms/detail/recalculate.hpp>
20 #include <boost/geometry/policies/robustness/robust_point_type.hpp>
22 // For spherical/geographic longitudes covered_by point/box
23 #include <boost/geometry/strategies/cartesian/point_in_box.hpp>
26 namespace boost { namespace geometry
29 #ifndef DOXYGEN_NO_DETAIL
30 namespace detail { namespace section
35 std::size_t Dimension,
37 typename CastedCSTag = typename tag_cast
39 typename cs_tag<Geometry>::type,
43 struct preceding_check
45 template <typename Point, typename Box>
46 static inline bool apply(int dir, Point const& point, Box const& /*point_box*/, Box const& other_box)
48 return (dir == 1 && get<Dimension>(point) < get<min_corner, Dimension>(other_box))
49 || (dir == -1 && get<Dimension>(point) > get<max_corner, Dimension>(other_box));
53 template <typename Geometry>
54 struct preceding_check<0, Geometry, spherical_tag>
56 template <typename Point, typename Box>
57 static inline bool apply(int dir, Point const& point, Box const& point_box, Box const& other_box)
59 typedef typename select_coordinate_type
63 typedef typename coordinate_system<Point>::type::units units_t;
67 calc_t const value = get<0>(point);
68 calc_t const other_min = get<min_corner, 0>(other_box);
69 calc_t const other_max = get<max_corner, 0>(other_box);
71 bool const pt_covered = strategy::within::covered_by_range
73 Point, 0, spherical_tag
85 calc_t const diff_min = math::longitude_distance_signed
90 calc_t const diff_min_min = math::longitude_distance_signed
93 >(other_min, get<min_corner, 0>(point_box));
95 return diff_min < c0 && diff_min_min <= c0 && diff_min_min <= diff_min;
99 calc_t const diff_max = math::longitude_distance_signed
104 calc_t const diff_max_max = math::longitude_distance_signed
107 >(other_max, get<max_corner, 0>(point_box));
109 return diff_max > c0 && diff_max_max >= c0 && diff_max <= diff_max_max;
119 std::size_t Dimension,
122 typename RobustPolicy
124 static inline bool preceding(int dir,
126 RobustBox const& point_robust_box,
127 RobustBox const& other_robust_box,
128 RobustPolicy const& robust_policy)
130 typename geometry::robust_point_type<Point, RobustPolicy>::type robust_point;
131 geometry::recalculate(robust_point, point, robust_policy);
132 return preceding_check<Dimension, Point>::apply(dir, robust_point, point_robust_box, other_robust_box);
137 std::size_t Dimension,
140 typename RobustPolicy
142 static inline bool exceeding(int dir,
144 RobustBox const& point_robust_box,
145 RobustBox const& other_robust_box,
146 RobustPolicy const& robust_policy)
148 return preceding<Dimension>(-dir, point, point_robust_box, other_robust_box, robust_policy);
152 }} // namespace detail::section
156 }} // namespace boost::geometry
158 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_SECTIONS_FUNCTIONS_HPP