My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
template <class T> struct Point_;
template <class T> struct Size_;
template <class T> struct Rect_;

template <class T>
struct Size_ : Moveable< Size_<T> > {
T cx, cy;

void Clear() { cx = cy = 0; }
bool IsEmpty() const { return cx == 0 || cy == 0; }

void SetNull() { cx = cy = Null; }
bool IsNullInstance() const { return UPP::IsNull(cx); }

Size_& operator+=(Size_ p) { cx += p.cx; cy += p.cy; return *this; }
Size_& operator+=(T t) { cx += t; cy += t; return *this; }
Size_& operator-=(Size_ p) { cx -= p.cx; cy -= p.cy; return *this; }
Size_& operator-=(T t) { cx -= t; cy -= t; return *this; }
Size_& operator*=(Size_ p) { cx *= p.cx; cy *= p.cy; return *this; }
Size_& operator*=(T t) { cx *= t; cy *= t; return *this; }
Size_& operator/=(Size_ p) { cx /= p.cx; cy /= p.cy; return *this; }
Size_& operator/=(T t) { cx /= t; cy /= t; return *this; }
Size_& operator<<=(int sh) { cx <<= sh; cy <<= sh; return *this; }
Size_& operator>>=(int sh) { cx >>= sh; cy >>= sh; return *this; }

Size_& operator++() { ++cx; ++cy; return *this; }
Size_& operator--() { --cx; --cy; return *this; }

friend Size_ operator+(Size_ s) { return s; }
friend Size_ operator-(Size_ s) { return Size_(-s.cx, -s.cy); }

friend Size_ operator+(Size_ a, Size_ b) { return a += b; }
friend Size_ operator+(Size_ a, T t) { return a += t; }
friend Size_ operator+(T t, Size_ b) { return b += t; }
friend Size_ operator-(Size_ a, Size_ b) { return a -= b; }
friend Size_ operator-(Size_ a, T t) { return a -= t; }
friend Size_ operator-(T t, Size_ b) { b = -b; return b += t; }
friend Size_ operator*(Size_ a, Size_ b) { return a *= b; }
friend Size_ operator*(Size_ a, T b) { return a *= b; }
friend Size_ operator*(T a, Size_ b) { return b *= a; }
friend Size_ operator/(Size_ a, Size_ b) { return a /= b; }
friend Size_ operator/(Size_ a, T b) { return a /= b; }
friend Size_ operator<<(Size_ a, int sh) { return a <<= sh; }
friend Size_ operator>>(Size_ a, int sh) { return a >>= sh; }

friend bool operator==(Size_ a, Size_ b) { return a.cx == b.cx && a.cy == b.cy; }
friend bool operator!=(Size_ a, Size_ b) { return !(a == b); }

friend Size_ min(Size_ a, Size_ b) { return Size_(min(a.cx, b.cx), min(a.cy, b.cy)); }
friend Size_ max(Size_ a, Size_ b) { return Size_(max(a.cx, b.cx), max(a.cy, b.cy)); }

friend Size_ Nvl(Size_ a, Size_ b) { return IsNull(a) ? b : a; }

friend T ScalarProduct(Size_ a, Size_ b) { return a.cx * b.cx + a.cy * b.cy; }
friend T VectorProduct(Size_ a, Size_ b) { return a.cx * b.cy - a.cy * b.cx; }
friend T Squared(Size_ a) { return a.cx * a.cx + a.cy * a.cy; }
friend double Length(Size_ a) { return hypot(a.cx, a.cy); }

unsigned GetHashValue() const { return CombineHash(cx, cy); }

String ToString() const;

Size_() {}
Size_(T cx, T cy) : cx(cx), cy(cy) {}

Size_(const Size_<int>& sz) : cx((T)sz.cx), cy((T)sz.cy) {}
Size_(const Size_<short>& sz) : cx((T)sz.cx), cy((T)sz.cy) {}
Size_(const Size_<double>& sz) : cx((T)sz.cx), cy((T)sz.cy) {}
Size_(const Size_<int64>& sz) : cx((T)sz.cx), cy((T)sz.cy) {}

Size_(const Point_<T>& pt) : cx(pt.x), cy(pt.y) {}

Size_(const Nuller&) { cx = cy = Null; }

#ifdef SVO_VALUE
operator Value() const { return FitsSvoValue<Size_>() ? SvoToValue(*this) : RichToValue(*this); }
Size_(const Value& src) { *this = src.Get<Size_>(); }
#else
operator Value() const { return RichValue<Size_>(*this); }
Size_(const Value& src) { *this = RichValue<Size_>::Extract(src); }
#endif

void Serialize(Stream& s) { s % cx % cy; }
void Jsonize(JsonIO& jio) { jio("cx", cx)("cy", cy); }
void Xmlize(XmlIO& xio) { xio.Attr("cx", cx).Attr("cy", cy); }

#ifdef PLATFORM_WIN32
operator SIZE*() { ASSERT(sizeof(*this) == sizeof(SIZE)); return (SIZE*)this; }
operator const SIZE*() const { ASSERT(sizeof(*this) == sizeof(SIZE)); return (SIZE*)this; }
operator SIZE() const { SIZE sz; sz.cx = cx; sz.cy = cy; return sz; }
LONG GetLONG() const { return MAKELONG(cx, cy); }

Size_(POINT pt) : cx((T)pt.x), cy((T)pt.y) {}
Size_(SIZE sz) : cx((T)sz.cx), cy((T)sz.cy) {}
explicit Size_(LONG lParam) { cx = (T)(int16)LOWORD(lParam); cy = (T)(int16)HIWORD(lParam); }
#endif
};

template <class T>
String Size_<T>::ToString() const {
String ss;
return ss << '(' << cx << ", " << cy << ')';
}

template <class T>
struct Point_ : Moveable< Point_<T> > {
T x, y;

typedef Size_<T> Sz;

void Clear() { x = y = 0; }
bool IsZero() const { return x == 0 && y == 0; }

void SetNull() { x = y = Null; }
bool IsNullInstance() const { return UPP::IsNull(x); }

void Offset(T dx, T dy) { x += dx; y += dy; }

Point_& operator+=(Sz p) { x += p.cx; y += p.cy; return *this; }
Point_& operator+=(Point_ p) { x += p.x; y += p.y; return *this; }
Point_& operator+=(T t) { x += t; y += t; return *this; }
Point_& operator-=(Sz p) { x -= p.cx; y -= p.cy; return *this; }
Point_& operator-=(Point_ p) { x -= p.x; y -= p.y; return *this; }
Point_& operator-=(T t) { x -= t; y -= t; return *this; }
Point_& operator*=(Sz p) { x *= p.cx; y *= p.cy; return *this; }
Point_& operator*=(Point_ p) { x *= p.x; y *= p.y; return *this; }
Point_& operator*=(T t) { x *= t; y *= t; return *this; }
Point_& operator/=(Sz p) { x /= p.cx; y /= p.cy; return *this; }
Point_& operator/=(Point_ p) { x /= p.x; y /= p.y; return *this; }
Point_& operator/=(T t) { x /= t; y /= t; return *this; }
Point_& operator<<=(int sh) { x <<= sh; y <<= sh; return *this; }
Point_& operator>>=(int sh) { x >>= sh; y >>= sh; return *this; }

Point_& operator++() { ++x; ++y; return *this; }
Point_& operator--() { --x; --y; return *this; }

friend Point_ operator+(Point_ p) { return p; }
friend Point_ operator-(Point_ p) { return Point_(-p.x, -p.y); }

friend Point_ operator+(Point_ a, Sz b) { return a += b; }
friend Point_ operator+(Point_ a, Point_ b) { return a += b; }
friend Point_ operator+(Point_ a, T t) { return a += t; }
friend Point_ operator+(T t, Point_ b) { return b += t; }
friend Sz operator+(Sz a, Point_ b) { return Point_(a) + b; }
friend Sz& operator+=(Sz& a, Point_ b) { return a = a + b; }
friend Point_ operator-(Point_ a, Sz b) { return a -= b; }
friend Point_ operator-(Point_ a, T t) { return a -= t; }
friend Sz operator-(Point_ a, Point_ b) { return a -= b; }
friend Sz operator-(Sz a, Point_ b) { return Point_(a) - b; }
friend Sz& operator-=(Sz& a, Point_ b) { return a = a - b; }
friend Point_ operator*(Point_ a, Point_ b) { return a *= b; }
friend Point_ operator*(Point_ a, T b) { return a *= b; }
friend Point_ operator*(T a, Point_ b) { return b *= a; }
friend Point_ operator/(Point_ a, Sz b) { return a /= b; }
friend Point_ operator/(Point_ a, T b) { return a /= b; }
friend Point_ operator<<(Point_ a, int sh) { return a <<= sh; }
friend Point_ operator>>(Point_ a, int sh) { return a >>= sh; }


friend bool operator==(Point_ a, Point_ b) { return a.x == b.x && a.y == b.y; }
friend bool operator!=(Point_ a, Point_ b) { return a.x != b.x || a.y != b.y; }

friend Point_ min(Point_ a, Point_ b) { return Point_(min(a.x, b.x), min(a.y, b.y)); }
friend Point_ max(Point_ a, Point_ b) { return Point_(max(a.x, b.x), max(a.y, b.y)); }

friend Point_ Nvl(Point_ a, Point_ b) { return IsNull(a) ? b : a; }

unsigned GetHashValue() const { return CombineHash(x, y); }

String ToString() const;

Point_() {}
Point_(T x, T y) : x(x), y(y) {}

Point_(const Point_<int>& pt) : x((T)pt.x), y((T)pt.y) {}
Point_(const Point_<short>& pt) : x((T)pt.x), y((T)pt.y) {}
Point_(const Point_<double>& pt) : x((T)pt.x), y((T)pt.y) {}
Point_(const Point_<int64>& pt) : x((T)pt.x), y((T)pt.y) {}

Point_(const Size_<T>& sz) : x(sz.cx), y(sz.cy) {}

Point_(const Nuller&) { x = y = Null; }

#ifdef SVO_VALUE
operator Value() const { return FitsSvoValue<Point_>() ? SvoToValue(*this) : RichToValue(*this); }
Point_(const Value& src) { *this = src.Get<Point_>(); }
#else
operator Value() const { return RichValue<Point_>(*this); }
Point_(const Value& src) { *this = RichValue<Point_>::Extract(src); }
#endif

void Serialize(Stream& s) { s % x % y; }
void Jsonize(JsonIO& jio) { jio("x", x)("y", y); }
void Xmlize(XmlIO& xio) { xio.Attr("x", x).Attr("y", y); }

#ifdef PLATFORM_WIN32
operator POINT*() { ASSERT(sizeof(*this) == sizeof(POINT)); return (POINT*)this; }
operator const POINT*() const { ASSERT(sizeof(*this) == sizeof(POINT)); return (POINT*)this; }
operator POINT() const { POINT p; p.x = x; p.y = y; return p; }
LONG GetLONG() const { return MAKELONG(x, y); }

Point_(POINT pt) : x((T)pt.x), y((T)pt.y) {}
Point_(SIZE sz) : x((T)sz.cx), y((T)sz.cy) {}
explicit Point_(LONG lParam) { x = (T)(int16)LOWORD(lParam); y = (T)(int16)HIWORD(lParam); }
#endif
};

template <class T>
String Point_<T>::ToString() const {
String ss;
return ss << '[' << x << ", " << y << ']';
}

template <class T>
T GHalf_(T t) { return t >> 1; }

template <>
inline double GHalf_(double d) { return d / 2; }

template <class T>
struct Rect_ : Moveable< Rect_<T> > {
T left, top, right, bottom;

typedef Point_<T> Pt;
typedef Size_<T> Sz;

void Clear() { left = top = right = bottom = 0; }

bool IsEmpty() const { return right <= left || bottom <= top; }
void SetNull();
bool IsNullInstance() const;

Pt TopLeft() const { return Pt(left, top); }
Pt TopCenter() const { return Pt(GHalf_(left + right), top); }
Pt TopRight() const { return Pt(right, top); }
Pt CenterLeft() const { return Pt(left, GHalf_(top + bottom)); }
Pt CenterPoint() const { return Pt(GHalf_(left + right), GHalf_(top + bottom)); }
Pt CenterRight() const { return Pt(right, GHalf_(top + bottom)); }
Pt BottomLeft() const { return Pt(left, bottom); }
Pt BottomCenter() const { return Pt(GHalf_(left + right), bottom); }
Pt BottomRight() const { return Pt(right, bottom); }
T Width() const { return right - left; }
T Height() const { return bottom - top; }
Sz Size() const { return Sz(right - left, bottom - top); }

T GetWidth() const { return right - left; }
T GetHeight() const { return bottom - top; }
Sz GetSize() const { return Sz(right - left, bottom - top); }

Pt CenterPos(T cx, T cy) const;
Pt CenterPos(Sz sz) const { return CenterPos(sz.cx, sz.cy); }
Rect_ CenterRect(Sz sz) const { return Rect_(CenterPos(sz), sz); }
Rect_ CenterRect(T cx, T cy) const { return CenterRect(Sz(cx, cy)); }

void Set(T l, T t, T r, T b) { left = l; top = t; right = r; bottom = b; }
void Set(Pt a, Pt b) { left = a.x; top = a.y; right = b.x; bottom = b.y; }
void Set(Pt a, Sz sz) { Set(a, a + sz); }
void Set(const Rect_& r) { Set(r.left, r.top, r.right, r.bottom); }

void SetSize(int cx, int cy) { right = left + cx; bottom = top + cy; }
void SetSize(Sz sz) { SetSize(sz.cx, sz.cy); }

void InflateHorz(T dx) { left -= dx; right += dx; }
void InflateVert(T dy) { top -= dy; bottom += dy; }
void Inflate(T dx, T dy) { InflateHorz(dx); InflateVert(dy); }
void Inflate(Sz sz) { Inflate(sz.cx, sz.cy); }
void Inflate(T dxy) { Inflate(dxy, dxy); }
void Inflate(T l, T t, T r, T b) { left -= l; top -= t; right += r; bottom += b; }
void Inflate(const Rect_& r) { Inflate(r.left, r.top, r.right, r.bottom); }

void DeflateHorz(T dx) { InflateHorz(-dx); }
void DeflateVert(T dy) { InflateVert(-dy); }
void Deflate(T dx, T dy) { Inflate(-dx, -dy); }
void Deflate(Sz sz) { Inflate(-sz); }
void Deflate(T dxy) { Inflate(-dxy); }
void Deflate(T l, T t, T r, T b) { Inflate(-l, -t, -r, -b); }
void Deflate(const Rect_& r) { Deflate(r.left, r.top, r.right, r.bottom); }

Rect_ InflatedHorz(T dx) const { Rect_ r = *this; r.InflateHorz(dx); return r; }
Rect_ InflatedVert(T dy) const { Rect_ r = *this; r.InflateVert(dy); return r; }
Rect_ Inflated(T dx, T dy) const { Rect_ r = *this; r.Inflate(dx, dy); return r; }
Rect_ Inflated(Sz sz) const { Rect_ r = *this; r.Inflate(sz); return r; }
Rect_ Inflated(T dxy) const { Rect_ r = *this; r.Inflate(dxy); return r; }
Rect_ Inflated(T l, T t, T r, T b) const { Rect_ m = *this; m.Inflate(l, t, r, b); return m; }
Rect_ Inflated(const Rect_& q) const { Rect_ r = *this; r.Inflate(q); return r; }

Rect_ DeflatedHorz(T dx) const { Rect_ r = *this; r.DeflateHorz(dx); return r; }
Rect_ DeflatedVert(T dy) const { Rect_ r = *this; r.DeflateVert(dy); return r; }
Rect_ Deflated(T dx, T dy) const { Rect_ r = *this; r.Deflate(dx, dy); return r; }
Rect_ Deflated(Sz sz) const { Rect_ r = *this; r.Deflate(sz); return r; }
Rect_ Deflated(T dxy) const { Rect_ r = *this; r.Deflate(dxy); return r; }
Rect_ Deflated(T l, T t, T r, T b) const { Rect_ m = *this; m.Deflate(l, t, r, b); return m; }
Rect_ Deflated(const Rect_& q) const { Rect_ r = *this; r.Deflate(q); return r; }

void OffsetHorz(T dx) { left += dx; right += dx; }
void OffsetVert(T dy) { top += dy; bottom += dy; }
void Offset(T dx, T dy) { OffsetHorz(dx); OffsetVert(dy); }
void Offset(Sz sz) { Offset(sz.cx, sz.cy); }
void Offset(Pt p) { Offset(p.x, p.y); }

Rect_ OffsetedHorz(T dx) const { Rect_ r = *this; r.OffsetHorz(dx); return r; }
Rect_ OffsetedVert(T dy) const { Rect_ r = *this; r.OffsetVert(dy); return r; }
Rect_ Offseted(T dx, T dy) const { Rect_ r = *this; r.Offset(dx, dy); return r; }
Rect_ Offseted(Sz sz) const { Rect_ r = *this; r.Offset(sz); return r; }
Rect_ Offseted(Pt p) const { Rect_ r = *this; r.Offset(p); return r; }

void Normalize();
Rect_ Normalized() const { Rect_ r = *this; r.Normalize(); return r; }

void Union(Pt p);
void Union(const Rect_& rc);
void Intersect(const Rect_& rc);

bool Contains(T x, T y) const;
bool Contains(Pt p) const { return Contains(p.x, p.y); }
bool Contains(const Rect_& rc) const;
bool Intersects(const Rect_& rc) const;

Pt Bind(Pt pt) const;

Rect_& operator+=(Sz sz) { Offset(sz); return *this; }
Rect_& operator+=(Pt p) { Offset(p); return *this; }
Rect_& operator+=(const Rect_& b);
Rect_& operator-=(Sz sz) { Offset(-sz); return *this; }
Rect_& operator-=(Pt p) { Offset(-p); return *this; }
Rect_& operator-=(const Rect_& b);

Rect_& operator|=(Pt p) { Union(p); return *this; }
Rect_& operator|=(const Rect_& rc) { Union(rc); return *this; }
Rect_& operator&=(const Rect_& rc) { Intersect(rc); return *this; }

bool operator==(const Rect_& b) const;
bool operator!=(const Rect_& b) const { return !operator==(b); }

friend Rect_ operator+(Rect_ a, Sz b) { return a += b; }
friend Rect_ operator+(Sz a, Rect_ b) { return b += a; }
friend Rect_ operator+(Rect_ a, Pt b) { return a += b; }
friend Rect_ operator+(Pt a, Rect_ b) { return b += a; }
friend Rect_ operator+(Rect_ a, const Rect_& b) { return a += b; }
friend Rect_ operator-(Rect_ a, Sz b) { return a -= b; }
friend Rect_ operator-(Rect_ a, Pt b) { return a -= b; }
friend Rect_ operator-(Rect_ a, const Rect_& b) { return a -= b; }
friend Rect_ operator|(Rect_ a, Rect_ b) { a.Union(b); return a; }
friend Rect_ operator&(Rect_ a, Rect_ b) { a.Intersect(b); return a; }
friend bool operator&&(const Rect_& a, const Rect_& b) { return a.Intersects(b); }
friend bool operator>=(const Rect_& a, Pt b) { return a.Contains(b); }
friend bool operator<=(Pt a, const Rect_& b) { return b.Contains(a); }
friend bool operator<=(const Rect_& a, const Rect_& b) { return b.Contains(a); }
friend bool operator>=(const Rect_& b, const Rect_& a) { return a.Contains(b); }

friend const Rect_& Nvl(const Rect_& a, const Rect_& b) { return IsNull(a) ? b : a; }

unsigned GetHashValue() const { return CombineHash(left, top, right, bottom); }

String ToString() const;

Rect_() {}
Rect_(T l, T t, T r, T b) { Set(l, t, r, b); }
Rect_(Pt a, Pt b) { Set(a, b); }
Rect_(Pt a, Sz sz) { Set(a, sz); }
Rect_(Sz sz) { Set(0, 0, sz.cx, sz.cy); }

Rect_(const Rect_<int>& r) { Set((T)r.left, (T)r.top, (T)r.right, (T)r.bottom); }
Rect_(const Rect_<short>& r) { Set((T)r.left, (T)r.top, (T)r.right, (T)r.bottom); }
Rect_(const Rect_<double>& r) { Set((T)r.left, (T)r.top, (T)r.right, (T)r.bottom); }
Rect_(const Rect_<int64>& r) { Set((T)r.left, (T)r.top, (T)r.right, (T)r.bottom); }

Rect_(const Nuller&) { SetNull(); }

operator Value() const { return RichValue<Rect_>(*this); }
/*explicit */Rect_(const Value& src) { *this = RichValue<Rect_>::Extract(src); }

void Serialize(Stream& s) { s % left % top % right % bottom; }
void Jsonize(JsonIO& jio) { jio("left", left)("top", top)("right", right)("bottom", bottom); }
void Xmlize(XmlIO& xio) { xio.Attr("left", left).Attr("top", top).Attr("right", right).Attr("bottom", bottom); }

#ifdef PLATFORM_WIN32
operator const RECT*() const { ASSERT(sizeof(*this) == sizeof(RECT)); return (RECT*)this; }
operator RECT*() { ASSERT(sizeof(*this) == sizeof(RECT)); return (RECT*)this; }
operator RECT&() { ASSERT(sizeof(*this) == sizeof(RECT)); return *(RECT*)this; }
operator RECT() const { RECT r; r.top = top; r.bottom = bottom;
r.left = left; r.right = right; return r; }
Rect_(const RECT& rc) { Set((T)rc.left, (T)rc.top, (T)rc.right, (T)rc.bottom); }
#endif
};

template <class T>
inline void Rect_<T>::SetNull()
{
left = right = top = bottom = Null;
}

template <>
inline void Rect_<double>::SetNull()
{
left = top = 0;
right = bottom = -1;
}

template <class T>
bool Rect_<T>::IsNullInstance() const {
return IsNull(left);
}

template <>
inline bool Rect_<double>::IsNullInstance() const {
return left > right || top > bottom;
}

template <class T>
Point_<T> Rect_<T>::CenterPos(T cx, T cy) const {
return Point_<T>(left + GHalf_(Width() - cx), top + GHalf_(Height() - cy));
}

template <class T>
void Rect_<T>::Normalize() {
if(left > right) Swap(left, right);
if(top > bottom) Swap(top, bottom);
}

template <class T>
void Rect_<T>::Union(Pt p) {
if(IsNull(p)) return;
if(IsNullInstance()) {
right = 1 + (left = p.x);
bottom = 1 + (top = p.y);
}
else
{
if(p.x >= right) right = p.x + 1;
else if(p.x < left) left = p.x;
if(p.y >= bottom) bottom = p.y + 1;
else if(p.y < top) top = p.y;
}
}

template <>
inline void Rect_<double>::Union(Point_<double> p) {
if(IsNull(p)) return;
if(IsNullInstance())
{
left = right = p.x;
top = bottom = p.y;
}
else
{
if(p.x < left) left = p.x;
else if(p.x > right) right = p.x;
if(p.y < top) top = p.y;
else if(p.y > bottom) bottom = p.y;
}
}

template <class T>
void Rect_<T>::Union(const Rect_<T>& r) {
if(IsNull(r)) return;
if(IsNullInstance()) {
Set(r);
return;
}
if(r.left < left) left = r.left;
if(r.top < top) top = r.top;
if(r.right > right) right = r.right;
if(r.bottom > bottom) bottom = r.bottom;
}

void Rect_double_Union(Rect_<double>& self, const Rect_<double>& r);

template <>
inline void Rect_<double>::Union(const Rect_<double>& r) {
Rect_double_Union(*this, r);
}

template <class T>
void Rect_<T>::Intersect(const Rect_<T>& r) {
if(r.left > left) left = r.left;
if(r.top > top) top = r.top;
if(right < left) right = left;
if(r.right < right) right = r.right;
if(r.bottom < bottom) bottom = r.bottom;
if(bottom < top) bottom = top;
}

template <class T>
bool Rect_<T>::Contains(T x, T y) const {
return x >= left && x < right && y >= top && y < bottom;
}

template <>
inline bool Rect_<double>::Contains(double x, double y) const {
return x >= left && x <= right && y >= top && y <= bottom;
}

template <class T>
bool Rect_<T>::Contains(const Rect_<T>& r) const {
return r.left >= left && r.top >= top && r.right <= right && r.bottom <= bottom;
}

template <class T>
bool Rect_<T>::Intersects(const Rect_<T>& r) const {
if(IsEmpty() || r.IsEmpty()) return false;
return r.right > left && r.bottom > top && r.left < right && r.top < bottom;
}

bool Rect_double_Intersects(const Rect_<double>& self, const Rect_<double>& r);

template <>
inline bool Rect_<double>::Intersects(const Rect_<double>& r) const {
return Rect_double_Intersects(*this, r);
}

template <class T>
Point_<T> Rect_<T>::Bind(Point_<T> pt) const {
return Point_<T>(pt.x < left ? left : pt.x >= right ? right - 1 : pt.x,
pt.y < top ? top : pt.y >= bottom ? bottom - 1 : pt.y);
}

Point_<double> Rect_double_Bind(const Rect_<double>& self, Point_<double> pt);

template <>
inline Point_<double> Rect_<double>::Bind(Point_<double> pt) const {
return Rect_double_Bind(*this, pt);
}

template <class T>
Rect_<T>& Rect_<T>::operator-=(const Rect_<T>& b) {
left -= b.left;
top -= b.top;
right -= b.right;
bottom -= b.bottom;
return *this;
}

template <class T>
Rect_<T>& Rect_<T>::operator+=(const Rect_<T>& b) {
left += b.left;
top += b.top;
right += b.right;
bottom += b.bottom;
return *this;
}

template <class T>
bool Rect_<T>::operator==(const Rect_& b) const {
return top == b.top && bottom == b.bottom && left == b.left && right == b.right;
}

template <class T>
String Rect_<T>::ToString() const
{
String str;
return str << AsString(TopLeft()) << " - " << AsString(BottomRight())
<< " : " << AsString(Size());
}

typedef Size_<int> Size;
typedef Point_<int> Point;
typedef Rect_<int> Rect;

typedef Size_<int16> Size16;
typedef Point_<int16> Point16;
typedef Rect_<int16> Rect16;

typedef Size_<double> Sizef;
typedef Point_<double> Pointf;
typedef Rect_<double> Rectf;

typedef Size_<int64> Size64;
typedef Point_<int64> Point64;
typedef Rect_<int64> Rect64;

const int SIZE_V = 70;
const int SIZE16_V = 71;
const int SIZEF_V = 72;
const int SIZE64_V = 79;

template<> inline dword ValueTypeNo(const Size*) { return SIZE_V; }
template<> inline dword ValueTypeNo(const Size16*) { return SIZE16_V; }
template<> inline dword ValueTypeNo(const Size64*) { return SIZE64_V; }
template<> inline dword ValueTypeNo(const Sizef*) { return SIZEF_V; }

const int POINT_V = 73;
const int POINT16_V = 74;
const int POINTF_V = 75;
const int POINT64_V = 80;

template<> inline dword ValueTypeNo(const Point*) { return POINT_V; }
template<> inline dword ValueTypeNo(const Point16*) { return POINT16_V; }
template<> inline dword ValueTypeNo(const Point64*) { return POINT64_V; }
template<> inline dword ValueTypeNo(const Pointf*) { return POINTF_V; }

const int RECT_V = 76;
const int RECT16_V = 77;
const int RECTF_V = 78;
const int RECT64_V = 81;

template<> inline dword ValueTypeNo(const Rect*) { return RECT_V; }
template<> inline dword ValueTypeNo(const Rect16*) { return RECT16_V; }
template<> inline dword ValueTypeNo(const Rect64*) { return RECT64_V; }
template<> inline dword ValueTypeNo(const Rectf*) { return RECTF_V; }

Rect RectC(int x, int y, int cx, int cy);
Rect16 Rect16C(int16 x, int16 y, int16 cx, int16 cy);
Rectf RectfC(double x, double y, double cx, double cy);

inline Size& operator*=(Size& sz, double a)
{
sz.cx = int(sz.cx * a);
sz.cy = int(sz.cy * a);
return sz;
}

inline Size& operator/=(Size& sz, double a)
{
sz.cx = int(sz.cx / a);
sz.cy = int(sz.cy / a);
return sz;
}

inline Size& operator*=(Size& sz, Sizef a)
{
sz.cx = int(sz.cx * a.cx);
sz.cy = int(sz.cy * a.cy);
return sz;
}

inline Size& operator/=(Size& sz, Sizef a)
{
sz.cx = int(sz.cx / a.cx);
sz.cy = int(sz.cy / a.cy);
return sz;
}

inline Sizef operator*(Size sz, double a) { return Sizef(sz.cx * a, sz.cy * a); }
inline Sizef operator*(double a, Size sz) { return Sizef(sz.cx * a, sz.cy * a); }
inline Sizef operator/(Size sz, double a) { return Sizef(sz.cx / a, sz.cy / a); }
inline Sizef operator*(Size sz, Sizef a) { return Sizef(sz.cx * a.cx, sz.cy * a.cy); }
inline Sizef operator*(Sizef a, Size sz) { return Sizef(sz.cx * a.cx, sz.cy * a.cy); }
inline Sizef operator/(Size sz, Sizef a) { return Sizef(sz.cx / a.cx, sz.cy / a.cy); }

inline Size16& operator*=(Size16& sz, double a)
{
sz.cx = int16(sz.cx * a);
sz.cy = int16(sz.cy * a);
return sz;
}

inline Size16& operator/=(Size16& sz, double a)
{
sz.cx = int16(sz.cx / a);
sz.cy = int16(sz.cy / a);
return sz;
}

inline Size16& operator*=(Size16& sz, Sizef a)
{
sz.cx = int16(sz.cx * a.cx);
sz.cy = int16(sz.cy * a.cy);
return sz;
}

inline Size16& operator/=(Size16& sz, Sizef a)
{
sz.cx = int16(sz.cx / a.cx);
sz.cy = int16(sz.cy / a.cy);
return sz;
}

inline Sizef operator*(Size16 sz, double a) { return Sizef(sz.cx * a, sz.cy * a); }
inline Sizef operator*(double a, Size16 sz) { return Sizef(sz.cx * a, sz.cy * a); }
inline Sizef operator/(Size16 sz, double a) { return Sizef(sz.cx / a, sz.cy / a); }
inline Sizef operator*(Size16 sz, Sizef a) { return Sizef(sz.cx * a.cx, sz.cy * a.cy); }
inline Sizef operator*(Sizef a, Size16 sz) { return Sizef(sz.cx * a.cx, sz.cy * a.cy); }
inline Sizef operator/(Size16 sz, Sizef a) { return Sizef(sz.cx / a.cx, sz.cy / a.cy); }

inline Rect RectC(int x, int y, int cx, int cy) {
return Rect(x, y, x + cx, y + cy);
}

inline Rect16 Rect16C(int16 x, int16 y, int16 cx, int16 cy) {
return Rect16(x, y, x + cx, y + cy);
}

inline Rectf RectfC(double x, double y, double cx, double cy) {
return Rectf(x, y, x + cx, y + cy);
}

inline Rect RectSort(Point a, Point b) { return Rect(min(a, b), max(a, b) + 1); }
inline Rectf RectfSort(Pointf a, Pointf b) { return Rectf(min(a, b), max(a, b)); }

Stream& Pack16(Stream& s, Point& p);
Stream& Pack16(Stream& s, Size& sz);
Stream& Pack16(Stream& s, Rect& r);

Size iscale(Size a, int b, int c);
Size iscalefloor(Size a, int b, int c);
Size iscaleceil(Size a, int b, int c);
Size idivfloor(Size a, int b);
Size idivceil(Size a, int b);
Size iscale(Size a, Size b, Size c);
Size iscalefloor(Size a, Size b, Size c);
Size iscaleceil(Size a, Size b, Size c);
Size idivfloor(Size a, Size b);
Size idivceil(Size a, Size b);

enum Alignment {
ALIGN_NULL,
ALIGN_LEFT,
ALIGN_TOP = ALIGN_LEFT,
ALIGN_RIGHT,
ALIGN_BOTTOM = ALIGN_RIGHT,
ALIGN_CENTER,
ALIGN_JUSTIFY,
};

Size GetRatioSize(Size stdsize, int cx, int cy);
Size GetFitSize(Size objsize, int cx, int cy);
inline Size GetFitSize(Size objsize, Size intosize) { return GetFitSize(objsize, intosize.cx, intosize.cy); }

Pointf Mid(const Pointf& a, const Pointf& b);
Pointf Orthogonal(const Pointf& p);
double Squared(const Pointf& p);
double Length(const Pointf& p);
double Bearing(const Pointf& p);
double Distance(const Pointf& p1, const Pointf& p2);
double SquaredDistance(const Pointf& p1, const Pointf& p2);
Pointf Polar(double a);
Pointf Polar(const Pointf& p, double r, double a);

#ifndef SVO_VALUE
template<> void Xmlize(XmlIO& xml, Point& p);
template<> void Xmlize(XmlIO& xml, Point16& p);
template<> void Xmlize(XmlIO& xml, Point64& p);
template<> void Xmlize(XmlIO& xml, Pointf& p);

template<> void Xmlize(XmlIO& xml, Size& sz);
template<> void Xmlize(XmlIO& xml, Size16& sz);
template<> void Xmlize(XmlIO& xml, Size64& sz);
template<> void Xmlize(XmlIO& xml, Sizef& sz);

template<> void Xmlize(XmlIO& xml, Rect& r);
template<> void Xmlize(XmlIO& xml, Rect16& r);
template<> void Xmlize(XmlIO& xml, Rect64& r);
template<> void Xmlize(XmlIO& xml, Rectf& r);
#endif

Change log

r4675 by cxl on Mar 10, 2012   Diff
Core: Value xmlize GCC fixes
Go to: 
Project members, sign in to write a code review

Older revisions

r4674 by cxl on Mar 10, 2012   Diff
Core: some Xmlization moved to rich
Value types
r4647 by cxl on Mar 3, 2012   Diff
.developing SvoValue
r4495 by cxl on Jan 30, 2012   Diff
Core: new Value reintegrated for
conditional compilation (SVO_VALUE
flag)
All revisions of this file

File info

Size: 30496 bytes, 745 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting