Chris@16
|
1 /*
|
Chris@16
|
2 Copyright 2008 Intel Corporation
|
Chris@16
|
3
|
Chris@16
|
4 Use, modification and distribution are subject to the Boost Software License,
|
Chris@16
|
5 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
6 http://www.boost.org/LICENSE_1_0.txt).
|
Chris@16
|
7 */
|
Chris@16
|
8 #ifndef BOOST_POLYGON_RECTANGLE_CONCEPT_HPP
|
Chris@16
|
9 #define BOOST_POLYGON_RECTANGLE_CONCEPT_HPP
|
Chris@16
|
10
|
Chris@16
|
11 #include "isotropy.hpp"
|
Chris@16
|
12
|
Chris@16
|
13 //point
|
Chris@16
|
14 #include "point_data.hpp"
|
Chris@16
|
15 #include "point_traits.hpp"
|
Chris@16
|
16 #include "point_concept.hpp"
|
Chris@16
|
17
|
Chris@16
|
18 //interval
|
Chris@16
|
19 #include "interval_data.hpp"
|
Chris@16
|
20 #include "interval_traits.hpp"
|
Chris@16
|
21 #include "interval_concept.hpp"
|
Chris@16
|
22
|
Chris@16
|
23 #include "rectangle_data.hpp"
|
Chris@16
|
24 #include "rectangle_traits.hpp"
|
Chris@16
|
25
|
Chris@16
|
26 namespace boost { namespace polygon{
|
Chris@16
|
27 struct rectangle_concept {};
|
Chris@16
|
28
|
Chris@16
|
29 template <typename T>
|
Chris@16
|
30 struct is_rectangle_concept { typedef gtl_no type; };
|
Chris@16
|
31 template <>
|
Chris@16
|
32 struct is_rectangle_concept<rectangle_concept> { typedef gtl_yes type; };
|
Chris@16
|
33
|
Chris@16
|
34 template <typename T>
|
Chris@16
|
35 struct is_mutable_rectangle_concept { typedef gtl_no type; };
|
Chris@16
|
36 template <>
|
Chris@16
|
37 struct is_mutable_rectangle_concept<rectangle_concept> { typedef gtl_yes type; };
|
Chris@16
|
38
|
Chris@16
|
39 template <>
|
Chris@16
|
40 struct geometry_domain<rectangle_concept> { typedef manhattan_domain type; };
|
Chris@16
|
41
|
Chris@16
|
42 template <typename T, typename CT>
|
Chris@16
|
43 struct rectangle_interval_type_by_concept { typedef void type; };
|
Chris@16
|
44 template <typename T>
|
Chris@16
|
45 struct rectangle_interval_type_by_concept<T, gtl_yes> { typedef typename rectangle_traits<T>::interval_type type; };
|
Chris@16
|
46
|
Chris@16
|
47 template <typename T>
|
Chris@16
|
48 struct rectangle_interval_type {
|
Chris@16
|
49 typedef typename rectangle_interval_type_by_concept<T, typename is_rectangle_concept<typename geometry_concept<T>::type>::type>::type type;
|
Chris@16
|
50 };
|
Chris@16
|
51
|
Chris@16
|
52 template <typename T, typename CT>
|
Chris@16
|
53 struct rectangle_coordinate_type_by_concept { typedef void type; };
|
Chris@16
|
54 template <typename T>
|
Chris@16
|
55 struct rectangle_coordinate_type_by_concept<T, gtl_yes> { typedef typename rectangle_traits<T>::coordinate_type type; };
|
Chris@16
|
56
|
Chris@16
|
57 template <typename T>
|
Chris@16
|
58 struct rectangle_coordinate_type {
|
Chris@16
|
59 typedef typename rectangle_coordinate_type_by_concept<T, typename is_rectangle_concept<typename geometry_concept<T>::type>::type>::type type;
|
Chris@16
|
60 };
|
Chris@16
|
61
|
Chris@16
|
62 template <typename T, typename CT>
|
Chris@16
|
63 struct rectangle_difference_type_by_concept { typedef void type; };
|
Chris@16
|
64 template <typename T>
|
Chris@16
|
65 struct rectangle_difference_type_by_concept<T, gtl_yes> {
|
Chris@16
|
66 typedef typename coordinate_traits<typename rectangle_traits<T>::coordinate_type>::coordinate_difference type; };
|
Chris@16
|
67
|
Chris@16
|
68 template <typename T>
|
Chris@16
|
69 struct rectangle_difference_type {
|
Chris@16
|
70 typedef typename rectangle_difference_type_by_concept<
|
Chris@16
|
71 T, typename is_rectangle_concept<typename geometry_concept<T>::type>::type>::type type;
|
Chris@16
|
72 };
|
Chris@16
|
73
|
Chris@16
|
74 template <typename T, typename CT>
|
Chris@16
|
75 struct rectangle_distance_type_by_concept { typedef void type; };
|
Chris@16
|
76 template <typename T>
|
Chris@16
|
77 struct rectangle_distance_type_by_concept<T, gtl_yes> {
|
Chris@16
|
78 typedef typename coordinate_traits<typename rectangle_coordinate_type<T>::type>::coordinate_distance type; };
|
Chris@16
|
79
|
Chris@16
|
80 template <typename T>
|
Chris@16
|
81 struct rectangle_distance_type {
|
Chris@16
|
82 typedef typename rectangle_distance_type_by_concept<
|
Chris@16
|
83 T, typename is_rectangle_concept<typename geometry_concept<T>::type>::type>::type type;
|
Chris@16
|
84 };
|
Chris@16
|
85
|
Chris@16
|
86 struct y_r_get_interval : gtl_yes {};
|
Chris@16
|
87
|
Chris@16
|
88 template <typename T>
|
Chris@16
|
89 typename enable_if< typename gtl_and<y_r_get_interval, typename is_rectangle_concept<typename geometry_concept<T>::type>::type>::type,
|
Chris@16
|
90 typename rectangle_interval_type<T>::type>::type
|
Chris@16
|
91 get(const T& rectangle, orientation_2d orient) {
|
Chris@16
|
92 return rectangle_traits<T>::get(rectangle, orient);
|
Chris@16
|
93 }
|
Chris@16
|
94
|
Chris@16
|
95 struct y_r_h : gtl_yes {};
|
Chris@16
|
96
|
Chris@16
|
97 template <typename T>
|
Chris@16
|
98 typename enable_if< typename gtl_and<y_r_h, typename is_rectangle_concept<typename geometry_concept<T>::type>::type>::type,
|
Chris@16
|
99 typename rectangle_interval_type<T>::type>::type
|
Chris@16
|
100 horizontal(const T& rectangle) {
|
Chris@16
|
101 return rectangle_traits<T>::get(rectangle, HORIZONTAL);
|
Chris@16
|
102 }
|
Chris@16
|
103
|
Chris@16
|
104 struct y_r_v : gtl_yes {};
|
Chris@16
|
105
|
Chris@16
|
106 template <typename T>
|
Chris@16
|
107 typename enable_if< typename gtl_and<y_r_v, typename is_rectangle_concept<typename geometry_concept<T>::type>::type>::type,
|
Chris@16
|
108 typename rectangle_interval_type<T>::type>::type
|
Chris@16
|
109 vertical(const T& rectangle) {
|
Chris@16
|
110 return rectangle_traits<T>::get(rectangle, VERTICAL);
|
Chris@16
|
111 }
|
Chris@16
|
112
|
Chris@16
|
113 struct y_r_set : gtl_yes {};
|
Chris@16
|
114
|
Chris@16
|
115 template <orientation_2d_enum orient, typename T, typename T2>
|
Chris@16
|
116 typename enable_if< typename gtl_and_3<y_r_set, typename is_mutable_rectangle_concept<typename geometry_concept<T>::type>::type,
|
Chris@16
|
117 typename is_interval_concept<typename geometry_concept<T2>::type>::type>::type,
|
Chris@16
|
118 void>::type
|
Chris@16
|
119 set(T& rectangle, const T2& interval) {
|
Chris@16
|
120 rectangle_mutable_traits<T>::set(rectangle, orient, interval);
|
Chris@16
|
121 }
|
Chris@16
|
122
|
Chris@16
|
123 struct y_r_set2 : gtl_yes {};
|
Chris@16
|
124
|
Chris@16
|
125 template <typename T, typename T2>
|
Chris@16
|
126 typename enable_if< typename gtl_and_3<y_r_set2, typename is_mutable_rectangle_concept<typename geometry_concept<T>::type>::type,
|
Chris@16
|
127 typename is_interval_concept<typename geometry_concept<T2>::type>::type>::type,
|
Chris@16
|
128 void>::type
|
Chris@16
|
129 set(T& rectangle, orientation_2d orient, const T2& interval) {
|
Chris@16
|
130 rectangle_mutable_traits<T>::set(rectangle, orient, interval);
|
Chris@16
|
131 }
|
Chris@16
|
132
|
Chris@16
|
133 struct y_r_h2 : gtl_yes {};
|
Chris@16
|
134
|
Chris@16
|
135 template <typename T, typename T2>
|
Chris@16
|
136 typename enable_if< typename gtl_and_3<y_r_h2, typename is_mutable_rectangle_concept<typename geometry_concept<T>::type>::type,
|
Chris@16
|
137 typename is_interval_concept<typename geometry_concept<T2>::type>::type>::type,
|
Chris@16
|
138 void>::type
|
Chris@16
|
139 horizontal(T& rectangle, const T2& interval) {
|
Chris@16
|
140 rectangle_mutable_traits<T>::set(rectangle, HORIZONTAL, interval);
|
Chris@16
|
141 }
|
Chris@16
|
142
|
Chris@16
|
143 struct y_r_v2 : gtl_yes {};
|
Chris@16
|
144
|
Chris@16
|
145 template <typename T, typename T2>
|
Chris@16
|
146 typename enable_if<
|
Chris@16
|
147 typename gtl_and_3<y_r_v2, typename is_mutable_rectangle_concept<typename geometry_concept<T>::type>::type,
|
Chris@16
|
148 typename is_interval_concept<typename geometry_concept<T2>::type>::type>::type, void>::type
|
Chris@16
|
149 vertical(T& rectangle, const T2& interval) {
|
Chris@16
|
150 rectangle_mutable_traits<T>::set(rectangle, VERTICAL, interval);
|
Chris@16
|
151 }
|
Chris@16
|
152
|
Chris@16
|
153 struct y_r_construct : gtl_yes {};
|
Chris@16
|
154
|
Chris@16
|
155 template <typename T, typename T2, typename T3>
|
Chris@16
|
156 typename enable_if< typename gtl_and<y_r_construct, typename is_mutable_rectangle_concept<typename geometry_concept<T>::type>::type>::type,
|
Chris@16
|
157 T>::type
|
Chris@16
|
158 construct(const T2& interval_horizontal,
|
Chris@16
|
159 const T3& interval_vertical) {
|
Chris@16
|
160 return rectangle_mutable_traits<T>::construct(interval_horizontal, interval_vertical); }
|
Chris@16
|
161
|
Chris@16
|
162 struct y_r_construct2 : gtl_yes {};
|
Chris@16
|
163
|
Chris@16
|
164 template <typename T, typename coord_type>
|
Chris@16
|
165 typename enable_if< typename gtl_and<y_r_construct2, typename is_mutable_rectangle_concept<typename geometry_concept<T>::type>::type>::type,
|
Chris@16
|
166 T>::type
|
Chris@16
|
167 construct(coord_type xl, coord_type yl, coord_type xh, coord_type yh) {
|
Chris@16
|
168 return rectangle_mutable_traits<T>::construct(interval_data<coord_type>(xl, xh),
|
Chris@16
|
169 interval_data<coord_type>(yl, yh));
|
Chris@16
|
170 }
|
Chris@16
|
171
|
Chris@16
|
172 struct y_r_cconstruct : gtl_yes {};
|
Chris@16
|
173
|
Chris@16
|
174 template <typename T, typename T2>
|
Chris@16
|
175 typename enable_if<
|
Chris@16
|
176 typename gtl_and_3<y_r_cconstruct,
|
Chris@16
|
177 typename is_mutable_rectangle_concept<typename geometry_concept<T>::type>::type,
|
Chris@16
|
178 typename is_rectangle_concept<typename geometry_concept<T2>::type>::type>::type,
|
Chris@16
|
179 T>::type
|
Chris@16
|
180 copy_construct(const T2& rectangle) {
|
Chris@16
|
181 return construct<T> (get(rectangle, HORIZONTAL), get(rectangle, VERTICAL));
|
Chris@16
|
182 }
|
Chris@16
|
183
|
Chris@16
|
184 struct y_r_assign : gtl_yes {};
|
Chris@16
|
185
|
Chris@16
|
186 template <typename rectangle_type_1, typename rectangle_type_2>
|
Chris@16
|
187 typename enable_if<
|
Chris@16
|
188 typename gtl_and_3< y_r_assign,
|
Chris@16
|
189 typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type_1>::type>::type,
|
Chris@16
|
190 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
191 rectangle_type_1>::type &
|
Chris@16
|
192 assign(rectangle_type_1& lvalue, const rectangle_type_2& rvalue) {
|
Chris@16
|
193 set(lvalue, HORIZONTAL, get(rvalue, HORIZONTAL));
|
Chris@16
|
194 set(lvalue, VERTICAL, get(rvalue, VERTICAL));
|
Chris@16
|
195 return lvalue;
|
Chris@16
|
196 }
|
Chris@16
|
197
|
Chris@16
|
198 struct y_r_equiv : gtl_yes {};
|
Chris@16
|
199
|
Chris@16
|
200 template <typename T, typename T2>
|
Chris@16
|
201 typename enable_if<
|
Chris@16
|
202 typename gtl_and_3< y_r_equiv,
|
Chris@16
|
203 typename is_rectangle_concept<typename geometry_concept<T>::type>::type,
|
Chris@16
|
204 typename is_rectangle_concept<typename geometry_concept<T2>::type>::type>::type,
|
Chris@16
|
205 bool>::type
|
Chris@16
|
206 equivalence(const T& rect1, const T2& rect2) {
|
Chris@16
|
207 return equivalence(get(rect1, HORIZONTAL), get(rect2, HORIZONTAL)) &&
|
Chris@16
|
208 equivalence(get(rect1, VERTICAL), get(rect2, VERTICAL));
|
Chris@16
|
209 }
|
Chris@16
|
210
|
Chris@16
|
211 struct y_r_get : gtl_yes {};
|
Chris@16
|
212
|
Chris@16
|
213 template <typename rectangle_type>
|
Chris@16
|
214 typename enable_if< typename gtl_and<y_r_get, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
215 typename rectangle_coordinate_type<rectangle_type>::type>::type
|
Chris@16
|
216 get(const rectangle_type& rectangle, orientation_2d orient, direction_1d dir) {
|
Chris@16
|
217 return get(rectangle_traits<rectangle_type>::get(rectangle, orient), dir);
|
Chris@16
|
218 }
|
Chris@16
|
219
|
Chris@16
|
220 struct y_r_set3 : gtl_yes {};
|
Chris@16
|
221
|
Chris@16
|
222 template <typename rectangle_type>
|
Chris@16
|
223 typename enable_if<typename gtl_and<y_r_set3, typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type, void>::type
|
Chris@16
|
224 set(rectangle_type& rectangle, orientation_2d orient, direction_1d dir,
|
Chris@16
|
225 typename rectangle_coordinate_type<rectangle_type>::type value) {
|
Chris@16
|
226 typename rectangle_interval_type<rectangle_type>::type ivl = get(rectangle, orient);
|
Chris@16
|
227 set(ivl, dir, value);
|
Chris@16
|
228 set(rectangle, orient, ivl);
|
Chris@16
|
229 }
|
Chris@16
|
230
|
Chris@16
|
231 struct y_r_xl : gtl_yes {};
|
Chris@16
|
232
|
Chris@16
|
233 template <typename rectangle_type>
|
Chris@16
|
234 typename enable_if< typename gtl_and<y_r_xl, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
235 typename rectangle_coordinate_type<rectangle_type>::type>::type
|
Chris@16
|
236 xl(const rectangle_type& rectangle) {
|
Chris@16
|
237 return get(rectangle, HORIZONTAL, LOW);
|
Chris@16
|
238 }
|
Chris@16
|
239
|
Chris@16
|
240 struct y_r_xl2 : gtl_yes {};
|
Chris@16
|
241
|
Chris@16
|
242 template <typename rectangle_type>
|
Chris@16
|
243 typename enable_if<typename gtl_and<y_r_xl2, typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type, void>::type
|
Chris@16
|
244 xl(rectangle_type& rectangle, typename rectangle_coordinate_type<rectangle_type>::type value) {
|
Chris@16
|
245 return set(rectangle, HORIZONTAL, LOW, value);
|
Chris@16
|
246 }
|
Chris@16
|
247
|
Chris@16
|
248 struct y_r_xh : gtl_yes {};
|
Chris@16
|
249
|
Chris@16
|
250 template <typename rectangle_type>
|
Chris@16
|
251 typename enable_if< typename gtl_and<y_r_xh, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
252 typename rectangle_coordinate_type<rectangle_type>::type>::type
|
Chris@16
|
253 xh(const rectangle_type& rectangle) {
|
Chris@16
|
254 return get(rectangle, HORIZONTAL, HIGH);
|
Chris@16
|
255 }
|
Chris@16
|
256
|
Chris@16
|
257 struct y_r_xh2 : gtl_yes {};
|
Chris@16
|
258
|
Chris@16
|
259 template <typename rectangle_type>
|
Chris@16
|
260 typename enable_if<typename gtl_and<y_r_xh2, typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type, void>::type
|
Chris@16
|
261 xh(rectangle_type& rectangle, typename rectangle_coordinate_type<rectangle_type>::type value) {
|
Chris@16
|
262 return set(rectangle, HORIZONTAL, HIGH, value);
|
Chris@16
|
263 }
|
Chris@16
|
264
|
Chris@16
|
265 struct y_r_yl : gtl_yes {};
|
Chris@16
|
266
|
Chris@16
|
267 template <typename rectangle_type>
|
Chris@16
|
268 typename enable_if< typename gtl_and<y_r_yl, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
269 typename rectangle_coordinate_type<rectangle_type>::type>::type
|
Chris@16
|
270 yl(const rectangle_type& rectangle) {
|
Chris@16
|
271 return get(rectangle, VERTICAL, LOW);
|
Chris@16
|
272 }
|
Chris@16
|
273
|
Chris@16
|
274 struct y_r_yl2 : gtl_yes {};
|
Chris@16
|
275
|
Chris@16
|
276 template <typename rectangle_type>
|
Chris@16
|
277 typename enable_if<typename gtl_and<y_r_yl2, typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type, void>::type
|
Chris@16
|
278 yl(rectangle_type& rectangle, typename rectangle_coordinate_type<rectangle_type>::type value) {
|
Chris@16
|
279 return set(rectangle, VERTICAL, LOW, value);
|
Chris@16
|
280 }
|
Chris@16
|
281
|
Chris@16
|
282 struct y_r_yh : gtl_yes {};
|
Chris@16
|
283
|
Chris@16
|
284 template <typename rectangle_type>
|
Chris@16
|
285 typename enable_if< typename gtl_and<y_r_yh, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
286 typename rectangle_coordinate_type<rectangle_type>::type>::type
|
Chris@16
|
287 yh(const rectangle_type& rectangle) {
|
Chris@16
|
288 return get(rectangle, VERTICAL, HIGH);
|
Chris@16
|
289 }
|
Chris@16
|
290
|
Chris@16
|
291 struct y_r_yh2 : gtl_yes {};
|
Chris@16
|
292
|
Chris@16
|
293 template <typename rectangle_type>
|
Chris@16
|
294 typename enable_if<typename gtl_and<y_r_yh2, typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type, void>::type
|
Chris@16
|
295 yh(rectangle_type& rectangle, typename rectangle_coordinate_type<rectangle_type>::type value) {
|
Chris@16
|
296 return set(rectangle, VERTICAL, HIGH, value);
|
Chris@16
|
297 }
|
Chris@16
|
298
|
Chris@16
|
299 struct y_r_ll : gtl_yes {};
|
Chris@16
|
300
|
Chris@16
|
301 template <typename rectangle_type>
|
Chris@16
|
302 typename enable_if<typename gtl_and<y_r_ll, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
303 point_data<typename rectangle_coordinate_type<rectangle_type>::type> >::type
|
Chris@16
|
304 ll(const rectangle_type& rectangle) {
|
Chris@16
|
305 return point_data<typename rectangle_coordinate_type<rectangle_type>::type> (xl(rectangle), yl(rectangle));
|
Chris@16
|
306 }
|
Chris@16
|
307
|
Chris@16
|
308 struct y_r_lr : gtl_yes {};
|
Chris@16
|
309
|
Chris@16
|
310 template <typename rectangle_type>
|
Chris@16
|
311 typename enable_if<typename gtl_and<y_r_lr, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
312 point_data<typename rectangle_coordinate_type<rectangle_type>::type> >::type
|
Chris@16
|
313 lr(const rectangle_type& rectangle) {
|
Chris@16
|
314 return point_data<typename rectangle_coordinate_type<rectangle_type>::type> (xh(rectangle), yl(rectangle));
|
Chris@16
|
315 }
|
Chris@16
|
316
|
Chris@16
|
317 struct y_r_ul : gtl_yes {};
|
Chris@16
|
318
|
Chris@16
|
319 template <typename rectangle_type>
|
Chris@16
|
320 typename enable_if<typename gtl_and<y_r_ul, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
321 point_data<typename rectangle_coordinate_type<rectangle_type>::type> >::type
|
Chris@16
|
322 ul(const rectangle_type& rectangle) {
|
Chris@16
|
323 return point_data<typename rectangle_coordinate_type<rectangle_type>::type> (xl(rectangle), yh(rectangle));
|
Chris@16
|
324 }
|
Chris@16
|
325
|
Chris@16
|
326 struct y_r_ur : gtl_yes {};
|
Chris@16
|
327
|
Chris@16
|
328 template <typename rectangle_type>
|
Chris@16
|
329 typename enable_if<typename gtl_and<y_r_ur, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
330 point_data<typename rectangle_coordinate_type<rectangle_type>::type> >::type
|
Chris@16
|
331 ur(const rectangle_type& rectangle) {
|
Chris@16
|
332 return point_data<typename rectangle_coordinate_type<rectangle_type>::type> (xh(rectangle), yh(rectangle));
|
Chris@16
|
333 }
|
Chris@16
|
334
|
Chris@16
|
335 struct y_r_contains : gtl_yes {};
|
Chris@16
|
336
|
Chris@16
|
337 template <typename rectangle_type, typename rectangle_type_2>
|
Chris@16
|
338 typename enable_if< typename gtl_and_3<y_r_contains, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type,
|
Chris@16
|
339 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
340 bool>::type
|
Chris@16
|
341 contains(const rectangle_type& rectangle, const rectangle_type_2 rectangle_contained,
|
Chris@16
|
342 bool consider_touch = true) {
|
Chris@16
|
343 return contains(horizontal(rectangle), horizontal(rectangle_contained), consider_touch) &&
|
Chris@16
|
344 contains(vertical(rectangle), vertical(rectangle_contained), consider_touch);
|
Chris@16
|
345 }
|
Chris@16
|
346
|
Chris@16
|
347 struct y_r_contains2 : gtl_yes {};
|
Chris@16
|
348
|
Chris@16
|
349 template <typename rectangle_type, typename point_type>
|
Chris@16
|
350 typename enable_if< typename gtl_and_3<y_r_contains2, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type,
|
Chris@16
|
351 typename is_point_concept<typename geometry_concept<point_type>::type>::type>::type, bool>::type
|
Chris@16
|
352 contains(const rectangle_type& rectangle, const point_type point_contained,
|
Chris@16
|
353 bool consider_touch = true) {
|
Chris@16
|
354 return contains(horizontal(rectangle), x(point_contained), consider_touch) &&
|
Chris@16
|
355 contains(vertical(rectangle), y(point_contained), consider_touch);
|
Chris@16
|
356 }
|
Chris@16
|
357
|
Chris@16
|
358 struct y_r_set_points : gtl_yes {};
|
Chris@16
|
359
|
Chris@16
|
360 // set all four coordinates based upon two points
|
Chris@16
|
361 template <typename rectangle_type, typename point_type_1, typename point_type_2>
|
Chris@16
|
362 typename enable_if< typename gtl_and_4< y_r_set_points,
|
Chris@16
|
363 typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type,
|
Chris@16
|
364 typename is_point_concept<typename geometry_concept<point_type_1>::type>::type,
|
Chris@16
|
365 typename is_point_concept<typename geometry_concept<point_type_2>::type>::type>::type,
|
Chris@16
|
366 rectangle_type>::type &
|
Chris@16
|
367 set_points(rectangle_type& rectangle, const point_type_1& p1,
|
Chris@16
|
368 const point_type_2& p2) {
|
Chris@16
|
369 typedef typename rectangle_coordinate_type<rectangle_type>::type Unit;
|
Chris@16
|
370 Unit x1(x(p1));
|
Chris@16
|
371 Unit x2(x(p2));
|
Chris@16
|
372 Unit y1(y(p1));
|
Chris@16
|
373 Unit y2(y(p2));
|
Chris@16
|
374 horizontal(rectangle, construct<typename rectangle_interval_type<rectangle_type>::type>(x1, x2));
|
Chris@16
|
375 vertical(rectangle, construct<typename rectangle_interval_type<rectangle_type>::type>(y1, y2));
|
Chris@16
|
376 return rectangle;
|
Chris@16
|
377 }
|
Chris@16
|
378
|
Chris@16
|
379 struct y_r_move : gtl_yes {};
|
Chris@16
|
380
|
Chris@16
|
381 // move rectangle by delta in orient
|
Chris@16
|
382 template <typename rectangle_type>
|
Chris@16
|
383 typename enable_if< typename gtl_and<y_r_move, typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
384 rectangle_type>::type &
|
Chris@16
|
385 move(rectangle_type& rectangle, orientation_2d orient,
|
Chris@16
|
386 typename coordinate_traits<typename rectangle_coordinate_type<rectangle_type>::type>::coordinate_difference delta) {
|
Chris@16
|
387 typename rectangle_interval_type<rectangle_type>::type ivl = get(rectangle, orient);
|
Chris@16
|
388 move(ivl, delta);
|
Chris@16
|
389 set(rectangle, orient, ivl);
|
Chris@16
|
390 return rectangle;
|
Chris@16
|
391 }
|
Chris@16
|
392
|
Chris@16
|
393 struct y_r_convolve : gtl_yes {};
|
Chris@16
|
394
|
Chris@16
|
395 // convolve this with b
|
Chris@16
|
396 template <typename rectangle_type_1, typename rectangle_type_2>
|
Chris@16
|
397 typename enable_if<
|
Chris@16
|
398 typename gtl_and_3< y_r_convolve,
|
Chris@16
|
399 typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type_1>::type>::type,
|
Chris@16
|
400 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
401 rectangle_type_1>::type &
|
Chris@16
|
402 convolve(rectangle_type_1& rectangle,
|
Chris@16
|
403 const rectangle_type_2& convolution_rectangle) {
|
Chris@16
|
404 typename rectangle_interval_type<rectangle_type_1>::type ivl = horizontal(rectangle);
|
Chris@16
|
405 horizontal(rectangle, convolve(ivl, horizontal(convolution_rectangle)));
|
Chris@16
|
406 ivl = vertical(rectangle);
|
Chris@16
|
407 vertical(rectangle, convolve(ivl, vertical(convolution_rectangle)));
|
Chris@16
|
408 return rectangle;
|
Chris@16
|
409 }
|
Chris@16
|
410
|
Chris@16
|
411 struct y_r_deconvolve : gtl_yes {};
|
Chris@16
|
412
|
Chris@16
|
413 // deconvolve this with b
|
Chris@16
|
414 template <typename rectangle_type_1, typename rectangle_type_2>
|
Chris@16
|
415 typename enable_if< typename gtl_and_3< y_r_deconvolve,
|
Chris@16
|
416 typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type_1>::type>::type,
|
Chris@16
|
417 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
418 rectangle_type_1>::type &
|
Chris@16
|
419 deconvolve(rectangle_type_1& rectangle, const rectangle_type_2& convolution_rectangle) {
|
Chris@16
|
420 typename rectangle_interval_type<rectangle_type_1>::type ivl = horizontal(rectangle);
|
Chris@16
|
421 horizontal(rectangle, deconvolve(ivl, horizontal(convolution_rectangle)));
|
Chris@16
|
422 ivl = vertical(rectangle);
|
Chris@16
|
423 vertical(rectangle, deconvolve(ivl, vertical(convolution_rectangle)));
|
Chris@16
|
424 return rectangle;
|
Chris@16
|
425 }
|
Chris@16
|
426
|
Chris@16
|
427 struct y_r_reconvolve : gtl_yes {};
|
Chris@16
|
428
|
Chris@16
|
429 // reflectedConvolve this with b
|
Chris@16
|
430 template <typename rectangle_type_1, typename rectangle_type_2>
|
Chris@16
|
431 typename enable_if<
|
Chris@16
|
432 typename gtl_and_3<y_r_reconvolve, typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type_1>::type>::type,
|
Chris@16
|
433 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
434 rectangle_type_1>::type &
|
Chris@16
|
435 reflected_convolve(rectangle_type_1& rectangle, const rectangle_type_2& convolution_rectangle) {
|
Chris@16
|
436 typename rectangle_interval_type<rectangle_type_1>::type ivl = horizontal(rectangle);
|
Chris@16
|
437 horizontal(rectangle, reflected_convolve(ivl, horizontal(convolution_rectangle)));
|
Chris@16
|
438 ivl = vertical(rectangle);
|
Chris@16
|
439 vertical(rectangle, reflected_convolve(ivl, vertical(convolution_rectangle)));
|
Chris@16
|
440 return rectangle;
|
Chris@16
|
441 }
|
Chris@16
|
442
|
Chris@16
|
443 struct y_r_redeconvolve : gtl_yes {};
|
Chris@16
|
444
|
Chris@16
|
445 // reflectedDeconvolve this with b
|
Chris@16
|
446 // deconvolve this with b
|
Chris@16
|
447 template <typename rectangle_type_1, typename rectangle_type_2>
|
Chris@16
|
448 typename enable_if<
|
Chris@16
|
449 typename gtl_and_3<y_r_redeconvolve, typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type_1>::type>::type,
|
Chris@16
|
450 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
451 rectangle_type_1>::type &
|
Chris@16
|
452 reflected_deconvolve(rectangle_type_1& rectangle, const rectangle_type_2& convolution_rectangle) {
|
Chris@16
|
453 typename rectangle_interval_type<rectangle_type_1>::type ivl = horizontal(rectangle);
|
Chris@16
|
454 horizontal(rectangle, reflected_deconvolve(ivl, horizontal(convolution_rectangle)));
|
Chris@16
|
455 ivl = vertical(rectangle);
|
Chris@16
|
456 vertical(rectangle, reflected_deconvolve(ivl, vertical(convolution_rectangle)));
|
Chris@16
|
457 return rectangle;
|
Chris@16
|
458 }
|
Chris@16
|
459
|
Chris@16
|
460 struct y_r_convolve2 : gtl_yes {};
|
Chris@16
|
461
|
Chris@16
|
462 // convolve with point
|
Chris@16
|
463 template <typename rectangle_type, typename point_type>
|
Chris@16
|
464 typename enable_if< typename gtl_and_3<y_r_convolve2, typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type,
|
Chris@16
|
465 typename is_point_concept<typename geometry_concept<point_type>::type>::type>::type,
|
Chris@16
|
466 rectangle_type>::type &
|
Chris@16
|
467 convolve(rectangle_type& rectangle, const point_type& convolution_point) {
|
Chris@16
|
468 typename rectangle_interval_type<rectangle_type>::type ivl = horizontal(rectangle);
|
Chris@16
|
469 horizontal(rectangle, convolve(ivl, x(convolution_point)));
|
Chris@16
|
470 ivl = vertical(rectangle);
|
Chris@16
|
471 vertical(rectangle, convolve(ivl, y(convolution_point)));
|
Chris@16
|
472 return rectangle;
|
Chris@16
|
473 }
|
Chris@16
|
474
|
Chris@16
|
475 struct y_r_deconvolve2 : gtl_yes {};
|
Chris@16
|
476
|
Chris@16
|
477 // deconvolve with point
|
Chris@16
|
478 template <typename rectangle_type, typename point_type>
|
Chris@16
|
479 typename enable_if<
|
Chris@16
|
480 typename gtl_and_3<y_r_deconvolve2, typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type,
|
Chris@16
|
481 typename is_point_concept<typename geometry_concept<point_type>::type>::type>::type, rectangle_type>::type &
|
Chris@16
|
482 deconvolve(rectangle_type& rectangle, const point_type& convolution_point) {
|
Chris@16
|
483 typename rectangle_interval_type<rectangle_type>::type ivl = horizontal(rectangle);
|
Chris@16
|
484 horizontal(rectangle, deconvolve(ivl, x(convolution_point)));
|
Chris@16
|
485 ivl = vertical(rectangle);
|
Chris@16
|
486 vertical(rectangle, deconvolve(ivl, y(convolution_point)));
|
Chris@16
|
487 return rectangle;
|
Chris@16
|
488 }
|
Chris@16
|
489
|
Chris@16
|
490 struct y_r_delta : gtl_yes {};
|
Chris@16
|
491
|
Chris@16
|
492 // get the magnitude of the interval range depending on orient
|
Chris@16
|
493 template <typename rectangle_type>
|
Chris@16
|
494 typename enable_if< typename gtl_and<y_r_delta, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
495 typename rectangle_difference_type<rectangle_type>::type>::type
|
Chris@16
|
496 delta(const rectangle_type& rectangle, orientation_2d orient) {
|
Chris@16
|
497 return delta(get(rectangle, orient));
|
Chris@16
|
498 }
|
Chris@16
|
499
|
Chris@16
|
500 struct y_r_area : gtl_yes {};
|
Chris@16
|
501
|
Chris@16
|
502 // get the area of the rectangle
|
Chris@16
|
503 template <typename rectangle_type>
|
Chris@16
|
504 typename enable_if< typename gtl_and<y_r_area, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
505 typename coordinate_traits<typename rectangle_coordinate_type<rectangle_type>::type>::manhattan_area_type>::type
|
Chris@16
|
506 area(const rectangle_type& rectangle) {
|
Chris@16
|
507 typedef typename coordinate_traits<typename rectangle_coordinate_type<rectangle_type>::type>::manhattan_area_type area_type;
|
Chris@16
|
508 return (area_type)delta(rectangle, HORIZONTAL) * (area_type)delta(rectangle, VERTICAL);
|
Chris@16
|
509 }
|
Chris@16
|
510
|
Chris@16
|
511 struct y_r_go : gtl_yes {};
|
Chris@16
|
512
|
Chris@16
|
513 // returns the orientation of the longest side
|
Chris@16
|
514 template <typename rectangle_type>
|
Chris@16
|
515 typename enable_if<typename gtl_and<y_r_go, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
516 orientation_2d>::type
|
Chris@16
|
517 guess_orientation(const rectangle_type& rectangle) {
|
Chris@16
|
518 return delta(rectangle, HORIZONTAL) >= delta(rectangle, VERTICAL) ?
|
Chris@16
|
519 HORIZONTAL : VERTICAL;
|
Chris@16
|
520 }
|
Chris@16
|
521
|
Chris@16
|
522 struct y_r_half_p : gtl_yes {};
|
Chris@16
|
523
|
Chris@16
|
524 // get the half perimeter of the rectangle
|
Chris@16
|
525 template <typename rectangle_type>
|
Chris@16
|
526 typename enable_if< typename gtl_and<y_r_half_p, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
527 typename rectangle_difference_type<rectangle_type>::type>::type
|
Chris@16
|
528 half_perimeter(const rectangle_type& rectangle) {
|
Chris@16
|
529 return delta(rectangle, HORIZONTAL) + delta(rectangle, VERTICAL);
|
Chris@16
|
530 }
|
Chris@16
|
531
|
Chris@16
|
532 struct y_r_perimeter : gtl_yes {};
|
Chris@16
|
533
|
Chris@16
|
534 // get the perimeter of the rectangle
|
Chris@16
|
535 template <typename rectangle_type>
|
Chris@16
|
536 typename enable_if< typename gtl_and<y_r_perimeter, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
537 typename rectangle_difference_type<rectangle_type>::type>::type
|
Chris@16
|
538 perimeter(const rectangle_type& rectangle) {
|
Chris@16
|
539 return 2 * half_perimeter(rectangle);
|
Chris@16
|
540 }
|
Chris@16
|
541
|
Chris@16
|
542 struct y_r_intersects : gtl_yes {};
|
Chris@16
|
543
|
Chris@16
|
544 // check if Rectangle b intersects `this` Rectangle
|
Chris@16
|
545 // [in] b Rectangle that will be checked
|
Chris@16
|
546 // [in] considerTouch If true, return true even if b touches the boundary
|
Chris@16
|
547 // [ret] . true if `t` intersects b
|
Chris@16
|
548 template <typename rectangle_type_1, typename rectangle_type_2>
|
Chris@16
|
549 typename enable_if<
|
Chris@16
|
550 typename gtl_and_3<y_r_intersects, typename is_rectangle_concept<typename geometry_concept<rectangle_type_1>::type>::type,
|
Chris@16
|
551 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
552 bool>::type
|
Chris@16
|
553 intersects(const rectangle_type_1& rectangle, const rectangle_type_2& b, bool consider_touch = true) {
|
Chris@16
|
554 return intersects(horizontal(rectangle), horizontal(b), consider_touch) &&
|
Chris@16
|
555 intersects(vertical(rectangle), vertical(b), consider_touch);
|
Chris@16
|
556 }
|
Chris@16
|
557
|
Chris@16
|
558 struct y_r_b_intersect : gtl_yes {};
|
Chris@16
|
559
|
Chris@16
|
560 // Check if boundaries of Rectangle b and `this` Rectangle intersect
|
Chris@16
|
561 // [in] b Rectangle that will be checked
|
Chris@16
|
562 // [in] considerTouch If true, return true even if p is on the foundary
|
Chris@16
|
563 // [ret] . true if `t` contains p
|
Chris@16
|
564 template <typename rectangle_type_1, typename rectangle_type_2>
|
Chris@16
|
565 typename enable_if<
|
Chris@16
|
566 typename gtl_and_3<y_r_b_intersect, typename is_rectangle_concept<typename geometry_concept<rectangle_type_1>::type>::type,
|
Chris@16
|
567 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
568 bool>::type
|
Chris@16
|
569 boundaries_intersect(const rectangle_type_1& rectangle, const rectangle_type_2& b,
|
Chris@16
|
570 bool consider_touch = true) {
|
Chris@16
|
571 return (intersects(rectangle, b, consider_touch) &&
|
Chris@16
|
572 !(contains(rectangle, b, !consider_touch)) &&
|
Chris@16
|
573 !(contains(b, rectangle, !consider_touch)));
|
Chris@16
|
574 }
|
Chris@16
|
575
|
Chris@16
|
576 struct y_r_b_abuts : gtl_yes {};
|
Chris@16
|
577
|
Chris@16
|
578 // check if b is touching 'this' on the end specified by dir
|
Chris@16
|
579 template <typename rectangle_type_1, typename rectangle_type_2>
|
Chris@16
|
580 typename enable_if< typename gtl_and_3<y_r_b_abuts, typename is_rectangle_concept<typename geometry_concept<rectangle_type_1>::type>::type,
|
Chris@16
|
581 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
582 bool>::type
|
Chris@16
|
583 abuts(const rectangle_type_1& rectangle, const rectangle_type_2& b,
|
Chris@16
|
584 direction_2d dir) {
|
Chris@16
|
585 return
|
Chris@16
|
586 abuts(get(rectangle, orientation_2d(dir)),
|
Chris@16
|
587 get(b, orientation_2d(dir)),
|
Chris@16
|
588 direction_1d(dir)) &&
|
Chris@16
|
589 intersects(get(rectangle, orientation_2d(dir).get_perpendicular()),
|
Chris@16
|
590 get(b, orientation_2d(dir).get_perpendicular()), true);
|
Chris@16
|
591 }
|
Chris@16
|
592
|
Chris@16
|
593 struct y_r_b_abuts2 : gtl_yes {};
|
Chris@16
|
594
|
Chris@16
|
595 // check if they are touching in the given orientation
|
Chris@16
|
596 template <typename rectangle_type_1, typename rectangle_type_2>
|
Chris@16
|
597 typename enable_if< typename gtl_and_3<y_r_b_abuts2, typename is_rectangle_concept<typename geometry_concept<rectangle_type_1>::type>::type,
|
Chris@16
|
598 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
599 bool>::type
|
Chris@16
|
600 abuts(const rectangle_type_1& rectangle, const rectangle_type_2& b,
|
Chris@16
|
601 orientation_2d orient) {
|
Chris@16
|
602 return
|
Chris@16
|
603 abuts(get(rectangle, orient), get(b, orient)) &&
|
Chris@16
|
604 intersects(get(rectangle, orient.get_perpendicular()),
|
Chris@16
|
605 get(b, orient.get_perpendicular()), true);
|
Chris@16
|
606 }
|
Chris@16
|
607
|
Chris@16
|
608 struct y_r_b_abuts3 : gtl_yes {};
|
Chris@16
|
609
|
Chris@16
|
610 // check if they are touching but not overlapping
|
Chris@16
|
611 template <typename rectangle_type_1, typename rectangle_type_2>
|
Chris@16
|
612 typename enable_if< typename gtl_and_3<y_r_b_abuts3, typename is_rectangle_concept<typename geometry_concept<rectangle_type_1>::type>::type,
|
Chris@16
|
613 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
614 bool>::type
|
Chris@16
|
615 abuts(const rectangle_type_1& rectangle, const rectangle_type_2& b) {
|
Chris@16
|
616 return abuts(rectangle, b, HORIZONTAL) || abuts(rectangle, b, VERTICAL);
|
Chris@16
|
617 }
|
Chris@16
|
618
|
Chris@16
|
619 struct y_r_b_intersect2 : gtl_yes {};
|
Chris@16
|
620
|
Chris@16
|
621 // intersect rectangle with interval on orient
|
Chris@16
|
622 template <typename rectangle_type, typename interval_type>
|
Chris@16
|
623 typename enable_if<
|
Chris@16
|
624 typename gtl_and_3<y_r_b_intersect2, typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type,
|
Chris@16
|
625 typename is_interval_concept<typename geometry_concept<interval_type>::type>::type>::type,
|
Chris@16
|
626 bool>::type
|
Chris@16
|
627 intersect(rectangle_type& rectangle, const interval_type& b,
|
Chris@16
|
628 orientation_2d orient, bool consider_touch = true) {
|
Chris@16
|
629 typename rectangle_interval_type<rectangle_type>::type ivl = get(rectangle, orient);
|
Chris@16
|
630 if(intersect(ivl, b, consider_touch)) {
|
Chris@16
|
631 set(rectangle, orient, ivl);
|
Chris@16
|
632 return true;
|
Chris@16
|
633 }
|
Chris@16
|
634 return false;
|
Chris@16
|
635 }
|
Chris@16
|
636
|
Chris@16
|
637 struct y_r_b_intersect3 : gtl_yes {};
|
Chris@16
|
638
|
Chris@16
|
639 // clip rectangle to b
|
Chris@16
|
640 template <typename rectangle_type_1, typename rectangle_type_2>
|
Chris@16
|
641 typename enable_if< typename gtl_and_3<y_r_b_intersect3, typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type_1>::type>::type,
|
Chris@16
|
642 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
643 bool>::type
|
Chris@16
|
644 intersect(rectangle_type_1& rectangle, const rectangle_type_2& b, bool consider_touch = true) {
|
Chris@16
|
645 if(intersects(rectangle, b)) {
|
Chris@16
|
646 intersect(rectangle, horizontal(b), HORIZONTAL, consider_touch);
|
Chris@16
|
647 intersect(rectangle, vertical(b), VERTICAL, consider_touch);
|
Chris@16
|
648 return true;
|
Chris@16
|
649 }
|
Chris@16
|
650 return false;
|
Chris@16
|
651 }
|
Chris@16
|
652
|
Chris@16
|
653 struct y_r_g_intersect : gtl_yes {};
|
Chris@16
|
654
|
Chris@16
|
655 // Sets this to the generalized intersection of this and the given rectangle
|
Chris@16
|
656 template <typename rectangle_type_1, typename rectangle_type_2>
|
Chris@16
|
657 typename enable_if< typename gtl_and_3<y_r_g_intersect,
|
Chris@16
|
658 typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type_1>::type>::type,
|
Chris@16
|
659 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
660 rectangle_type_1>::type &
|
Chris@16
|
661 generalized_intersect(rectangle_type_1& rectangle, const rectangle_type_2& b) {
|
Chris@16
|
662 typename rectangle_interval_type<rectangle_type_1>::type ivl = get(rectangle, HORIZONTAL);
|
Chris@16
|
663 generalized_intersect(ivl, horizontal(b));
|
Chris@16
|
664 horizontal(rectangle, ivl);
|
Chris@16
|
665 ivl = vertical(rectangle);
|
Chris@16
|
666 generalized_intersect(ivl, vertical(b));
|
Chris@16
|
667 vertical(rectangle, ivl);
|
Chris@16
|
668 return rectangle;
|
Chris@16
|
669 }
|
Chris@16
|
670
|
Chris@16
|
671 struct y_r_bloat : gtl_yes {};
|
Chris@16
|
672
|
Chris@16
|
673 // bloat the interval specified by orient by bloating
|
Chris@16
|
674 template <typename rectangle_type>
|
Chris@16
|
675 typename enable_if<typename gtl_and<y_r_bloat, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
676 rectangle_type>::type &
|
Chris@16
|
677 bloat(rectangle_type& rectangle, orientation_2d orient,
|
Chris@16
|
678 typename rectangle_coordinate_type<rectangle_type>::type bloating) {
|
Chris@16
|
679 typename rectangle_interval_type<rectangle_type>::type ivl = get(rectangle, orient);
|
Chris@16
|
680 bloat(ivl, bloating);
|
Chris@16
|
681 set(rectangle, orient, ivl);
|
Chris@16
|
682 return rectangle;
|
Chris@16
|
683 }
|
Chris@16
|
684
|
Chris@16
|
685 struct y_r_bloat2 : gtl_yes {};
|
Chris@16
|
686
|
Chris@16
|
687 // bloat the Rectangle by bloating
|
Chris@16
|
688 template <typename rectangle_type>
|
Chris@16
|
689 typename enable_if<typename gtl_and<y_r_bloat2, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
690 rectangle_type>::type &
|
Chris@16
|
691 bloat(rectangle_type& rectangle,
|
Chris@16
|
692 typename rectangle_coordinate_type<rectangle_type>::type bloating) {
|
Chris@16
|
693 bloat(rectangle, HORIZONTAL, bloating);
|
Chris@16
|
694 return bloat(rectangle, VERTICAL, bloating);
|
Chris@16
|
695 }
|
Chris@16
|
696
|
Chris@16
|
697 struct y_r_bloat3 : gtl_yes {};
|
Chris@16
|
698
|
Chris@16
|
699 // bloat the interval cooresponding to orient by bloating in dir direction
|
Chris@16
|
700 template <typename rectangle_type>
|
Chris@16
|
701 typename enable_if<typename gtl_and<y_r_bloat3, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
702 rectangle_type>::type &
|
Chris@16
|
703 bloat(rectangle_type& rectangle, direction_2d dir,
|
Chris@16
|
704 typename rectangle_coordinate_type<rectangle_type>::type bloating) {
|
Chris@16
|
705 typename rectangle_interval_type<rectangle_type>::type ivl = get(rectangle, orientation_2d(dir));
|
Chris@16
|
706 bloat(ivl, direction_1d(dir), bloating);
|
Chris@16
|
707 set(rectangle, orientation_2d(dir), ivl);
|
Chris@16
|
708 return rectangle;
|
Chris@16
|
709 }
|
Chris@16
|
710
|
Chris@16
|
711 struct y_r_shrink : gtl_yes {};
|
Chris@16
|
712
|
Chris@16
|
713 // shrink the interval specified by orient by bloating
|
Chris@16
|
714 template <typename rectangle_type>
|
Chris@16
|
715 typename enable_if<typename gtl_and<y_r_shrink, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
716 rectangle_type>::type &
|
Chris@16
|
717 shrink(rectangle_type& rectangle, orientation_2d orient,
|
Chris@16
|
718 typename rectangle_coordinate_type<rectangle_type>::type shrinking) {
|
Chris@16
|
719 return bloat(rectangle, orient, -shrinking);
|
Chris@16
|
720 }
|
Chris@16
|
721
|
Chris@16
|
722 struct y_r_shrink2 : gtl_yes {};
|
Chris@16
|
723
|
Chris@16
|
724 // shrink the Rectangle by bloating
|
Chris@16
|
725 template <typename rectangle_type>
|
Chris@16
|
726 typename enable_if<typename gtl_and<y_r_shrink2, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
727 rectangle_type>::type &
|
Chris@16
|
728 shrink(rectangle_type& rectangle,
|
Chris@16
|
729 typename rectangle_coordinate_type<rectangle_type>::type shrinking) {
|
Chris@16
|
730 return bloat(rectangle, -shrinking);
|
Chris@16
|
731 }
|
Chris@16
|
732
|
Chris@16
|
733 struct y_r_shrink3 : gtl_yes {};
|
Chris@16
|
734
|
Chris@16
|
735 // shrink the interval cooresponding to orient by bloating in dir direction
|
Chris@16
|
736 template <typename rectangle_type>
|
Chris@16
|
737 typename enable_if<typename gtl_and<y_r_shrink3, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
738 rectangle_type>::type &
|
Chris@16
|
739 shrink(rectangle_type& rectangle, direction_2d dir,
|
Chris@16
|
740 typename rectangle_coordinate_type<rectangle_type>::type shrinking) {
|
Chris@16
|
741 return bloat(rectangle, dir, -shrinking);
|
Chris@16
|
742 }
|
Chris@16
|
743
|
Chris@16
|
744 struct y_r_encompass : gtl_yes {};
|
Chris@16
|
745
|
Chris@16
|
746 // encompass interval on orient
|
Chris@16
|
747 template <typename rectangle_type, typename interval_type>
|
Chris@16
|
748 typename enable_if<typename gtl_and_3<
|
Chris@16
|
749 y_r_encompass,
|
Chris@16
|
750 typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type,
|
Chris@16
|
751 typename is_interval_concept<typename geometry_concept<interval_type>::type>::type>::type,
|
Chris@16
|
752 bool>::type
|
Chris@16
|
753 encompass(rectangle_type& rectangle, const interval_type& b, orientation_2d orient) {
|
Chris@16
|
754 typename rectangle_interval_type<rectangle_type>::type ivl = get(rectangle, orient);
|
Chris@16
|
755 if(encompass(ivl, b)) {
|
Chris@16
|
756 set(rectangle, orient, ivl);
|
Chris@16
|
757 return true;
|
Chris@16
|
758 }
|
Chris@16
|
759 return false;
|
Chris@16
|
760 }
|
Chris@16
|
761
|
Chris@16
|
762 struct y_r_encompass2 : gtl_yes {};
|
Chris@16
|
763
|
Chris@16
|
764 // enlarge rectangle to encompass the Rectangle b
|
Chris@16
|
765 template <typename rectangle_type_1, typename rectangle_type_2>
|
Chris@16
|
766 typename enable_if< typename gtl_and_3<
|
Chris@16
|
767 y_r_encompass2,
|
Chris@16
|
768 typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type_1>::type>::type,
|
Chris@16
|
769 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type >::type,
|
Chris@16
|
770 bool>::type
|
Chris@16
|
771 encompass(rectangle_type_1& rectangle, const rectangle_type_2& b) {
|
Chris@16
|
772 //note that operator | is intentional because both should be called regardless
|
Chris@16
|
773 return encompass(rectangle, horizontal(b), HORIZONTAL) |
|
Chris@16
|
774 encompass(rectangle, vertical(b), VERTICAL);
|
Chris@16
|
775 }
|
Chris@16
|
776
|
Chris@16
|
777 struct y_r_encompass3 : gtl_yes {};
|
Chris@16
|
778
|
Chris@16
|
779 // enlarge rectangle to encompass the point b
|
Chris@16
|
780 template <typename rectangle_type_1, typename point_type>
|
Chris@16
|
781 typename enable_if<typename gtl_and_3<
|
Chris@16
|
782 y_r_encompass3,
|
Chris@16
|
783 typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type_1>::type>::type,
|
Chris@16
|
784 typename is_point_concept<typename geometry_concept<point_type>::type>::type>::type,
|
Chris@16
|
785 bool>::type
|
Chris@16
|
786 encompass(rectangle_type_1& rectangle, const point_type& b) {
|
Chris@16
|
787 typename rectangle_interval_type<rectangle_type_1>::type hivl, vivl;
|
Chris@16
|
788 hivl = horizontal(rectangle);
|
Chris@16
|
789 vivl = vertical(rectangle);
|
Chris@16
|
790 //note that operator | is intentional because both should be called regardless
|
Chris@16
|
791 bool retval = encompass(hivl, x(b)) | encompass(vivl, y(b));
|
Chris@16
|
792 if(retval) {
|
Chris@16
|
793 horizontal(rectangle, hivl);
|
Chris@16
|
794 vertical(rectangle, vivl);
|
Chris@16
|
795 }
|
Chris@16
|
796 return retval;
|
Chris@16
|
797 }
|
Chris@16
|
798
|
Chris@16
|
799 struct y_r_center : gtl_yes {};
|
Chris@16
|
800
|
Chris@16
|
801 // returns the center of the rectangle
|
Chris@16
|
802 template <typename point_type, typename rectangle_type>
|
Chris@16
|
803 typename enable_if<
|
Chris@16
|
804 typename gtl_and_3<y_r_center, typename is_mutable_point_concept<typename geometry_concept<point_type>::type>::type,
|
Chris@16
|
805 typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
806 bool>::type
|
Chris@16
|
807 center(point_type& center_point, const rectangle_type& rectangle) {
|
Chris@16
|
808 center_point = construct<point_type>(center(horizontal(rectangle)),
|
Chris@16
|
809 center(vertical(rectangle)));
|
Chris@16
|
810 return true;
|
Chris@16
|
811 }
|
Chris@16
|
812
|
Chris@16
|
813 struct y_r_get_corner : gtl_yes {};
|
Chris@16
|
814
|
Chris@16
|
815 template <typename point_type, typename rectangle_type>
|
Chris@16
|
816 typename enable_if<
|
Chris@16
|
817 typename gtl_and_3<y_r_get_corner, typename is_mutable_point_concept<typename geometry_concept<point_type>::type>::type,
|
Chris@16
|
818 typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
819 bool>::type
|
Chris@16
|
820 get_corner(point_type& corner_point, const rectangle_type& rectangle, direction_2d direction_facing, direction_1d direction_turning) {
|
Chris@16
|
821 typedef typename rectangle_coordinate_type<rectangle_type>::type Unit;
|
Chris@16
|
822 Unit u1 = get(rectangle, direction_facing);
|
Chris@16
|
823 Unit u2 = get(rectangle, direction_facing.turn(direction_turning));
|
Chris@16
|
824 if(orientation_2d(direction_facing).to_int()) std::swap(u1, u2);
|
Chris@16
|
825 corner_point = construct<point_type>(u1, u2);
|
Chris@16
|
826 return true;
|
Chris@16
|
827 }
|
Chris@16
|
828
|
Chris@16
|
829 struct y_r_get_half : gtl_yes {};
|
Chris@16
|
830
|
Chris@16
|
831 template <typename rectangle_type>
|
Chris@16
|
832 typename enable_if<typename gtl_and<y_r_get_half, typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
833 rectangle_type>::type
|
Chris@16
|
834 get_half(const rectangle_type& rectangle, direction_2d dir) {
|
Chris@16
|
835 rectangle_type retval(rectangle);
|
Chris@16
|
836 set(retval, orientation_2d(dir), get_half(get(rectangle, orientation_2d(dir)), direction_1d(dir)));
|
Chris@16
|
837 return retval;
|
Chris@16
|
838 }
|
Chris@16
|
839
|
Chris@16
|
840 struct y_r_join_with : gtl_yes {};
|
Chris@16
|
841
|
Chris@16
|
842 template <typename rectangle_type_1, typename rectangle_type_2>
|
Chris@16
|
843 typename enable_if< typename gtl_and_3<y_r_join_with, typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type_1>::type>::type,
|
Chris@16
|
844 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
845 bool>::type
|
Chris@16
|
846 join_with(rectangle_type_1& rectangle, const rectangle_type_2& b) {
|
Chris@16
|
847 typedef typename rectangle_interval_type<rectangle_type_1>::type Interval1;
|
Chris@16
|
848 typedef typename rectangle_interval_type<rectangle_type_2>::type Interval2;
|
Chris@16
|
849 Interval1 hi1 = get(rectangle, HORIZONTAL);
|
Chris@16
|
850 Interval1 vi1 = get(rectangle, VERTICAL);
|
Chris@16
|
851 Interval2 hi2 = get(b, HORIZONTAL), vi2 = get(b, VERTICAL);
|
Chris@16
|
852 Interval1 temp;
|
Chris@16
|
853 if (equivalence(hi1, hi2) && join_with(vi1, vi2)) {
|
Chris@16
|
854 vertical(rectangle, vi1);
|
Chris@16
|
855 return true;
|
Chris@16
|
856 }
|
Chris@16
|
857 if (equivalence(vi1, vi2) && join_with(hi1, hi2)) {
|
Chris@16
|
858 horizontal(rectangle, hi1);
|
Chris@16
|
859 return true;
|
Chris@16
|
860 }
|
Chris@16
|
861 return false;
|
Chris@16
|
862 }
|
Chris@16
|
863
|
Chris@16
|
864 struct y_r_eda2 : gtl_yes {};
|
Chris@16
|
865
|
Chris@16
|
866 template <typename rectangle_type, typename point_type>
|
Chris@16
|
867 typename enable_if< typename gtl_and_3<y_r_eda2,
|
Chris@16
|
868 typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type,
|
Chris@16
|
869 typename is_point_concept<typename geometry_concept<point_type>::type>::type>::type,
|
Chris@16
|
870 typename rectangle_difference_type<rectangle_type>::type>::type
|
Chris@16
|
871 euclidean_distance(const rectangle_type& lvalue, const point_type& rvalue, orientation_2d orient) {
|
Chris@16
|
872 return euclidean_distance(get(lvalue, orient), get(rvalue, orient));
|
Chris@16
|
873 }
|
Chris@16
|
874
|
Chris@16
|
875 struct y_r_eda : gtl_yes {};
|
Chris@16
|
876
|
Chris@16
|
877 template <typename rectangle_type, typename rectangle_type_2>
|
Chris@16
|
878 typename enable_if<
|
Chris@16
|
879 typename gtl_and_3<y_r_eda,
|
Chris@16
|
880 typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type,
|
Chris@16
|
881 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
882 typename rectangle_difference_type<rectangle_type>::type>::type
|
Chris@16
|
883 euclidean_distance(const rectangle_type& lvalue, const rectangle_type_2& rvalue, orientation_2d orient) {
|
Chris@16
|
884 return euclidean_distance(get(lvalue, orient), get(rvalue, orient));
|
Chris@16
|
885 }
|
Chris@16
|
886
|
Chris@16
|
887 struct y_r_sed : gtl_yes {};
|
Chris@16
|
888
|
Chris@16
|
889 template <typename rectangle_type, typename point_type>
|
Chris@16
|
890 typename enable_if< typename gtl_and_3<y_r_sed,
|
Chris@16
|
891 typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type,
|
Chris@16
|
892 typename is_point_concept<typename geometry_concept<point_type>::type>::type>::type,
|
Chris@16
|
893 typename rectangle_difference_type<rectangle_type>::type>::type
|
Chris@16
|
894 square_euclidean_distance(rectangle_type& lvalue, const point_type& rvalue) {
|
Chris@16
|
895 typename coordinate_traits<typename rectangle_coordinate_type<rectangle_type>::type>::coordinate_difference xdist, ydist;
|
Chris@16
|
896 xdist = euclidean_distance(lvalue, rvalue, HORIZONTAL);
|
Chris@16
|
897 ydist = euclidean_distance(lvalue, rvalue, VERTICAL);
|
Chris@16
|
898 return (xdist * xdist) + (ydist * ydist);
|
Chris@16
|
899 }
|
Chris@16
|
900
|
Chris@16
|
901 struct y_r_sed2 : gtl_yes {};
|
Chris@16
|
902
|
Chris@16
|
903 template <typename rectangle_type, typename rectangle_type_2>
|
Chris@16
|
904 typename enable_if<
|
Chris@16
|
905 typename gtl_and_3<y_r_sed2, typename is_rectangle_concept< typename geometry_concept<rectangle_type>::type>::type,
|
Chris@16
|
906 typename is_rectangle_concept< typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
907 typename rectangle_difference_type<rectangle_type>::type>::type
|
Chris@16
|
908 square_euclidean_distance(const rectangle_type& lvalue, const rectangle_type_2& rvalue) {
|
Chris@16
|
909 typename coordinate_traits<typename rectangle_coordinate_type<rectangle_type>::type>::coordinate_difference xdist, ydist;
|
Chris@16
|
910 xdist = euclidean_distance(lvalue, rvalue, HORIZONTAL);
|
Chris@16
|
911 ydist = euclidean_distance(lvalue, rvalue, VERTICAL);
|
Chris@16
|
912 return (xdist * xdist) + (ydist * ydist);
|
Chris@16
|
913 }
|
Chris@16
|
914
|
Chris@16
|
915 struct y_r_edist : gtl_yes {};
|
Chris@16
|
916
|
Chris@16
|
917 template <typename rectangle_type, typename point_type>
|
Chris@16
|
918 typename enable_if< typename gtl_and_3<y_r_edist, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type,
|
Chris@16
|
919 typename is_point_concept<typename geometry_concept<point_type>::type>::type>::type,
|
Chris@16
|
920 typename rectangle_distance_type<rectangle_type>::type>::type
|
Chris@16
|
921 euclidean_distance(rectangle_type& lvalue, const point_type& rvalue) {
|
Chris@16
|
922 return std::sqrt((double)(square_euclidean_distance(lvalue, rvalue)));
|
Chris@16
|
923 }
|
Chris@16
|
924
|
Chris@16
|
925 struct y_r_edist2 : gtl_yes {};
|
Chris@16
|
926
|
Chris@16
|
927 template <typename rectangle_type, typename rectangle_type_2>
|
Chris@16
|
928 typename enable_if< typename gtl_and_3<y_r_edist2, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type,
|
Chris@16
|
929 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
930 typename rectangle_distance_type<rectangle_type>::type>::type
|
Chris@16
|
931 euclidean_distance(const rectangle_type& lvalue, const rectangle_type_2& rvalue) {
|
Chris@16
|
932 double val = (int)square_euclidean_distance(lvalue, rvalue);
|
Chris@16
|
933 return std::sqrt(val);
|
Chris@16
|
934 }
|
Chris@16
|
935
|
Chris@16
|
936 struct y_r_mdist : gtl_yes {};
|
Chris@16
|
937
|
Chris@16
|
938 template <typename rectangle_type, typename point_type>
|
Chris@16
|
939 typename enable_if<
|
Chris@16
|
940 typename gtl_and_3<y_r_mdist, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type,
|
Chris@16
|
941 typename is_point_concept<typename geometry_concept<point_type>::type>::type>::type,
|
Chris@16
|
942 typename rectangle_difference_type<rectangle_type>::type>::type
|
Chris@16
|
943 manhattan_distance(rectangle_type& lvalue, const point_type& rvalue) {
|
Chris@16
|
944 typename coordinate_traits<typename rectangle_coordinate_type<rectangle_type>::type>::coordinate_difference xdist, ydist;
|
Chris@16
|
945 xdist = euclidean_distance(lvalue, rvalue, HORIZONTAL);
|
Chris@16
|
946 ydist = euclidean_distance(lvalue, rvalue, VERTICAL);
|
Chris@16
|
947 return xdist + ydist;
|
Chris@16
|
948 }
|
Chris@16
|
949
|
Chris@16
|
950 struct y_r_mdist2 : gtl_yes {};
|
Chris@16
|
951
|
Chris@16
|
952 template <typename rectangle_type, typename rectangle_type_2>
|
Chris@16
|
953 typename enable_if<
|
Chris@16
|
954 typename gtl_and_3<y_r_mdist2, typename is_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type,
|
Chris@16
|
955 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
956 typename rectangle_difference_type<rectangle_type>::type>::type
|
Chris@16
|
957 manhattan_distance(const rectangle_type& lvalue, const rectangle_type_2& rvalue) {
|
Chris@16
|
958 typename coordinate_traits<typename rectangle_coordinate_type<rectangle_type>::type>::coordinate_difference xdist, ydist;
|
Chris@16
|
959 xdist = euclidean_distance(lvalue, rvalue, HORIZONTAL);
|
Chris@16
|
960 ydist = euclidean_distance(lvalue, rvalue, VERTICAL);
|
Chris@16
|
961 return xdist + ydist;
|
Chris@16
|
962 }
|
Chris@16
|
963
|
Chris@16
|
964 struct y_r_scale_up : gtl_yes {};
|
Chris@16
|
965
|
Chris@16
|
966 template <typename rectangle_type>
|
Chris@16
|
967 typename enable_if<typename gtl_and<y_r_scale_up, typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
968 rectangle_type>::type &
|
Chris@16
|
969 scale_up(rectangle_type& rectangle,
|
Chris@16
|
970 typename coordinate_traits<typename rectangle_coordinate_type<rectangle_type>::type>::unsigned_area_type factor) {
|
Chris@101
|
971 typename rectangle_interval_type<rectangle_type>::type h = horizontal(rectangle);
|
Chris@101
|
972 horizontal(rectangle, scale_up(h, factor));
|
Chris@101
|
973 typename rectangle_interval_type<rectangle_type>::type v = vertical(rectangle);
|
Chris@101
|
974 vertical(rectangle, scale_up(v, factor));
|
Chris@16
|
975 return rectangle;
|
Chris@16
|
976 }
|
Chris@16
|
977
|
Chris@16
|
978 struct y_r_scale_down : gtl_yes {};
|
Chris@16
|
979
|
Chris@16
|
980 template <typename rectangle_type>
|
Chris@16
|
981 typename enable_if<typename gtl_and<y_r_scale_down, typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
982 rectangle_type>::type &
|
Chris@16
|
983 scale_down(rectangle_type& rectangle,
|
Chris@16
|
984 typename coordinate_traits<typename rectangle_coordinate_type<rectangle_type>::type>::unsigned_area_type factor) {
|
Chris@101
|
985 typename rectangle_interval_type<rectangle_type>::type h = horizontal(rectangle);
|
Chris@101
|
986 horizontal(rectangle, scale_down(h, factor));
|
Chris@101
|
987 typename rectangle_interval_type<rectangle_type>::type v = vertical(rectangle);
|
Chris@101
|
988 vertical(rectangle, scale_down(v, factor));
|
Chris@16
|
989 return rectangle;
|
Chris@16
|
990 }
|
Chris@16
|
991
|
Chris@16
|
992 struct y_r_scale : gtl_yes {};
|
Chris@16
|
993
|
Chris@16
|
994 template <typename rectangle_type, typename scaling_type>
|
Chris@16
|
995 typename enable_if<typename gtl_and<y_r_scale, typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
996 rectangle_type>::type &
|
Chris@16
|
997 scale(rectangle_type& rectangle, const scaling_type& scaling) {
|
Chris@16
|
998 point_data<typename rectangle_coordinate_type<rectangle_type>::type> llp(xl(rectangle), yl(rectangle));
|
Chris@16
|
999 point_data<typename rectangle_coordinate_type<rectangle_type>::type> urp(xl(rectangle), yl(rectangle));
|
Chris@16
|
1000 scale(llp, scaling);
|
Chris@16
|
1001 scale(urp, scaling);
|
Chris@16
|
1002 set_points(rectangle, llp, urp);
|
Chris@16
|
1003 return rectangle;
|
Chris@16
|
1004 }
|
Chris@16
|
1005
|
Chris@16
|
1006 struct y_r_transform : gtl_yes {};
|
Chris@16
|
1007
|
Chris@16
|
1008 template <typename rectangle_type, typename transformation_type>
|
Chris@16
|
1009 typename enable_if<typename gtl_and<y_r_transform, typename is_mutable_rectangle_concept<typename geometry_concept<rectangle_type>::type>::type>::type,
|
Chris@16
|
1010 rectangle_type>::type &
|
Chris@16
|
1011 transform(rectangle_type& rectangle, const transformation_type& transformation) {
|
Chris@16
|
1012 point_data<typename rectangle_coordinate_type<rectangle_type>::type> llp(xl(rectangle), yl(rectangle));
|
Chris@16
|
1013 point_data<typename rectangle_coordinate_type<rectangle_type>::type> urp(xh(rectangle), yh(rectangle));
|
Chris@16
|
1014 transform(llp, transformation);
|
Chris@16
|
1015 transform(urp, transformation);
|
Chris@16
|
1016 set_points(rectangle, llp, urp);
|
Chris@16
|
1017 return rectangle;
|
Chris@16
|
1018 }
|
Chris@16
|
1019
|
Chris@16
|
1020 template <typename rectangle_type_1, typename rectangle_type_2>
|
Chris@16
|
1021 class less_rectangle_concept {
|
Chris@16
|
1022 private:
|
Chris@16
|
1023 orientation_2d orient_;
|
Chris@16
|
1024 public:
|
Chris@16
|
1025 inline less_rectangle_concept(orientation_2d orient = VERTICAL) : orient_(orient) {}
|
Chris@16
|
1026 typename enable_if<
|
Chris@16
|
1027 typename gtl_and< typename is_rectangle_concept<typename geometry_concept<rectangle_type_1>::type>::type,
|
Chris@16
|
1028 typename is_rectangle_concept<typename geometry_concept<rectangle_type_2>::type>::type>::type,
|
Chris@16
|
1029 bool>::type
|
Chris@16
|
1030 operator () (const rectangle_type_1& a,
|
Chris@16
|
1031 const rectangle_type_2& b) const {
|
Chris@16
|
1032 typedef typename rectangle_coordinate_type<rectangle_type_1>::type Unit;
|
Chris@16
|
1033 Unit vl1 = get(get(a, orient_), LOW);
|
Chris@16
|
1034 Unit vl2 = get(get(b, orient_), LOW);
|
Chris@16
|
1035 if(vl1 > vl2) return false;
|
Chris@16
|
1036 if(vl1 == vl2) {
|
Chris@16
|
1037 orientation_2d perp = orient_.get_perpendicular();
|
Chris@16
|
1038 Unit hl1 = get(get(a, perp), LOW);
|
Chris@16
|
1039 Unit hl2 = get(get(b, perp), LOW);
|
Chris@16
|
1040 if(hl1 > hl2) return false;
|
Chris@16
|
1041 if(hl1 == hl2) {
|
Chris@16
|
1042 Unit vh1 = get(get(a, orient_), HIGH);
|
Chris@16
|
1043 Unit vh2 = get(get(b, orient_), HIGH);
|
Chris@16
|
1044 if(vh1 > vh2) return false;
|
Chris@16
|
1045 if(vh1 == vh2) {
|
Chris@16
|
1046 Unit hh1 = get(get(a, perp), HIGH);
|
Chris@16
|
1047 Unit hh2 = get(get(b, perp), HIGH);
|
Chris@16
|
1048 return hh1 < hh2;
|
Chris@16
|
1049 }
|
Chris@16
|
1050 }
|
Chris@16
|
1051 }
|
Chris@16
|
1052 return true;
|
Chris@16
|
1053 }
|
Chris@16
|
1054
|
Chris@16
|
1055 };
|
Chris@16
|
1056
|
Chris@16
|
1057 template <typename T>
|
Chris@16
|
1058 template <typename interval_type_1>
|
Chris@16
|
1059 inline void rectangle_data<T>::set(orientation_2d orient, const interval_type_1& interval) {
|
Chris@16
|
1060 assign(ranges_[orient.to_int()], interval);
|
Chris@16
|
1061 }
|
Chris@16
|
1062
|
Chris@16
|
1063 template <class T>
|
Chris@16
|
1064 template <class T2>
|
Chris@16
|
1065 rectangle_data<T>& rectangle_data<T>::operator=(const T2& rvalue) {
|
Chris@16
|
1066 assign(*this, rvalue);
|
Chris@16
|
1067 return *this;
|
Chris@16
|
1068 }
|
Chris@16
|
1069
|
Chris@16
|
1070 template <class T>
|
Chris@16
|
1071 template <class T2>
|
Chris@16
|
1072 bool rectangle_data<T>::operator==(const T2& rvalue) const {
|
Chris@16
|
1073 return equivalence(*this, rvalue);
|
Chris@16
|
1074 }
|
Chris@16
|
1075
|
Chris@16
|
1076 template <typename T>
|
Chris@16
|
1077 struct geometry_concept<rectangle_data<T> > {
|
Chris@16
|
1078 typedef rectangle_concept type;
|
Chris@16
|
1079 };
|
Chris@16
|
1080 }
|
Chris@16
|
1081 }
|
Chris@16
|
1082 #endif
|