Chris@16
|
1 // Boost.Geometry (aka GGL, Generic Geometry Library)
|
Chris@16
|
2
|
Chris@16
|
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
|
Chris@16
|
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
|
Chris@16
|
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
|
Chris@16
|
6
|
Chris@16
|
7 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
|
Chris@16
|
8 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
|
Chris@16
|
9
|
Chris@16
|
10 // Use, modification and distribution is subject to the Boost Software License,
|
Chris@16
|
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
12 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
13
|
Chris@16
|
14 #ifndef BOOST_GEOMETRY_STRATEGIES_CARTESIAN_POINT_IN_BOX_HPP
|
Chris@16
|
15 #define BOOST_GEOMETRY_STRATEGIES_CARTESIAN_POINT_IN_BOX_HPP
|
Chris@16
|
16
|
Chris@16
|
17
|
Chris@16
|
18 #include <boost/geometry/core/access.hpp>
|
Chris@16
|
19 #include <boost/geometry/core/coordinate_dimension.hpp>
|
Chris@16
|
20 #include <boost/geometry/strategies/covered_by.hpp>
|
Chris@16
|
21 #include <boost/geometry/strategies/within.hpp>
|
Chris@16
|
22
|
Chris@16
|
23
|
Chris@101
|
24 namespace boost { namespace geometry { namespace strategy
|
Chris@16
|
25 {
|
Chris@101
|
26
|
Chris@16
|
27 namespace within
|
Chris@16
|
28 {
|
Chris@16
|
29
|
Chris@16
|
30
|
Chris@16
|
31 struct within_range
|
Chris@16
|
32 {
|
Chris@16
|
33 template <typename Value1, typename Value2>
|
Chris@16
|
34 static inline bool apply(Value1 const& value, Value2 const& min_value, Value2 const& max_value)
|
Chris@16
|
35 {
|
Chris@16
|
36 return value > min_value && value < max_value;
|
Chris@16
|
37 }
|
Chris@16
|
38 };
|
Chris@16
|
39
|
Chris@16
|
40
|
Chris@16
|
41 struct covered_by_range
|
Chris@16
|
42 {
|
Chris@16
|
43 template <typename Value1, typename Value2>
|
Chris@16
|
44 static inline bool apply(Value1 const& value, Value2 const& min_value, Value2 const& max_value)
|
Chris@16
|
45 {
|
Chris@16
|
46 return value >= min_value && value <= max_value;
|
Chris@16
|
47 }
|
Chris@16
|
48 };
|
Chris@16
|
49
|
Chris@16
|
50
|
Chris@16
|
51 template
|
Chris@16
|
52 <
|
Chris@16
|
53 typename SubStrategy,
|
Chris@16
|
54 typename Point,
|
Chris@16
|
55 typename Box,
|
Chris@16
|
56 std::size_t Dimension,
|
Chris@16
|
57 std::size_t DimensionCount
|
Chris@16
|
58 >
|
Chris@16
|
59 struct relate_point_box_loop
|
Chris@16
|
60 {
|
Chris@16
|
61 static inline bool apply(Point const& point, Box const& box)
|
Chris@16
|
62 {
|
Chris@101
|
63 if (! SubStrategy::apply(get<Dimension>(point),
|
Chris@101
|
64 get<min_corner, Dimension>(box),
|
Chris@16
|
65 get<max_corner, Dimension>(box))
|
Chris@16
|
66 )
|
Chris@16
|
67 {
|
Chris@16
|
68 return false;
|
Chris@16
|
69 }
|
Chris@101
|
70
|
Chris@16
|
71 return relate_point_box_loop
|
Chris@16
|
72 <
|
Chris@16
|
73 SubStrategy,
|
Chris@16
|
74 Point, Box,
|
Chris@16
|
75 Dimension + 1, DimensionCount
|
Chris@16
|
76 >::apply(point, box);
|
Chris@16
|
77 }
|
Chris@16
|
78 };
|
Chris@16
|
79
|
Chris@16
|
80
|
Chris@16
|
81 template
|
Chris@16
|
82 <
|
Chris@16
|
83 typename SubStrategy,
|
Chris@16
|
84 typename Point,
|
Chris@16
|
85 typename Box,
|
Chris@16
|
86 std::size_t DimensionCount
|
Chris@16
|
87 >
|
Chris@16
|
88 struct relate_point_box_loop<SubStrategy, Point, Box, DimensionCount, DimensionCount>
|
Chris@16
|
89 {
|
Chris@16
|
90 static inline bool apply(Point const& , Box const& )
|
Chris@16
|
91 {
|
Chris@16
|
92 return true;
|
Chris@16
|
93 }
|
Chris@16
|
94 };
|
Chris@16
|
95
|
Chris@16
|
96
|
Chris@16
|
97 template
|
Chris@16
|
98 <
|
Chris@16
|
99 typename Point,
|
Chris@16
|
100 typename Box,
|
Chris@16
|
101 typename SubStrategy = within_range
|
Chris@16
|
102 >
|
Chris@16
|
103 struct point_in_box
|
Chris@16
|
104 {
|
Chris@101
|
105 static inline bool apply(Point const& point, Box const& box)
|
Chris@16
|
106 {
|
Chris@16
|
107 return relate_point_box_loop
|
Chris@16
|
108 <
|
Chris@16
|
109 SubStrategy,
|
Chris@101
|
110 Point, Box,
|
Chris@16
|
111 0, dimension<Point>::type::value
|
Chris@16
|
112 >::apply(point, box);
|
Chris@16
|
113 }
|
Chris@16
|
114 };
|
Chris@16
|
115
|
Chris@16
|
116
|
Chris@16
|
117 } // namespace within
|
Chris@16
|
118
|
Chris@16
|
119
|
Chris@16
|
120 #ifndef DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
Chris@16
|
121
|
Chris@16
|
122
|
Chris@16
|
123 namespace within { namespace services
|
Chris@16
|
124 {
|
Chris@16
|
125
|
Chris@16
|
126 template <typename Point, typename Box>
|
Chris@16
|
127 struct default_strategy
|
Chris@16
|
128 <
|
Chris@101
|
129 point_tag, box_tag,
|
Chris@101
|
130 point_tag, areal_tag,
|
Chris@101
|
131 cartesian_tag, cartesian_tag,
|
Chris@16
|
132 Point, Box
|
Chris@16
|
133 >
|
Chris@16
|
134 {
|
Chris@101
|
135 typedef within::point_in_box<Point, Box> type;
|
Chris@16
|
136 };
|
Chris@16
|
137
|
Chris@16
|
138
|
Chris@16
|
139 }} // namespace within::services
|
Chris@16
|
140
|
Chris@16
|
141
|
Chris@16
|
142 namespace covered_by { namespace services
|
Chris@16
|
143 {
|
Chris@16
|
144
|
Chris@16
|
145
|
Chris@16
|
146 template <typename Point, typename Box>
|
Chris@16
|
147 struct default_strategy
|
Chris@16
|
148 <
|
Chris@101
|
149 point_tag, box_tag,
|
Chris@101
|
150 point_tag, areal_tag,
|
Chris@101
|
151 cartesian_tag, cartesian_tag,
|
Chris@16
|
152 Point, Box
|
Chris@16
|
153 >
|
Chris@16
|
154 {
|
Chris@16
|
155 typedef within::point_in_box
|
Chris@16
|
156 <
|
Chris@16
|
157 Point, Box,
|
Chris@16
|
158 within::covered_by_range
|
Chris@16
|
159 > type;
|
Chris@16
|
160 };
|
Chris@16
|
161
|
Chris@16
|
162
|
Chris@16
|
163 }} // namespace covered_by::services
|
Chris@16
|
164
|
Chris@16
|
165
|
Chris@16
|
166 #endif // DOXYGEN_NO_STRATEGY_SPECIALIZATIONS
|
Chris@16
|
167
|
Chris@16
|
168
|
Chris@16
|
169 }}} // namespace boost::geometry::strategy
|
Chris@16
|
170
|
Chris@16
|
171
|
Chris@16
|
172 #endif // BOOST_GEOMETRY_STRATEGIES_CARTESIAN_POINT_IN_BOX_HPP
|