1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2
3 // Copyright (c) 2015 Barend Gehrels, Amsterdam, the Netherlands.
4
5 // This file was modified by Oracle on 2015, 2017.
6 // Modifications copyright (c) 2015-2017, Oracle and/or its affiliates.
7
8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
9
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)
13
14 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_SECTIONS_FUNCTIONS_HPP
15 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_SECTIONS_FUNCTIONS_HPP
16
17
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>
21
22
23 namespace boost { namespace geometry
24 {
25
26 #ifndef DOXYGEN_NO_DETAIL
27 namespace detail { namespace section
28 {
29
30 template
31 <
32 std::size_t Dimension,
33 typename Geometry,
34 typename CastedCSTag = typename tag_cast
35 <
36 typename cs_tag<Geometry>::type,
37 spherical_tag
38 >::type
39 >
40 struct preceding_check
41 {
42 template <typename Point, typename Box>
applyboost::geometry::detail::section::preceding_check43 static inline bool apply(int dir, Point const& point, Box const& /*point_box*/, Box const& other_box)
44 {
45 return (dir == 1 && get<Dimension>(point) < get<min_corner, Dimension>(other_box))
46 || (dir == -1 && get<Dimension>(point) > get<max_corner, Dimension>(other_box));
47 }
48 };
49
50 template <typename Geometry>
51 struct preceding_check<0, Geometry, spherical_tag>
52 {
53 template <typename Point, typename Box>
applyboost::geometry::detail::section::preceding_check54 static inline bool apply(int dir, Point const& point, Box const& point_box, Box const& other_box)
55 {
56 typedef typename select_coordinate_type
57 <
58 Point, Box
59 >::type calc_t;
60 typedef typename coordinate_system<Point>::type::units units_t;
61
62 calc_t const c0 = 0;
63
64 if (dir == 1)
65 {
66 calc_t const diff_min = math::longitude_distance_signed
67 <
68 units_t, calc_t
69 >(get<min_corner, 0>(other_box), get<0>(point));
70
71 calc_t const diff_min_min = math::longitude_distance_signed
72 <
73 units_t, calc_t
74 >(get<min_corner, 0>(other_box), get<min_corner, 0>(point_box));
75
76 return diff_min < c0 && diff_min_min <= c0 && diff_min_min <= diff_min;
77 }
78 else if (dir == -1)
79 {
80 calc_t const diff_max = math::longitude_distance_signed
81 <
82 units_t, calc_t
83 >(get<max_corner, 0>(other_box), get<0>(point));
84
85 calc_t const diff_max_max = math::longitude_distance_signed
86 <
87 units_t, calc_t
88 >(get<max_corner, 0>(other_box), get<max_corner, 0>(point_box));
89
90 return diff_max > c0 && diff_max_max >= c0 && diff_max <= diff_max_max;
91 }
92
93 return false;
94 }
95 };
96
97
98 template
99 <
100 std::size_t Dimension,
101 typename Point,
102 typename RobustBox,
103 typename RobustPolicy
104 >
preceding(int dir,Point const & point,RobustBox const & point_robust_box,RobustBox const & other_robust_box,RobustPolicy const & robust_policy)105 static inline bool preceding(int dir,
106 Point const& point,
107 RobustBox const& point_robust_box,
108 RobustBox const& other_robust_box,
109 RobustPolicy const& robust_policy)
110 {
111 typename geometry::robust_point_type<Point, RobustPolicy>::type robust_point;
112 geometry::recalculate(robust_point, point, robust_policy);
113 return preceding_check<Dimension, Point>::apply(dir, robust_point, point_robust_box, other_robust_box);
114 }
115
116 template
117 <
118 std::size_t Dimension,
119 typename Point,
120 typename RobustBox,
121 typename RobustPolicy
122 >
exceeding(int dir,Point const & point,RobustBox const & point_robust_box,RobustBox const & other_robust_box,RobustPolicy const & robust_policy)123 static inline bool exceeding(int dir,
124 Point const& point,
125 RobustBox const& point_robust_box,
126 RobustBox const& other_robust_box,
127 RobustPolicy const& robust_policy)
128 {
129 return preceding<Dimension>(-dir, point, point_robust_box, other_robust_box, robust_policy);
130 }
131
132
133 }} // namespace detail::section
134 #endif
135
136
137 }} // namespace boost::geometry
138
139 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_SECTIONS_FUNCTIONS_HPP
140