Debian Codegraph @

cuneiform_src/Kern/lns32/src/lns_skew1024.h

raw
1 /*
2 Copyright (c) 1993-2008, Cognitive Technologies
3 All rights reserved.
4
5 Разрешается повторное распространение и использование как в виде исходного кода,
6 так и в двоичной форме, с изменениями или без, при соблюдении следующих условий:
7
8 * При повторном распространении исходного кода должны оставаться указанное
9 выше уведомление об авторском праве, этот список условий и последующий
10 отказ от гарантий.
11 * При повторном распространении двоичного кода в документации и/или в
12 других материалах, поставляемых при распространении, должны сохраняться
13 указанная выше информация об авторском праве, этот список условий и
14 последующий отказ от гарантий.
15 * Ни название Cognitive Technologies, ни имена ее сотрудников не могут
16 быть использованы в качестве средства поддержки и/или продвижения
17 продуктов, основанных на этом ПО, без предварительного письменного
18 разрешения.
19
20 ЭТА ПРОГРАММА ПРЕДОСТАВЛЕНА ВЛАДЕЛЬЦАМИ АВТОРСКИХ ПРАВ И/ИЛИ ДРУГИМИ ЛИЦАМИ "КАК
21 ОНА ЕСТЬ" БЕЗ КАКОГО-ЛИБО ВИДА ГАРАНТИЙ, ВЫРАЖЕННЫХ ЯВНО ИЛИ ПОДРАЗУМЕВАЕМЫХ,
22 ВКЛЮЧАЯ ГАРАНТИИ КОММЕРЧЕСКОЙ ЦЕННОСТИ И ПРИГОДНОСТИ ДЛЯ КОНКРЕТНОЙ ЦЕЛИ, НО НЕ
23 ОГРАНИЧИВАЯСЬ ИМИ. НИ ВЛАДЕЛЕЦ АВТОРСКИХ ПРАВ И НИ ОДНО ДРУГОЕ ЛИЦО, КОТОРОЕ
24 МОЖЕТ ИЗМЕНЯТЬ И/ИЛИ ПОВТОРНО РАСПРОСТРАНЯТЬ ПРОГРАММУ, НИ В КОЕМ СЛУЧАЕ НЕ
25 НЕСЁТ ОТВЕТСТВЕННОСТИ, ВКЛЮЧАЯ ЛЮБЫЕ ОБЩИЕ, СЛУЧАЙНЫЕ, СПЕЦИАЛЬНЫЕ ИЛИ
26 ПОСЛЕДОВАВШИЕ УБЫТКИ, СВЯЗАННЫЕ С ИСПОЛЬЗОВАНИЕМ ИЛИ ПОНЕСЕННЫЕ ВСЛЕДСТВИЕ
27 НЕВОЗМОЖНОСТИ ИСПОЛЬЗОВАНИЯ ПРОГРАММЫ (ВКЛЮЧАЯ ПОТЕРИ ДАННЫХ, ИЛИ ДАННЫЕ,
28 СТАВШИЕ НЕГОДНЫМИ, ИЛИ УБЫТКИ И/ИЛИ ПОТЕРИ ДОХОДОВ, ПОНЕСЕННЫЕ ИЗ-ЗА ДЕЙСТВИЙ
29 ТРЕТЬИХ ЛИЦ И/ИЛИ ОТКАЗА ПРОГРАММЫ РАБОТАТЬ СОВМЕСТНО С ДРУГИМИ ПРОГРАММАМИ,
30 НО НЕ ОГРАНИЧИВАЯСЬ ЭТИМИ СЛУЧАЯМИ), НО НЕ ОГРАНИЧИВАЯСЬ ИМИ, ДАЖЕ ЕСЛИ ТАКОЙ
31 ВЛАДЕЛЕЦ ИЛИ ДРУГОЕ ЛИЦО БЫЛИ ИЗВЕЩЕНЫ О ВОЗМОЖНОСТИ ТАКИХ УБЫТКОВ И ПОТЕРЬ.
32
33 Redistribution and use in source and binary forms, with or without modification,
34 are permitted provided that the following conditions are met:
35
36 * Redistributions of source code must retain the above copyright notice,
37 this list of conditions and the following disclaimer.
38 * Redistributions in binary form must reproduce the above copyright notice,
39 this list of conditions and the following disclaimer in the documentation
40 and/or other materials provided with the distribution.
41 * Neither the name of the Cognitive Technologies nor the names of its
42 contributors may be used to endorse or promote products derived from this
43 software without specific prior written permission.
44
45 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
46 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
47 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
48 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
49 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
51 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
52 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
53 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
54 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55 */
56
57
58 //////////////////////////////////////////////////////
59 // Rotation routines:
60 //
61 // inline Point32& Deskew( Point32& pt, int32_t skew1024);
62 // inline Point16& Deskew( Point16& pt, int32_t skew1024);
63 //
64 // NOTE: POSITIVE SKEW == CLOCKWISE
65 //////////////////////////////////////////////////////
66
67 #ifdef __cplusplus
68
69 #ifndef __SKEW1024_H
70 #define __SKEW1024_H
71
72 #include "cttypes.h"
73
74 inline Point32& Deskew( Point32& pt, int32_t skew1024)
75 {
76 long phi_sq = (skew1024*skew1024);
77 long dx = ( (skew1024*pt.y+0x200) >> 10 );
78 long dy = ( (skew1024*pt.x+0x200) >> 10 );
79 long ddx =( (phi_sq*pt.x+0x100000) >> 21 );
80 long ddy =( (phi_sq*pt.y+0x100000) >> 21 );
81 pt.x -= dx;
82 pt.x -= ddx;
83 pt.y += dy;
84 pt.y -= ddy;
85 return pt;
86 }
87
88 inline Point16& Deskew( Point16& pt, int32_t skew1024)
89 {
90 long phi_sq = (skew1024*skew1024);
91 long dx = ( (skew1024*(long)pt.y+0x200) >> 10 );
92 long dy = ( (skew1024*(long)pt.x+0x200) >> 10 );
93 long ddx =( (phi_sq*(long)pt.x+0x100000) >> 21 );
94 long ddy =( (phi_sq*(long)pt.y+0x100000) >> 21 );
95 pt.x -= (int16_t)dx;
96 pt.x -= (int16_t)ddx;
97 pt.y += (int16_t)dy;
98 pt.y -= (int16_t)ddy;
99 return pt;
100 }
101
102 inline Point32& DeskewRel( Point32& pt, int32_t skew1024, Point32& rel )
103 {
104 pt.x -= rel.x;
105 pt.y -= rel.y;
106 Deskew( pt, skew1024 );
107 pt.x += rel.x;
108 pt.y += rel.y;
109 return pt;
110 }
111
112 inline Point16& DeskewRel( Point16& pt, int32_t skew1024, Point16& rel )
113 {
114 pt.x -= rel.x;
115 pt.y -= rel.y;
116 Deskew( pt, skew1024 );
117 pt.x += rel.x;
118 pt.y += rel.y;
119 return pt;
120 }
121
122 inline Point32& GetCenter( const Rect32& rc, Point32& center)
123 {
124 center.x = (rc.left+rc.right)>>1;
125 center.y = (rc.top+rc.bottom)>>1;
126 return center;
127 }
128
129 inline Point16& GetCenter( const Rect16& rc, Point16& center)
130 {
131 center.x = (rc.left+rc.right)>>1;
132 center.y = (rc.top+rc.bottom)>>1;
133 return center;
134 }
135
136 inline Point32& Copy(Point32& dst, Point16 const & src)
137 {
138 dst.x=src.x; dst.y=src.y;
139 return dst;
140 }
141
142 inline Point16& Copy(Point16& dst, Point32 const & src)
143 {
144 dst.x=(int16_t)src.x; dst.y=(int16_t)src.y;
145 return dst;
146 }
147
148 inline Rect32& Copy(Rect32& dst, Rect16 const & src)
149 {
150 dst.left = src.left; dst.right = src.right;
151 dst.top = src.top; dst.bottom = src.bottom;
152 return dst;
153 }
154
155 inline Rect16& Copy(Rect16& dst, Rect32 const & src)
156 {
157 dst.left = (int16_t)src.left; dst.right = (int16_t)src.right;
158 dst.top = (int16_t)src.top; dst.bottom = (int16_t)src.bottom;
159 return dst;
160 }
161
162 //////////////////////////////////////////////////////////
163 // diagonal points => rect
164 inline Rect32& Pt2Rc(Rect32& dst, Point16 const & a, Point16 const & b )
165 {
166 dst.left = a.x; dst.right = b.x;
167 dst.top = a.y; dst.bottom = b.y;
168 return dst;
169 }
170 inline Rect16& Pt2Rc(Rect16& dst, Point16 const & a, Point16 const & b )
171 {
172 dst.left = a.x; dst.right = b.x;
173 dst.top = a.y; dst.bottom = b.y;
174 return dst;
175 }
176 inline Rect32& Pt2Rc(Rect32& dst, Point32 const & a, Point32 const & b )
177 {
178 dst.left = a.x; dst.right = b.x;
179 dst.top = a.y; dst.bottom = b.y;
180 return dst;
181 }
182 inline Rect16& Pt2Rc(Rect16& dst, Point32 const & a, Point32 const & b )
183 {
184 dst.left = (int16_t)a.x; dst.right = (int16_t)b.x;
185 dst.top = (int16_t)a.y; dst.bottom = (int16_t)b.y;
186 return dst;
187 }
188
189 ////////////////////////////////////////////////////
190 // movements ( -=, += )
191 #define RC_MINUS_PT { rc.left -= pt.x; rc.right -= pt.x; rc.top -= pt.y; rc.bottom-= pt.y; return rc; }
192 #define RC_PLUS_PT { rc.left += pt.x; rc.right += pt.x; rc.top += pt.y; rc.bottom+= pt.y; return rc; }
193 #define RC_MINUS_PT_16 { rc.left -= (int16_t)pt.x; rc.right -= (int16_t)pt.x; rc.top -= (int16_t)pt.y; rc.bottom-= (int16_t)pt.y; return rc; }
194 #define RC_PLUS_PT_16 { rc.left += (int16_t)pt.x; rc.right += (int16_t)pt.x; rc.top += (int16_t)pt.y; rc.bottom+= (int16_t)pt.y; return rc; }
195 inline Rect32& operator -=(Rect32& rc, Point32 const & pt) RC_MINUS_PT
196 inline Rect16& operator -=(Rect16& rc, Point16 const & pt) RC_MINUS_PT_16
197 inline Rect32& operator -=(Rect32& rc, Point16 const & pt) RC_MINUS_PT
198 inline Rect16& operator -=(Rect16& rc, Point32 const & pt) RC_MINUS_PT_16
199 inline Rect32& operator +=(Rect32& rc, Point32 const & pt) RC_PLUS_PT
200 inline Rect16& operator +=(Rect16& rc, Point16 const & pt) RC_PLUS_PT_16
201 inline Rect32& operator +=(Rect32& rc, Point16 const & pt) RC_PLUS_PT
202 inline Rect16& operator +=(Rect16& rc, Point32 const & pt) RC_PLUS_PT_16
203
204 #define PT_MINUS_PT { pt.x -= pt1.x; pt.y -= pt1.y; return pt; }
205 #define PT_PLUS_PT { pt.x += pt1.x; pt.y += pt1.y; return pt; }
206 inline Point32& operator -=(Point32& pt, Point32 const & pt1) PT_MINUS_PT
207 inline Point16& operator -=(Point16& pt, Point16 const & pt1) PT_MINUS_PT
208 inline Point32& operator -=(Point32& pt, Point16 const & pt1) PT_MINUS_PT
209 inline Point16& operator -=(Point16& pt, Point32 const & pt1) PT_MINUS_PT
210 inline Point32& operator +=(Point32& pt, Point32 const & pt1) PT_PLUS_PT
211 inline Point16& operator +=(Point16& pt, Point16 const & pt1) PT_PLUS_PT
212 inline Point32& operator +=(Point32& pt, Point16 const & pt1) PT_PLUS_PT
213 inline Point16& operator +=(Point16& pt, Point32 const & pt1) PT_PLUS_PT
214
215 //////////////////////////////////////////////////
216 // With integer: *= /= -= +=
217
218 // --- addition ---
219 inline Rect32& operator +=(Rect32& rc, const int a )
220 {
221 rc.left += a; rc.right += a;
222 rc.top += a; rc.bottom+= a;
223 return rc;
224 }
225 inline Rect16& operator +=(Rect16& rc, const int a )
226 {
227 rc.left += a; rc.right += a;
228 rc.top += a; rc.bottom+= a;
229 return rc;
230 }
231 inline Point32& operator +=(Point32& pt, const int a )
232 {
233 pt.x += a; pt.y += a;
234 return pt;
235 }
236 inline Point16& operator +=(Point16& pt, const int a )
237 {
238 pt.x += a; pt.y += a;
239 return pt;
240 }
241
242 // --- subtraction ---
243 inline Rect32& operator -=(Rect32& rc, const int a )
244 {
245 rc.left -= a; rc.right -= a;
246 rc.top -= a; rc.bottom-= a;
247 return rc;
248 }
249 inline Rect16& operator -=(Rect16& rc, const int a )
250 {
251 rc.left -= a; rc.right -= a;
252 rc.top -= a; rc.bottom-= a;
253 return rc;
254 }
255 inline Point32& operator -=(Point32& pt, const int a )
256 {
257 pt.x -= a; pt.y -= a;
258 return pt;
259 }
260 inline Point16& operator -=(Point16& pt, const int a )
261 {
262 pt.x -= a; pt.y -= a;
263 return pt;
264 }
265
266 // --- multiplication ---
267 #define RC_MUL_A { rc.left*=a; rc.right*=a; rc.top*=a; rc.bottom*=a; return rc;}
268 inline Rect32& operator *=(Rect32& rc, const int a ) RC_MUL_A
269 inline Rect16& operator *=(Rect16& rc, const int a ) RC_MUL_A
270 inline Rect32& operator *=(Rect32& rc, const double a ) RC_MUL_A
271 inline Rect16& operator *=(Rect16& rc, const double a ) RC_MUL_A
272
273 #define PT_MUL_A { pt.x *= a; pt.y *= a; return pt; }
274 inline Point32& operator *=(Point32& pt, const int a ) PT_MUL_A
275 inline Point16& operator *=(Point16& pt, const int a ) PT_MUL_A
276 inline Point32& operator *=(Point32& pt, double a ) PT_MUL_A
277 inline Point16& operator *=(Point16& pt, double a ) PT_MUL_A
278
279 // --- division ---
280 inline Rect32& operator /=(Rect32& rc, const int a )
281 {
282 rc.left /= a; rc.right /= a;
283 rc.top /= a; rc.bottom/= a;
284 return rc;
285 }
286 inline Rect16& operator /=(Rect16& rc, const int a )
287 {
288 rc.left /= a; rc.right /= a;
289 rc.top /= a; rc.bottom/= a;
290 return rc;
291 }
292 inline Point32& operator /=(Point32& pt, const int a )
293 {
294 pt.x /= a; pt.y /= a;
295 return pt;
296 }
297 inline Point16& operator /=(Point16& pt, const int a )
298 {
299 pt.x /= a; pt.y /= a;
300 return pt;
301 }
302
303 //////////////////////////////////////////////////
304 // equality
305 inline Bool operator == ( const Rect16& r1, const Rect16& r2 )
306 { return r1.left == r2.left
307 && r1.top == r2.top
308 && r1.right == r2.right
309 && r1.bottom== r2.bottom;
310 }
311
312 inline Bool operator == ( const Rect32& r1, const Rect32& r2 )
313 { return r1.left == r2.left
314 && r1.top == r2.top
315 && r1.right == r2.right
316 && r1.bottom== r2.bottom;
317 }
318
319 inline Bool operator == ( const Point16& p1, const Point16& p2 )
320 { return p1.x == p2.x && p1.y == p2.y;
321 }
322
323 inline Bool operator == ( const Point32& p1, const Point32& p2 )
324 { return p1.x == p2.x && p1.y == p2.y;
325 }
326
327
328 //////////////////////////////////////////////////
329 inline Rect32& DeskewCenter( Rect32& rc, int32_t skew1024)
330 {
331 Point32 center; GetCenter(rc, center);
332 Point32 old_center = center;
333 Deskew( center, skew1024 );
334 center -= old_center; // diff
335 rc += center;
336 return rc;
337 }
338
339 inline Rect16& DeskewCenter( Rect16& rc, int32_t skew1024)
340 {
341 Point16 center; GetCenter(rc, center);
342 Point16 old_center = center;
343 Deskew( center, skew1024 );
344 center -= old_center; // diff
345 rc += center;
346 return rc;
347 }
348
349 inline Rect32& DeskewCenterRel( Rect32& rc, int32_t skew1024, Point32& pt)
350 {
351 Point32 center; GetCenter(rc, center);
352 Point32 old_center = center;
353 DeskewRel( center, skew1024, pt );
354 center -= old_center; // diff
355 rc += center;
356 return rc;
357 }
358
359 inline Rect16& DeskewCenterRel( Rect16& rc, int32_t skew1024, Point16& pt)
360 {
361 Point16 center; GetCenter(rc, center);
362 Point16 old_center = center;
363 DeskewRel( center, skew1024, pt );
364 center -= old_center; // diff
365 rc += center;
366 return rc;
367 }
368
369 inline Rect16& Expand( Rect16& rc, int16_t delta )
370 {
371 rc.left -= delta; rc.top -= delta;
372 rc.right+= delta; rc.bottom+= delta;
373 return rc;
374 }
375
376 inline Rect32& Expand( Rect32& rc, int32_t delta )
377 {
378 rc.left -= delta; rc.top -= delta;
379 rc.right+= delta; rc.bottom+= delta;
380 return rc;
381 }
382
383 // make points: lt & rb (main diag) or rt & lb (other)
384 inline void GetDiag1( Rect32& rc, Point32& lt, Point32& rb )
385 { lt.x = rc.left; lt.y = rc.top; rb.x = rc.right;rb.y = rc.bottom; }
386 inline void GetDiag1( Rect16& rc, Point16& lt, Point16& rb )
387 { lt.x = rc.left; lt.y = rc.top; rb.x = rc.right;rb.y = rc.bottom; }
388 inline void GetDiag2( Rect32& rc, Point32& rt, Point32& lb )
389 { rt.x = rc.right; rt.y = rc.top; lb.x = rc.left;lb.y = rc.bottom; }
390 inline void GetDiag2( Rect16& rc, Point16& rt, Point16& lb )
391 { rt.x = rc.right; rt.y = rc.top; lb.x = rc.left;lb.y = rc.bottom; }
392
393 inline Rect32& GetBounding( Rect32& rc_src, Rect32& rc_dest, int32_t skew1024 )
394 // dest rect can be the same as source
395 {
396 Point32 lt, rb; GetDiag1(rc_src, lt, rb);
397 Deskew(lt, skew1024); Deskew(rb, skew1024);
398 Point32 rt, lb; GetDiag2(rc_src, rt, lb);
399 Deskew(rt, skew1024); Deskew(lb, skew1024);
400 if (skew1024 < 0)
401 {
402 rc_dest.left = lt.x;
403 rc_dest.right = rb.x;
404 rc_dest.top = rt.y;
405 rc_dest.bottom= lb.y;
406 }
407 else
408 {
409 rc_dest.left = lb.x;
410 rc_dest.right = rt.x;
411 rc_dest.top = lt.y;
412 rc_dest.bottom= rb.y;
413 };
414 return rc_dest;
415 }
416
417 inline Rect16& GetBounding( Rect16& rc_src, Rect16& rc_dest, int32_t skew1024 )
418 // dest rect can be the same as source
419 {
420 Point16 lt, rb; GetDiag1(rc_src, lt, rb);
421 Deskew(lt, skew1024); Deskew(rb, skew1024);
422 Point16 rt, lb; GetDiag2(rc_src, rt, lb);
423 Deskew(rt, skew1024); Deskew(lb, skew1024);
424 if (skew1024 < 0)
425 {
426 rc_dest.left = lt.x;
427 rc_dest.right = rb.x;
428 rc_dest.top = rt.y;
429 rc_dest.bottom= lb.y;
430 }
431 else
432 {
433 rc_dest.left = lb.x;
434 rc_dest.right = rt.x;
435 rc_dest.top = lt.y;
436 rc_dest.bottom= rb.y;
437 };
438 return rc_dest;
439 }
440 //////////////////////////////////////////////////////////
441 // inequality
442 #define RC_NOTEQ_RC { return r1.left != r2.left || r1.top != r2.top \
443 || r1.right != r2.right || r1.bottom!= r2.bottom; }
444
445 inline Bool operator != ( const Rect16& r1, const Rect16& r2) RC_NOTEQ_RC
446 inline Bool operator != ( const Rect16& r1, const Rect32& r2) RC_NOTEQ_RC
447 inline Bool operator != ( const Rect32& r1, const Rect16& r2) RC_NOTEQ_RC
448 inline Bool operator != ( const Rect32& r1, const Rect32& r2) RC_NOTEQ_RC
449
450 #define PT_NOTEQ_PT { return pt1.x != pt2.x || pt1.y != pt2.y; }
451
452 inline Bool operator != ( const Point16& pt1, const Point16& pt2) PT_NOTEQ_PT
453 inline Bool operator != ( const Point16& pt1, const Point32& pt2) PT_NOTEQ_PT
454 inline Bool operator != ( const Point32& pt1, const Point16& pt2) PT_NOTEQ_PT
455 inline Bool operator != ( const Point32& pt1, const Point32& pt2) PT_NOTEQ_PT
456
457 ///////////////////////////////////////////////////////////////
458 // 22.03.97 17:48, V.P
459 inline Bool operator !(const Rect16 & r) { return (r.left > r.right)||(r.top > r.bottom); }
460 inline Bool operator !(const Rect32 & r) { return (r.left > r.right)||(r.top > r.bottom); }
461 inline Bool Not(const Rect16 & r) { return (r.left > r.right)||(r.top > r.bottom); }
462 inline Bool Not(const Rect32 & r) { return (r.left > r.right)||(r.top > r.bottom); }
463
464 #define SetMax( a, b ) { if ((a) < (b)) (a) = (b); }
465 #define SetMin( a, b ) { if ((a) > (b)) (a) = (b); }
466
467 inline Rect32& operator |=(Rect32& rc, const Rect32& r)
468 { SetMin( rc.left, r.left ); SetMin( rc.top , r.top );
469 SetMax( rc.right, r.right); SetMax( rc.bottom, r.bottom );
470 return rc;
471 }
472 inline Rect16& operator |=(Rect16& rc, const Rect16& r)
473 { SetMin( rc.left, r.left ); SetMin( rc.top , r.top );
474 SetMax( rc.right, r.right); SetMax( rc.bottom, r.bottom );
475 return rc;
476 }
477
478 inline Rect32& operator &=(Rect32& rc, const Rect32& r)
479 { SetMax( rc.left, r.left ); SetMax( rc.top , r.top );
480 SetMin( rc.right, r.right); SetMin( rc.bottom, r.bottom );
481 return rc;
482 }
483 inline Rect16& operator &=(Rect16& rc, const Rect16& r)
484 { SetMax( rc.left, r.left ); SetMax( rc.top , r.top );
485 SetMin( rc.right, r.right); SetMin( rc.bottom, r.bottom );
486 return rc;
487 }
488
489 inline Rect16& Set( Rect16& r, int left, int top, int right, int bottom )
490 { r.left=left; r.top=top; r.right=right; r.bottom=bottom; return r; }
491 inline Rect32& Set( Rect32& r, int left, int top, int right, int bottom )
492 { r.left=left; r.top=top; r.right=right; r.bottom=bottom; return r; }
493 inline Rect16& Check( Rect16& r )
494 {
495 if (r.left>r.right) {int x=r.left; r.left=r.right; r.right=x; };
496 if (r.top>r.bottom) {int x=r.top; r.top=r.bottom; r.bottom=x; }
497 return r;
498 }
499 inline Rect32& Check( Rect32& r )
500 {
501 if (r.left>r.right) {int x=r.left; r.left=r.right; r.right=x; };
502 if (r.top>r.bottom) {int x=r.top; r.top=r.bottom; r.bottom=x; }
503 return r;
504 }
505
506 inline Point16& Set( Point16& p, int x, int y ){ p.x=x; p.y=y; return p; }
507 inline Point32& Set( Point32& p, int x, int y ){ p.x=x; p.y=y; return p; }
508
509 inline int width( const Rect16& rc ) { return rc.right-rc.left+1; }
510 inline int width( const Rect32& rc ) { return rc.right-rc.left+1; }
511
512 inline int height( const Rect16& rc ) { return rc.bottom-rc.top+1; }
513 inline int height( const Rect32& rc ) { return rc.bottom-rc.top+1; }
514
515 inline Bool Overlap( const Rect16& r1, const Rect16& r2 )
516 { return !( (r1.left > r2.right)||(r1.top > r2.bottom) ||
517 (r2.left > r1.right)||(r2.top > r1.bottom)
518 );
519 }
520 inline Bool Overlap( const Rect32& r1, const Rect32& r2 )
521 { return !( (r1.left > r2.right)||(r1.top > r2.bottom) ||
522 (r2.left > r1.right)||(r2.top > r1.bottom)
523 );
524 }
525
526 inline Bool Inside( const Rect16& r, const Point16 & p)
527 { return !( (p.x < r.left)||(p.x > r.right )||
528 (p.y < r.top) ||(p.y > r.bottom)
529 );
530 }
531 inline Bool Inside( const Rect32& r, const Point32 & p)
532 { return !( (p.x < r.left)||(p.x > r.right )||
533 (p.y < r.top) ||(p.y > r.bottom)
534 );
535 }
536
537 inline Bool Overlap( int a1, int a2, int b1, int b2 ) // two ranges intersection
538 { // assumed that a1 <= a2; b1 <= b2
539 return !( (a2 < b1) || (b2 < a1) );
540 }
541
542 #endif
543
544 #endif // __cplusplus