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.
7 // This file was modified by Oracle on 2015-2017.
8 // Modifications copyright (c) 2015-2017, Oracle and/or its affiliates.
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
15 // Use, modification and distribution is subject to the Boost Software License,
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
19 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_POINT_IN_BOX_HPP
20 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_POINT_IN_BOX_HPP
23 #include <boost/geometry/core/access.hpp>
24 #include <boost/geometry/core/coordinate_dimension.hpp>
25 #include <boost/geometry/strategies/covered_by.hpp>
26 #include <boost/geometry/strategies/within.hpp>
27 #include <boost/geometry/util/normalize_spheroidal_coordinates.hpp>
30 namespace boost { namespace geometry { namespace strategy
38 template <typename Value1, typename Value2>
39 static inline bool apply(Value1 const& value, Value2 const& min_value, Value2 const& max_value)
41 return value > min_value && value < max_value;
45 struct covered_by_coord
47 template <typename Value1, typename Value2>
48 static inline bool apply(Value1 const& value, Value2 const& min_value, Value2 const& max_value)
50 return value >= min_value && value <= max_value;
54 template <typename Geometry, std::size_t Dimension, typename CSTag>
60 template <typename Geometry, std::size_t Dimension, typename CSTag>
61 struct covered_by_range
66 // NOTE: the result would be the same if instead of structs defined below
67 // the above xxx_range were used with the following arguments:
68 // (min_value + diff_min, min_value, max_value)
69 struct within_longitude_diff
71 template <typename CalcT>
72 static inline bool apply(CalcT const& diff_min, CalcT const& min_value, CalcT const& max_value)
76 && (min_value + diff_min < max_value
77 /*|| max_value - diff_min > min_value*/);
81 struct covered_by_longitude_diff
83 template <typename CalcT>
84 static inline bool apply(CalcT const& diff_min, CalcT const& min_value, CalcT const& max_value)
86 return min_value + diff_min <= max_value
87 /*|| max_value - diff_min >= min_value*/;
92 template <typename Geometry,
95 struct longitude_range
97 template <typename Value1, typename Value2>
98 static inline bool apply(Value1 const& value, Value2 const& min_value, Value2 const& max_value)
100 typedef typename select_most_precise
104 typedef typename coordinate_system<Geometry>::type::units units_t;
105 typedef math::detail::constants_on_spheroid<calc_t, units_t> constants;
107 if (CoordCheck::apply(value, min_value, max_value))
112 // min <= max <=> diff >= 0
113 calc_t const diff_ing = max_value - min_value;
115 // if containing covers the whole globe it contains all
116 if (diff_ing >= constants::period())
121 // calculate positive longitude translation with min_value as origin
122 calc_t const diff_min = math::longitude_distance_unsigned<units_t, calc_t>(min_value, value);
124 return DiffCheck::template apply<calc_t>(diff_min, min_value, max_value);
129 // spherical_equatorial_tag, spherical_polar_tag and geographic_cat are casted to spherical_tag
130 template <typename Geometry>
131 struct within_range<Geometry, 0, spherical_tag>
132 : longitude_range<Geometry, within_coord, within_longitude_diff>
136 template <typename Geometry>
137 struct covered_by_range<Geometry, 0, spherical_tag>
138 : longitude_range<Geometry, covered_by_coord, covered_by_longitude_diff>
144 template <typename, std::size_t, typename> class SubStrategy,
147 std::size_t Dimension,
148 std::size_t DimensionCount
150 struct relate_point_box_loop
152 static inline bool apply(Point const& point, Box const& box)
154 typedef typename tag_cast<typename cs_tag<Point>::type, spherical_tag>::type cs_tag_t;
156 if (! SubStrategy<Point, Dimension, cs_tag_t>::apply(get<Dimension>(point),
157 get<min_corner, Dimension>(box),
158 get<max_corner, Dimension>(box))
164 return relate_point_box_loop
168 Dimension + 1, DimensionCount
169 >::apply(point, box);
176 template <typename, std::size_t, typename> class SubStrategy,
179 std::size_t DimensionCount
181 struct relate_point_box_loop<SubStrategy, Point, Box, DimensionCount, DimensionCount>
183 static inline bool apply(Point const& , Box const& )
194 template <typename, std::size_t, typename> class SubStrategy = within_range
198 static inline bool apply(Point const& point, Box const& box)
200 return relate_point_box_loop
204 0, dimension<Point>::type::value
205 >::apply(point, box);
210 } // namespace within
213 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
216 namespace within { namespace services
219 template <typename Point, typename Box>
220 struct default_strategy
224 pointlike_tag, areal_tag,
225 cartesian_tag, cartesian_tag
228 typedef within::point_in_box<Point, Box> type;
231 // spherical_equatorial_tag, spherical_polar_tag and geographic_cat are casted to spherical_tag
232 template <typename Point, typename Box>
233 struct default_strategy
237 pointlike_tag, areal_tag,
238 spherical_tag, spherical_tag
241 typedef within::point_in_box<Point, Box> type;
245 }} // namespace within::services
248 namespace covered_by { namespace services
252 template <typename Point, typename Box>
253 struct default_strategy
257 pointlike_tag, areal_tag,
258 cartesian_tag, cartesian_tag
261 typedef within::point_in_box
264 within::covered_by_range
268 // spherical_equatorial_tag, spherical_polar_tag and geographic_cat are casted to spherical_tag
269 template <typename Point, typename Box>
270 struct default_strategy
274 pointlike_tag, areal_tag,
275 spherical_tag, spherical_tag
278 typedef within::point_in_box
281 within::covered_by_range
286 }} // namespace covered_by::services
289 #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
292 }}} // namespace boost::geometry::strategy
295 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_POINT_IN_BOX_HPP