Iridescence 1.00
Embedded Graphic Framework
Loading...
Searching...
No Matches
ds_geometry.h
1/* Copyright (C) 2017 - 2024, Thornwave Labs Inc - All Rights Reserved.
2 * Unauthorized copying of this file, via any medium is strictly prohibited.
3 * Proprietary and confidential.
4 * Written by Razvan Turiac <razvan.turiac@thornwave.com>
5*/
6
7#ifndef _DS_GEOMETRY_H
8#define _DS_GEOMETRY_H
9
10
11#include <stdint.h>
12
13#include <ds_math.h>
14#include <ds_types.h>
15
16
17class DsFPoint;
18class DsSurface;
19
24{
25public:
29 DsPoint(): x(0), y(0)
30 {
31 }
32
33
40 DsPoint(int32_t x, int32_t y): x(x), y(y)
41 {
42 }
43
44
51
52
56 void swap(void)
57 {
58 const int32_t t = x;
59 x = y;
60 y = t;
61 }
62
63
69 bool operator==(const DsPoint &rhs)
70 {
71 return (x == rhs.x) && (y == rhs.y);
72 }
73
74
81 {
82 DsPoint rv;
83
84 rv.x = -x;
85 rv.y = -y;
86
87 return rv;
88 }
89
90
99 friend DsPoint operator+(const DsPoint &lhs, const DsPoint &rhs)
100 {
101 DsPoint r(lhs.x + rhs.x, lhs.y + rhs.y);
102 return r;
103 }
104
105
114 friend DsPoint operator+(const DsPoint &lhs, int32_t rhs)
115 {
116 DsPoint r(lhs.x + rhs, lhs.y + rhs);
117 return r;
118 }
119
120
129 {
130 x += rhs.x;
131 y += rhs.y;
132
133 return *this;
134 }
135
136
144 DsPoint& operator+=(int32_t rhs)
145 {
146 x += rhs;
147 y += rhs;
148
149 return *this;
150 }
151
152
161 friend DsPoint operator-(const DsPoint &lhs, const DsPoint &rhs)
162 {
163 DsPoint r(lhs.x - rhs.x, lhs.y - rhs.y);
164 return r;
165 }
166
167
176 friend DsPoint operator-(const DsPoint &lhs, int32_t rhs)
177 {
178 DsPoint r(lhs.x - rhs, lhs.y - rhs);
179 return r;
180 }
181
182
191 {
192 x -= rhs.x;
193 y -= rhs.y;
194
195 return *this;
196 }
197
198
206 DsPoint& operator-=(int32_t rhs)
207 {
208 x -= rhs;
209 y -= rhs;
210
211 return *this;
212 }
213
214
223 friend DsPoint operator*(const DsPoint &lhs, int32_t multiplier)
224 {
225 DsPoint r(lhs.x * multiplier, lhs.y * multiplier);
226 return r;
227 }
228
229
238 friend DsPoint operator/(const DsPoint &lhs, int32_t divisor)
239 {
240 DsPoint r(lhs.x / divisor, lhs.y / divisor);
241 return r;
242 }
243
244
253 friend DsPoint operator/(const DsPoint &lhs, float divisor)
254 {
255 DsPoint r(round(lhs.x / divisor), round(lhs.y / divisor));
256 return r;
257 }
258
259
268 {
269 DsPoint rv = *this;
270
271 if (rv.x < min.x)
272 rv.x = min.x;
273
274 if (rv.y < min.y)
275 rv.y = min.y;
276
277 return rv;
278 }
279
280
289 {
290 DsPoint rv = *this;
291
292 if (rv.x > max.x)
293 rv.x = max.x;
294
295 if (rv.y > max.y)
296 rv.y = max.y;
297
298 return rv;
299 }
300
301
310 DsPoint saturate(const DsPoint &min, const DsPoint &max)
311 {
312 DsPoint rv = *this;
313
314 if (rv.x < min.x)
315 rv.x = min.x;
316 else if (rv.x > max.x)
317 rv.x = max.x;
318
319 if (rv.y < min.y)
320 rv.y = min.y;
321 else if (rv.y > max.y)
322 rv.y = max.y;
323
324 return rv;
325 }
326
327
335 float distance(const DsPoint &p) const
336 {
337 const int32_t dx = p.x - x;
338 const int32_t dy = p.y - y;
339
340 return sqrt(dx * dx + dy * dy);
341 }
342
343
351 float distanceX(const DsPoint &p) const
352 {
353 return abs(p.x - x);
354 }
355
356
364 float distanceY(const DsPoint &p) const
365 {
366 return abs(p.y - y);
367 }
368
369
378 friend float distance(const DsPoint &p1, const DsPoint& p2)
379 {
380 const int32_t dx = p1.x - p2.x;
381 const int32_t dy = p1.y - p2.y;
382
383 return sqrt(dx * dx + dy * dy);
384 }
385
386 int32_t x;
387 int32_t y;
388};
389
390
391
392
397{
398public:
402 DsFPoint(): x(0), y(0)
403 {
404 }
405
406
413 DsFPoint(float x, float y): x(x), y(y)
414 {
415 }
416
417
423 DsFPoint(const DsPoint &rhs): x(rhs.x), y(rhs.y)
424 {
425 }
426
427
434 {
435 x = rhs.x;
436 y = rhs.y;
437
438 return *this;
439 }
440
441
445 void swap(void)
446 {
447 const float t = x;
448 x = y;
449 y = t;
450 }
451
452
458 bool operator==(const DsFPoint &rhs)
459 {
460 return (x == rhs.x) && (y == rhs.y);
461 }
462
463
470 {
471 DsFPoint rv;
472
473 rv.x = -x;
474 rv.y = -y;
475
476 return rv;
477 }
478
479
488 friend DsFPoint operator+(const DsFPoint &lhs, const DsFPoint &rhs)
489 {
490 DsFPoint r(lhs.x + rhs.x, lhs.y + rhs.y);
491 return r;
492 }
493
494
503 friend DsFPoint operator+(const DsFPoint &lhs, float rhs)
504 {
505 DsFPoint r(lhs.x + rhs, lhs.y + rhs);
506 return r;
507 }
508
509
518 {
519 x += rhs.x;
520 y += rhs.y;
521
522 return *this;
523 }
524
525
534 {
535 x += rhs;
536 y += rhs;
537
538 return *this;
539 }
540
541
550 friend DsFPoint operator-(const DsFPoint &lhs, const DsFPoint &rhs)
551 {
552 DsFPoint r(lhs.x - rhs.x, lhs.y - rhs.y);
553 return r;
554 }
555
556
565 friend DsFPoint operator-(const DsFPoint &lhs, float rhs)
566 {
567 DsFPoint r(lhs.x - rhs, lhs.y - rhs);
568 return r;
569 }
570
571
580 {
581 x -= rhs.x;
582 y -= rhs.y;
583
584 return *this;
585 }
586
587
596 {
597 x -= rhs;
598 y -= rhs;
599
600 return *this;
601 }
602
603
612 friend DsFPoint operator*(const DsFPoint &lhs, float multiplier)
613 {
614 DsFPoint r(lhs.x * multiplier, lhs.y * multiplier);
615 return r;
616 }
617
618
627 friend DsFPoint operator/(const DsFPoint &lhs, float divisor)
628 {
629 DsFPoint r(lhs.x / divisor, lhs.y / divisor);
630 return r;
631 }
632
633
642 {
643 DsFPoint rv = *this;
644
645 if (rv.x < min.x)
646 rv.x = min.x;
647
648 if (rv.y < min.y)
649 rv.y = min.y;
650
651 return rv;
652 }
653
654
663 {
664 DsFPoint rv = *this;
665
666 if (rv.x > max.x)
667 rv.x = max.x;
668
669 if (rv.y > max.y)
670 rv.y = max.y;
671
672 return rv;
673 }
674
675
684 DsFPoint saturate(const DsFPoint &min, const DsFPoint &max)
685 {
686 DsFPoint rv = *this;
687
688 if (rv.x < min.x)
689 rv.x = min.x;
690 else if (rv.x > max.x)
691 rv.x = max.x;
692
693 if (rv.y < min.y)
694 rv.y = min.y;
695 else if (rv.y > max.y)
696 rv.y = max.y;
697
698 return rv;
699 }
700
701
709 float distance(const DsFPoint &p) const
710 {
711 const int32_t dx = p.x - x;
712 const int32_t dy = p.y - y;
713
714 return sqrt(dx * dx + dy * dy);
715 }
716
717
725 float distanceX(const DsFPoint &p) const
726 {
727 return abs(p.x - x);
728 }
729
730
738 float distanceY(const DsFPoint &p) const
739 {
740 return abs(p.y - y);
741 }
742
751 friend float distance(const DsFPoint &p1, const DsFPoint& p2)
752 {
753 const float dx = p1.x - p2.x;
754 const float dy = p1.y - p2.y;
755
756 return sqrt(dx * dx + dy * dy);
757 }
758
759
764 operator DsPoint() const
765 {
766 DsPoint r(x, y);
767 return r;
768 }
769
770 float x;
771 float y;
772};
773
774
775
780{
781public:
785 DsSize(): w(0), h(0)
786 {
787 }
788
789
796 DsSize(int32_t w, int32_t h): w(w), h(h)
797 {
798 }
799
800
806 DsSize(const DsPoint &p): w(p.x), h(p.y)
807 {
808 }
809
810
816 bool operator==(const DsSize &rhs) const
817 {
818 return (w == rhs.w) && (h == rhs.h);
819 }
820
821
827 bool operator!=(const DsSize &rhs) const
828 {
829 return (w != rhs.w) || (h != rhs.h);
830 }
831
832
839 {
840 DsSize rv;
841
842 rv.w = -w;
843 rv.h = -h;
844
845 return rv;
846 }
847
856 friend DsSize operator+(const DsSize &lhs, const DsSize &rhs)
857 {
858 DsSize r(lhs.w + rhs.w, lhs.h + rhs.h);
859 return r;
860 }
861
862
871 friend DsSize operator+(const DsSize &lhs, int32_t rhs)
872 {
873 DsSize r(lhs.w + rhs, lhs.h + rhs);
874 return r;
875 }
876
877
886 {
887 w += rhs.w;
888 h += rhs.h;
889 return *this;
890 }
891
892
900 DsSize& operator+=(int32_t rhs)
901 {
902 w += rhs;
903 h += rhs;
904 return *this;
905 }
906
907
916 friend DsSize operator-(const DsSize &lhs, const DsSize &rhs)
917 {
918 DsSize r(lhs.w - rhs.w, lhs.h - rhs.h);
919 return r;
920 }
921
922
931 friend DsSize operator-(const DsSize &lhs, int32_t rhs)
932 {
933 DsSize r(lhs.w - rhs, lhs.h - rhs);
934 return r;
935 }
936
937
946 {
947 w -= rhs.w;
948 h -= rhs.h;
949 return *this;
950 }
951
952
960 DsSize& operator-=(int32_t rhs)
961 {
962 w -= rhs;
963 h -= rhs;
964 return *this;
965 }
966
967
976 friend DsSize operator*(const DsSize &lhs, float multiplier)
977 {
978 DsSize r(round(lhs.w * multiplier), round(lhs.h * multiplier));
979 return r;
980 }
981
982
991 friend DsSize operator/(const DsSize &lhs, float divisor)
992 {
993 DsSize r(round(lhs.w / divisor), round(lhs.h / divisor));
994 return r;
995 }
996
997
1006 {
1007 DsSize rv = *this;
1008
1009 if (rv.w < min.w)
1010 rv.w = min.w;
1011
1012 if (rv.h < min.h)
1013 rv.h = min.h;
1014
1015 return rv;
1016 }
1017
1018
1027 {
1028 DsSize rv = *this;
1029
1030 if (rv.w > max.w)
1031 rv.w = max.w;
1032
1033 if (rv.h > max.h)
1034 rv.h = max.h;
1035
1036 return rv;
1037 }
1038
1039
1040
1047 {
1048 DsSize rv = DsSize(h, w);
1049 return rv;
1050 }
1051
1052
1053
1062 DsSize saturate(const DsSize &min, const DsSize &max)
1063 {
1064 DsSize rv = *this;
1065
1066 if (rv.w < min.w)
1067 rv.w = min.w;
1068 else if (rv.w > max.w)
1069 rv.w = max.w;
1070
1071 if (rv.h < min.h)
1072 rv.h = min.h;
1073 else if (rv.h > max.h)
1074 rv.h = max.h;
1075
1076 return rv;
1077 }
1078
1079
1084 operator DsPoint() const
1085 {
1086 DsPoint r(w, h);
1087 return r;
1088 }
1089
1094 operator DsFPoint() const
1095 {
1096 DsFPoint r(w, h);
1097 return r;
1098 }
1099
1100 int32_t w;
1101 int32_t h;
1102};
1103
1104
1105
1110{
1111public:
1115 DsFSize(): w(0), h(0)
1116 {
1117 }
1118
1119
1126 DsFSize(float w, float h): w(w), h(h)
1127 {
1128 }
1129
1130
1136 DsFSize(const DsPoint &p): w(p.x), h(p.y)
1137 {
1138 }
1139
1140
1146 DsFSize(const DsFPoint &p): w(p.x), h(p.y)
1147 {
1148 }
1149
1150
1156 DsFSize(const DsSize &s): w(s.w), h(s.h)
1157 {
1158 }
1159
1160
1166 bool operator==(const DsFSize &rhs) const
1167 {
1168 return (w == rhs.w) && (h == rhs.h);
1169 }
1170
1171
1177 bool operator!=(const DsFSize &rhs) const
1178 {
1179 return (w != rhs.w) || (h != rhs.h);
1180 }
1181
1182
1189 {
1190 DsFSize rv;
1191
1192 rv.w = -w;
1193 rv.h = -h;
1194
1195 return rv;
1196 }
1197
1206 friend DsFSize operator+(const DsFSize &lhs, const DsFSize &rhs)
1207 {
1208 DsFSize r(lhs.w + rhs.w, lhs.h + rhs.h);
1209 return r;
1210 }
1211
1212
1221 friend DsFSize operator+(const DsFSize &lhs, float rhs)
1222 {
1223 DsFSize r(lhs.w + rhs, lhs.h + rhs);
1224 return r;
1225 }
1226
1227
1236 {
1237 w += rhs.w;
1238 h += rhs.h;
1239 return *this;
1240 }
1241
1242
1251 {
1252 w += rhs;
1253 h += rhs;
1254 return *this;
1255 }
1256
1257
1266 friend DsFSize operator-(const DsFSize &lhs, const DsFSize &rhs)
1267 {
1268 DsFSize r(lhs.w - rhs.w, lhs.h - rhs.h);
1269 return r;
1270 }
1271
1272
1281 friend DsFSize operator-(const DsFSize &lhs, float rhs)
1282 {
1283 DsFSize r(lhs.w - rhs, lhs.h - rhs);
1284 return r;
1285 }
1286
1287
1296 {
1297 w -= rhs.w;
1298 h -= rhs.h;
1299 return *this;
1300 }
1301
1302
1311 {
1312 w -= rhs;
1313 h -= rhs;
1314 return *this;
1315 }
1316
1317
1326 friend DsFSize operator*(const DsFSize &lhs, float multiplier)
1327 {
1328 return DsFSize(lhs.w * multiplier, lhs.h * multiplier);
1329 }
1330
1331
1340 friend DsFSize operator*(const DsFSize &lhs, const DsFSize &rhs)
1341 {
1342 return DsFSize(lhs.w * rhs.w, lhs.h * rhs.h);
1343 }
1344
1345
1354 friend DsFSize operator/(const DsFSize &lhs, const DsFSize &rhs)
1355 {
1356 return DsFSize(lhs.w / rhs.w, lhs.h / rhs.h);
1357 }
1358
1359
1368 friend DsFSize operator/(const DsFSize &lhs, float divisor)
1369 {
1370 return DsFSize(lhs.w / divisor, lhs.h / divisor);
1371 }
1372
1373
1380 {
1381 DsFSize rv = DsFSize(h, w);
1382 return rv;
1383 }
1384
1385
1394 {
1395 DsFSize rv = *this;
1396
1397 if (rv.w < min.w)
1398 rv.w = min.w;
1399
1400 if (rv.h < min.h)
1401 rv.h = min.h;
1402
1403 return rv;
1404 }
1405
1406
1415 {
1416 DsFSize rv = *this;
1417
1418 if (rv.w > max.w)
1419 rv.w = max.w;
1420
1421 if (rv.h > max.h)
1422 rv.h = max.h;
1423
1424 return rv;
1425 }
1426
1427
1436 DsFSize saturate(const DsFSize &min, const DsFSize &max)
1437 {
1438 DsFSize rv = *this;
1439
1440 if (rv.w < min.w)
1441 rv.w = min.w;
1442 else if (rv.w > max.w)
1443 rv.w = max.w;
1444
1445 if (rv.h < min.h)
1446 rv.h = min.h;
1447 else if (rv.h > max.h)
1448 rv.h = max.h;
1449
1450 return rv;
1451 }
1452
1453
1458 operator DsPoint() const
1459 {
1460 DsPoint r(w, h);
1461 return r;
1462 }
1463
1468 operator DsFPoint() const
1469 {
1470 DsFPoint r(w, h);
1471 return r;
1472 }
1473
1478 operator DsSize() const
1479 {
1480 DsSize r(w, h);
1481 return r;
1482 }
1483
1484 float w;
1485 float h;
1486};
1487
1488
1489class DsFRect;
1490
1492{
1493public:
1494 virtual pair<float, float> getVerticalRange(float x) const = 0;
1495 virtual pair<float, float> getHorizontalRange(float y) const = 0;
1496
1497 virtual DsFRect getRect(void) const = 0;
1498
1499 virtual void rotate(const DsSurface& surface) = 0;
1500 virtual DsFRect move(const DsFPoint& offset) = 0;
1501};
1502
1506class DsRect: public DsRegion
1507{
1508public:
1509
1513 DsRect(): x(0), y(0), w(0), h(0)
1514 {
1515 }
1516
1525 DsRect(int32_t x, int32_t y, int32_t w, int32_t h): x(x), y(y), w(w), h(h)
1526 {
1527 }
1528
1535 DsRect(const DsPoint &pos, const DsSize &size): x(pos.x), y(pos.y), w(size.w), h(size.h)
1536 {
1537 }
1538
1539
1546 {
1547 return DsPoint(x, y);
1548 }
1549
1555 void setPosition(const DsPoint &pos)
1556 {
1557 x = pos.x;
1558 y = pos.y;
1559 }
1560
1561
1567 void setPosition(const DsFPoint &pos)
1568 {
1569 x = round(pos.x);
1570 y = round(pos.y);
1571 }
1572
1573
1579 DsSize getSize(void) const
1580 {
1581 return DsSize(w, h);
1582 }
1583
1589 void setSize(const DsSize &size)
1590 {
1591 w = size.w;
1592 h = size.h;
1593 }
1594
1595
1602 {
1603 DsFPoint center;
1604
1605 center.x = x + w / 2.0;
1606 center.y = y + h / 2.0;
1607
1608 return center;
1609 }
1610
1611
1617 uint32_t area(void) const
1618 {
1619 return w * h;
1620 }
1621
1622
1630 bool contains(const DsPoint &p) const
1631 {
1632 return (p.x >= x) && (p.x < (x + w)) &&
1633 (p.y >= y) && (p.y < (y + h));
1634 }
1635
1636
1644 DsRect intersect(const DsRect &r) const
1645 {
1646 const int32_t xx = max(x, r.x);
1647 const int32_t yy = max(y, r.y);
1648
1649 int32_t ww = min(x + w, r.x + r.w);
1650 int32_t hh = min(y + h, r.y + r.h);
1651
1652 ww = max(ww - xx, 0);
1653 hh = max(hh - yy, 0);
1654
1655 return DsRect(xx, yy, ww, hh);
1656 }
1657
1658
1666 DsRect& move(const DsPoint &offset)
1667 {
1668 x += offset.x;
1669 y += offset.y;
1670
1671 return *this;
1672 }
1673
1674
1680 DsFRect move(const DsFPoint& offset) override final;
1681
1682
1690 DsRect& cat(const DsRect &r)
1691 {
1692 if (area() == 0)
1693 {
1694 *this = r;
1695 }
1696 else if (r.area())
1697 {
1698 w = max(x + w, r.x + r.w);
1699 h = max(y + h, r.y + r.h);
1700
1701 x = min(x, r.x);
1702 y = min(y, r.y);
1703
1704 w -= x;
1705 h -= y;
1706 }
1707
1708 return *this;
1709 }
1710
1711
1720 friend DsRect operator+(const DsRect &lhs, const DsRect &rhs)
1721 {
1722 DsRect result = lhs;
1723
1724 result.w = max(lhs.x + lhs.w, rhs.x + rhs.w);
1725 result.h = max(lhs.y + lhs.h, rhs.y + rhs.h);
1726
1727 result.x = min(lhs.x, rhs.x);
1728 result.y = min(lhs.y, rhs.y);
1729
1730 result.w -= result.x;
1731 result.h -= result.y;
1732
1733 return result;
1734 }
1735
1736
1744 DsRect erode(uint32_t size) const
1745 {
1746 DsRect rect(*this);
1747
1748 rect.x += size;
1749 rect.y += size;
1750
1751 rect.w -= 2 * size;
1752 rect.h -= 2 * size;
1753
1754 return rect;
1755 }
1756
1757
1765 DsRect erodeHorizontal(uint32_t size) const
1766 {
1767 DsRect rect(*this);
1768
1769 rect.x += size;
1770 rect.w -= 2 * size;
1771
1772 return rect;
1773 }
1774
1782 DsRect erodeLeft(uint32_t size) const
1783 {
1784 DsRect rect(*this);
1785
1786 rect.x += size;
1787 rect.w -= size;
1788
1789 return rect;
1790 }
1791
1799 DsRect erodeRight(uint32_t size) const
1800 {
1801 DsRect rect(*this);
1802
1803 rect.w -= size;
1804
1805 return rect;
1806 }
1807
1808
1816 DsRect erodeVertical(uint32_t size) const
1817 {
1818 DsRect rect(*this);
1819
1820 rect.y += size;
1821 rect.h -= 2 * size;
1822
1823 return rect;
1824 }
1825
1833 DsRect erodeTop(uint32_t size) const
1834 {
1835 DsRect rect(*this);
1836
1837 rect.y += size;
1838 rect.h -= size;
1839
1840 return rect;
1841 }
1842
1843
1851 DsRect erodeBottom(uint32_t size) const
1852 {
1853 DsRect rect(*this);
1854
1855 rect.h -= size;
1856
1857 return rect;
1858 }
1859
1860
1868 DsRect dilate(uint32_t size)
1869 {
1870 DsRect rect(*this);
1871
1872 rect.x -= size;
1873 rect.y -= size;
1874
1875 rect.w += 2 * size;
1876 rect.h += 2 * size;
1877
1878 return rect;
1879 }
1880
1888 DsRect dilateTop(uint32_t size)
1889 {
1890 DsRect rect(*this);
1891
1892 rect.y -= size;
1893 rect.h += size;
1894
1895 return rect;
1896 }
1897
1898
1906 DsRect dilateBotom(uint32_t size)
1907 {
1908 DsRect rect(*this);
1909
1910 rect.h += size;
1911
1912 return rect;
1913 }
1914
1915
1923 DsRect dilateLeft(uint32_t size)
1924 {
1925 DsRect rect(*this);
1926
1927 rect.x -= size;
1928 rect.w += size;
1929
1930 return rect;
1931 }
1932
1933
1941 DsRect dilateRight(uint32_t size)
1942 {
1943 DsRect rect(*this);
1944
1945 rect.w += size;
1946
1947 return rect;
1948 }
1949
1950
1958 DsRect getLeftRegion(int32_t split_line)
1959 {
1960 DsRect rect(*this);
1961 rect.w = min(split_line, rect.w);
1962 return rect;
1963 }
1964
1965
1973 DsRect getRightRegion(int32_t split_line)
1974 {
1975 DsRect rect(*this);
1976 rect.x += min(split_line, rect.w);
1977 rect.w -= min(split_line, rect.w);
1978 return rect;
1979 }
1980
1981
1989 DsRect getTopRegion(int32_t split_line)
1990 {
1991 DsRect rect(*this);
1992 rect.h = min(split_line, rect.h);
1993 return rect;
1994 }
1995
1996
2004 DsRect getBottomRegion(int32_t split_line)
2005 {
2006 DsRect rect(*this);
2007 rect.y += min(split_line, rect.h);
2008 rect.h -= min(split_line, rect.h);
2009 return rect;
2010 }
2011
2012
2022 DsRect& align(const DsRect& boundary, const DsAlignment &alignment, const DsPoint &offset = DsPoint())
2023 {
2024 if (alignment.isBottom())
2025 y = boundary.y + boundary.h - h - offset.y;
2026 else if (alignment.isCenterV())
2027 y = boundary.y + ((boundary.h - h) >> 1) + offset.y;
2028 else
2029 y = boundary.y + offset.y;
2030
2031 if (alignment.isRight())
2032 x = boundary.x + boundary.w - w - offset.x;
2033 else if (alignment.isCenterH())
2034 x = boundary.x + ((boundary.w - w) >> 1) + offset.x;
2035 else
2036 x = boundary.x + offset.x;
2037
2038 return *this;
2039 }
2040
2041 pair<float, float> getVerticalRange(float x) const override final;
2042 pair<float, float> getHorizontalRange(float y) const override final;
2043 DsFRect getRect(void) const override final;
2044 void rotate(const DsSurface& surface) override final;
2045
2046
2047 int32_t x;
2048 int32_t y;
2049 int32_t w;
2050 int32_t h;
2051};
2052
2053
2054
2058class DsFRect: public DsRegion
2059{
2060public:
2061
2065 DsFRect(): x(0), y(0), w(0), h(0)
2066 {
2067 }
2068
2069
2075 DsFRect(const DsRect &r): x(r.x), y(r.y), w(r.w), h(r.h)
2076 {
2077 }
2078
2087 DsFRect(float x, float y, float w, float h): x(x), y(y), w(w), h(h)
2088 {
2089 }
2090
2097 DsFRect(const DsFPoint &pos, const DsFSize &size): x(pos.x), y(pos.y), w(size.w), h(size.h)
2098 {
2099 }
2100
2101
2108 {
2109 return DsFPoint(x, y);
2110 }
2111
2117 void setPosition(const DsFPoint &pos)
2118 {
2119 x = pos.x;
2120 y = pos.y;
2121 }
2122
2123
2129 DsFSize getSize(void) const
2130 {
2131 return DsFSize(w, h);
2132 }
2133
2139 void setSize(const DsFSize &size)
2140 {
2141 w = size.w;
2142 h = size.h;
2143 }
2144
2145
2152 {
2153 DsFPoint center;
2154
2155 center.x = x + w / 2.0;
2156 center.y = y + h / 2.0;
2157
2158 return center;
2159 }
2160
2161
2167 float area(void) const
2168 {
2169 return w * h;
2170 }
2171
2172
2180 bool contains(const DsFPoint &p) const
2181 {
2182 return (p.x >= x) && (p.x < (x + w)) &&
2183 (p.y >= y) && (p.y < (y + h));
2184 }
2185
2186
2194 DsFRect intersect(const DsFRect &r) const
2195 {
2196 const float xx = max(x, r.x);
2197 const float yy = max(y, r.y);
2198
2199 float ww = min(x + w, r.x + r.w);
2200 float hh = min(y + h, r.y + r.h);
2201
2202 ww = max(ww - xx, 0);
2203 hh = max(hh - yy, 0);
2204
2205 return DsFRect(xx, yy, ww, hh);
2206 }
2207
2208
2216 DsFRect move(const DsFPoint &offset) override final
2217 {
2218 x += offset.x;
2219 y += offset.y;
2220
2221 return *this;
2222 }
2223
2224
2233 {
2234 if (area() == 0)
2235 {
2236 *this = r;
2237 }
2238 else if (r.area())
2239 {
2240 w = max(x + w, r.x + r.w);
2241 h = max(y + h, r.y + r.h);
2242
2243 x = min(x, r.x);
2244 y = min(y, r.y);
2245
2246 w -= x;
2247 h -= y;
2248 }
2249
2250 return *this;
2251 }
2252
2253
2262 friend DsFRect operator+(const DsFRect &lhs, const DsFRect &rhs)
2263 {
2264 DsFRect result = lhs;
2265
2266 result.w = max(lhs.x + lhs.w, rhs.x + rhs.w);
2267 result.h = max(lhs.y + lhs.h, rhs.y + rhs.h);
2268
2269 result.x = min(lhs.x, rhs.x);
2270 result.y = min(lhs.y, rhs.y);
2271
2272 result.w -= result.x;
2273 result.h -= result.y;
2274
2275 return result;
2276 }
2277
2278
2286 DsFRect erode(float size) const
2287 {
2288 DsFRect rect(*this);
2289
2290 if (size > 0)
2291 {
2292 rect.x += size;
2293 rect.y += size;
2294 rect.w -= 2 * size;
2295 rect.h -= 2 * size;
2296 }
2297
2298 return rect;
2299 }
2300
2301
2309 DsFRect erodeHorizontal(float size) const
2310 {
2311 DsFRect rect(*this);
2312
2313 if (size > 0)
2314 {
2315 rect.x += size;
2316 rect.w -= 2 * size;
2317 }
2318
2319 return rect;
2320 }
2321
2329 DsFRect erodeLeft(float size) const
2330 {
2331 DsFRect rect(*this);
2332
2333 if (size > 0)
2334 {
2335 rect.x += size;
2336 rect.w -= size;
2337 }
2338
2339 return rect;
2340 }
2341
2349 DsFRect erodeRight(float size) const
2350 {
2351 DsFRect rect(*this);
2352
2353 if (size > 0)
2354 rect.w -= size;
2355
2356 return rect;
2357 }
2358
2359
2367 DsFRect erodeVertical(float size) const
2368 {
2369 DsFRect rect(*this);
2370
2371 if (size > 0)
2372 {
2373 rect.y += size;
2374 rect.h -= 2 * size;
2375 }
2376
2377 return rect;
2378 }
2379
2387 DsFRect erodeTop(float size) const
2388 {
2389 DsFRect rect(*this);
2390
2391 if (size > 0)
2392 {
2393 rect.y += size;
2394 rect.h -= size;
2395 }
2396
2397 return rect;
2398 }
2399
2400
2408 DsFRect erodeBottom(float size) const
2409 {
2410 DsFRect rect(*this);
2411
2412 if (size > 0)
2413 rect.h -= size;
2414
2415 return rect;
2416 }
2417
2418
2426 DsFRect dilate(float size)
2427 {
2428 DsFRect rect(*this);
2429
2430 if (size > 0)
2431 {
2432 rect.x -= size;
2433 rect.y -= size;
2434 rect.w += 2 * size;
2435 rect.h += 2 * size;
2436 }
2437
2438 return rect;
2439 }
2440
2448 DsFRect dilateTop(float size)
2449 {
2450 DsFRect rect(*this);
2451
2452 if (size > 0)
2453 {
2454 rect.y -= size;
2455 rect.h += size;
2456 }
2457
2458 return rect;
2459 }
2460
2461
2470 {
2471 DsFRect rect(*this);
2472
2473 if (size > 0)
2474 rect.h += size;
2475
2476 return rect;
2477 }
2478
2479
2488 {
2489 DsFRect rect(*this);
2490
2491 if (size > 0)
2492 {
2493 rect.x -= size;
2494 rect.w += size;
2495 }
2496
2497 return rect;
2498 }
2499
2500
2509 {
2510 DsFRect rect(*this);
2511
2512 if (size > 0)
2513 rect.w += size;
2514
2515 return rect;
2516 }
2517
2518
2526 DsFRect getLeftRegion(float split_line)
2527 {
2528 DsFRect rect(*this);
2529 rect.w = min(split_line, rect.w);
2530 return rect;
2531 }
2532
2533
2541 DsFRect getRightRegion(float split_line)
2542 {
2543 DsFRect rect(*this);
2544 rect.x += min(split_line, rect.w);
2545 rect.w -= min(split_line, rect.w);
2546 return rect;
2547 }
2548
2549
2557 DsFRect getTopRegion(float split_line)
2558 {
2559 DsFRect rect(*this);
2560 rect.h = min(split_line, rect.h);
2561 return rect;
2562 }
2563
2564
2572 DsFRect getBottomRegion(float split_line)
2573 {
2574 DsFRect rect(*this);
2575 rect.y += min(split_line, rect.h);
2576 rect.h -= min(split_line, rect.h);
2577 return rect;
2578 }
2579
2580
2590 DsFRect& align(const DsFRect& boundary, const DsAlignment &alignment, const DsFPoint &offset = DsFPoint())
2591 {
2592 if (alignment.isBottom())
2593 y = boundary.y + boundary.h - h - offset.y;
2594 else if (alignment.isCenterV())
2595 y = boundary.y + ((boundary.h - h) / 2.0) + offset.y;
2596 else
2597 y = boundary.y + offset.y;
2598
2599 if (alignment.isRight())
2600 x = boundary.x + boundary.w - w - offset.x;
2601 else if (alignment.isCenterH())
2602 x = boundary.x + ((boundary.w - w) / 2.0) + offset.x;
2603 else
2604 x = boundary.x + offset.x;
2605
2606 return *this;
2607 }
2608
2613 operator DsRect() const
2614 {
2615 return DsRect(round(x), round(y), round(w), round(h));
2616 }
2617
2618
2619 pair<float, float> getVerticalRange(float x) const override final;
2620 pair<float, float> getHorizontalRange(float y) const override final;
2621 DsFRect getRect(void) const override final;
2622 void rotate(const DsSurface& surface) override final;
2623
2624 float x;
2625 float y;
2626 float w;
2627 float h;
2628};
2629
2630
2631
2635class DsEllipse: public DsRegion
2636{
2637public:
2642 {
2643 }
2644
2653 DsEllipse(float xc, float yc, float rx, float ry): center(xc, yc), radius(rx, ry),
2654 mRhRh(rx * rx), mRvRv(ry * ry),
2655 mRhRhDivRyRy(mRhRh / mRvRv), mRvRvDivRxRx(mRvRv / mRhRh)
2656 {
2657 }
2658
2659
2667 mRhRh(radius.w * radius.w), mRvRv(radius.h * radius.h),
2668 mRhRhDivRyRy(mRhRh / mRvRv), mRvRvDivRxRx(mRvRv / mRhRh)
2669 {
2670 }
2671
2672
2673
2680 mRhRh(this->radius.w * this->radius.w), mRvRv(this->radius.h * this->radius.h),
2681 mRhRhDivRyRy(mRhRh / mRvRv), mRvRvDivRxRx(mRvRv / mRhRh)
2682 {
2683 }
2684
2685
2686
2693 mRhRh(this->radius.w * this->radius.w), mRvRv(this->radius.h * this->radius.h),
2694 mRhRhDivRyRy(mRhRh / mRvRv), mRvRvDivRxRx(mRvRv / mRhRh)
2695 {
2696 }
2697
2698
2706 mRhRh(this->radius.w * this->radius.w), mRvRv(this->radius.h * this->radius.h),
2707 mRhRhDivRyRy(mRhRh / mRvRv), mRvRvDivRxRx(mRvRv / mRhRh)
2708 {
2709 }
2710
2711
2718 DsFRect move(const DsFPoint& offset) override final
2719 {
2720 center += offset;
2721 return getRect();
2722 }
2723
2724
2725 pair<float, float> getVerticalRange(float x) const override final;
2726 pair<float, float> getHorizontalRange(float y) const override final;
2727 DsFRect getRect(void) const override final;
2728 void rotate(const DsSurface& surface) override final;
2729
2730 void setRadius(DsFSize radius);
2731 void setRect(const DsFRect &rect);
2732
2733 float getRadiusAtAngle(float angle);
2734 DsFPoint getPointAtAngle(float angle);
2735
2736 static void computeArcBoundary(float start_angle, float end_angle, bool include_center, float &left, float &right, float &top, float &bottom);
2737 DsFRect computeArcBoundary(float start_angle, float end_angle, bool include_center);
2738
2741
2742private:
2743 float mRhRh;
2744 float mRvRv;
2745 float mRhRhDivRyRy;
2746 float mRvRvDivRxRx;
2747};
2748
2749
2750#endif
DsAlignment is a class representing both horizontal and vertical alignment type.
Definition ds_types.h:130
bool isRight(void) const
Is the horizontal alignment right?
Definition ds_types.h:205
bool isBottom(void) const
Is the vertical alignment bottom?
Definition ds_types.h:232
bool isCenterH(void) const
Is the horizontal alignment center?
Definition ds_types.h:196
bool isCenterV(void) const
Is the vertical alignment center?
Definition ds_types.h:223
DsEllipse is a class that represents a 2D ellipse (Xc, Yc, Rx, Ry)
Definition ds_geometry.h:2636
DsEllipse(DsFPoint center, float radius)
Creates a DsEllipse object initialized to a circle (horizontal and vertical radius are equal)
Definition ds_geometry.h:2705
DsEllipse(DsFPoint center, DsFSize radius)
Creates a DsEllipse object.
Definition ds_geometry.h:2666
DsEllipse(DsFSize radius)
Creates a DsEllipse object initialized to a circle (horizontal and vertical radius are equal)
Definition ds_geometry.h:2679
DsFRect move(const DsFPoint &offset) override final
Moves the current DsEllipse object by a specified 2D offset.
Definition ds_geometry.h:2718
DsFSize radius
ellipse radius
Definition ds_geometry.h:2740
DsEllipse(float radius)
Creates a DsEllipse object initialized to a circle (horizontal and vertical radius are equal)
Definition ds_geometry.h:2692
DsEllipse(float xc, float yc, float rx, float ry)
Creates a DsEllipse object.
Definition ds_geometry.h:2653
DsEllipse()
Creates a DsEllipse object initialized to (center = (0, 0), radius = (0, 0)).
Definition ds_geometry.h:2641
DsFPoint center
ellipse center coordinates
Definition ds_geometry.h:2739
DsFPoint is a class that represents the X and Y 2D coordinates of a point as floating point numbers.
Definition ds_geometry.h:397
friend DsFPoint operator+(const DsFPoint &lhs, const DsFPoint &rhs)
Addition operator - adds two DsFPoint objects.
Definition ds_geometry.h:488
bool operator==(const DsFPoint &rhs)
Comparison operator.
Definition ds_geometry.h:458
DsFPoint(float x, float y)
Creates a DsFPoint object initialized to (x, y).
Definition ds_geometry.h:413
friend DsFPoint operator+(const DsFPoint &lhs, float rhs)
Addition operator - adds a number to both the X and Y coordinates of a DsFPoint object.
Definition ds_geometry.h:503
DsFPoint(const DsPoint &rhs)
Assignment operator from a DsFPoint object.
Definition ds_geometry.h:423
float distance(const DsFPoint &p) const
Calculates the Euclidian distance between the current DsFPoint object and a second DsFPoint object.
Definition ds_geometry.h:709
friend DsFPoint operator-(const DsFPoint &lhs, float rhs)
Subtraction operator - subtracts a number from a DsFPoint object.
Definition ds_geometry.h:565
DsFPoint saturateMin(const DsFPoint &min)
Saturates the current DsFPoint object coordinates to the minimum specified.
Definition ds_geometry.h:641
DsFPoint & operator+=(float rhs)
Addition operator - adds a number to both the X and Y coordinates of the current DsFPoint object.
Definition ds_geometry.h:533
friend float distance(const DsFPoint &p1, const DsFPoint &p2)
Calculates the Euclidian distance between two DsFPoint objects.
Definition ds_geometry.h:751
DsFPoint & operator-=(const DsFPoint &rhs)
Subtraction operator - subtracts a DsFPoint object from the current DsFPoint object.
Definition ds_geometry.h:579
friend DsFPoint operator-(const DsFPoint &lhs, const DsFPoint &rhs)
Subtraction operator - subtracts two DsFPoint objects.
Definition ds_geometry.h:550
DsFPoint saturateMax(const DsFPoint &max)
Saturates the current DsFPoint object coordinates to the maximum specified.
Definition ds_geometry.h:662
DsFPoint & operator+=(const DsFPoint &rhs)
Addition operator - adds a DsFPoint object to the current DsFPoint object.
Definition ds_geometry.h:517
DsFPoint operator-() const
Unary minus operator. Reverses the signs of both the X and Y coordinates of the current DsFPoint obje...
Definition ds_geometry.h:469
friend DsFPoint operator/(const DsFPoint &lhs, float divisor)
Floating point division operator - divides both X and Y coordinates of a DsFPoint object by the same ...
Definition ds_geometry.h:627
float distanceY(const DsFPoint &p) const
Calculates the Y component of the Euclidian distance between the current DsFPoint object and a second...
Definition ds_geometry.h:738
DsFPoint & operator-=(float rhs)
Subtraction operator - subtracts a number from the current DsFPoint object.
Definition ds_geometry.h:595
DsFPoint()
Creates a DsFPoint object initialized to (0, 0).
Definition ds_geometry.h:402
void swap(void)
Swaps the X and Y coordinates of the current DsFPoint object.
Definition ds_geometry.h:445
friend DsFPoint operator*(const DsFPoint &lhs, float multiplier)
Multiplication operator - multiplies both X and Y coordinates of a DsFPoint object with the same mult...
Definition ds_geometry.h:612
DsFPoint & operator=(const DsPoint &rhs)
Assignment operator from a DsPoint object.
Definition ds_geometry.h:433
float distanceX(const DsFPoint &p) const
Calculates the X component of the Euclidian distance between the current DsFPoint object and a second...
Definition ds_geometry.h:725
float y
Y component.
Definition ds_geometry.h:771
DsFPoint saturate(const DsFPoint &min, const DsFPoint &max)
Saturates the current DsFPoint object coordinates to the minimum and maximum specified.
Definition ds_geometry.h:684
float x
X component.
Definition ds_geometry.h:770
DsFRect is a class that represents a 2D rectangle (X, Y, W, H) using floating point coordiantes and s...
Definition ds_geometry.h:2059
DsFRect()
Creates a DsRect object initialized to (0, 0, 0, 0).
Definition ds_geometry.h:2065
DsFRect erodeTop(float size) const
Erodes the current DsRect object by a specific size on the top side only.
Definition ds_geometry.h:2387
DsFRect(const DsFPoint &pos, const DsFSize &size)
Creates a DsPoint object initialized to (x, y, w, h).
Definition ds_geometry.h:2097
DsFRect dilateLeft(float size)
Dilates the current DsRect object by a specific size on the left side only.
Definition ds_geometry.h:2487
DsFRect erodeBottom(float size) const
Erodes the current DsRect object by a specific size on the bottom side only.
Definition ds_geometry.h:2408
DsFRect getRightRegion(float split_line)
Splits the rectangle in two using a vertical line and returns the right rectangle.
Definition ds_geometry.h:2541
friend DsFRect operator+(const DsFRect &lhs, const DsFRect &rhs)
Addition operator - concatenates two DsRect objects.
Definition ds_geometry.h:2262
DsFRect & cat(const DsFRect &r)
Concatenates the current DsRect object with another rectangle.
Definition ds_geometry.h:2232
float x
X coordinate of the top left corner.
Definition ds_geometry.h:2624
DsFPoint getCenter(void) const
Gets the position of the center of the rectangle.
Definition ds_geometry.h:2151
DsFRect & align(const DsFRect &boundary, const DsAlignment &alignment, const DsFPoint &offset=DsFPoint())
Changes the X and Y components of the current rectangle to align it in the specified parent rectangle...
Definition ds_geometry.h:2590
void setPosition(const DsFPoint &pos)
Sets the position of the rectangle (top left corner).
Definition ds_geometry.h:2117
float area(void) const
Gets the area of rectangle.
Definition ds_geometry.h:2167
void setSize(const DsFSize &size)
Sets the size of the rectangle.
Definition ds_geometry.h:2139
float y
Y coordinate of the top left corner.
Definition ds_geometry.h:2625
DsFPoint getPosition(void) const
Gets the position of the rectangle (top left corner).
Definition ds_geometry.h:2107
DsFSize getSize(void) const
Gets the size of the rectangle.
Definition ds_geometry.h:2129
DsFRect dilateTop(float size)
Dilates the current DsRect object by a specific size on the top side only.
Definition ds_geometry.h:2448
DsFRect dilateBotom(float size)
Dilates the current DsRect object by a specific size on the bottom side only.
Definition ds_geometry.h:2469
DsFRect getBottomRegion(float split_line)
Splits the rectangle in two using a horizontal line and returns the bottom rectangle.
Definition ds_geometry.h:2572
DsFRect move(const DsFPoint &offset) override final
Moves the current DsRect object by a specified 2D offset.
Definition ds_geometry.h:2216
DsFRect dilateRight(float size)
Dilates the current DsRect object by a specific size on the right side only.
Definition ds_geometry.h:2508
float h
Height of the rectangle in pixels.
Definition ds_geometry.h:2627
DsFRect erodeLeft(float size) const
Erodes the current DsRect object by a specific size on the left side only.
Definition ds_geometry.h:2329
DsFRect getTopRegion(float split_line)
Splits the rectangle in two using a horizontal line and returns the top rectangle.
Definition ds_geometry.h:2557
DsFRect dilate(float size)
Dilates the current DsRect object by a specific size.
Definition ds_geometry.h:2426
DsFRect intersect(const DsFRect &r) const
Gets the intersection rectangle of the current DsRect object with another rectangle.
Definition ds_geometry.h:2194
float w
Width of the rectangle in pixels.
Definition ds_geometry.h:2626
DsFRect erode(float size) const
Erodes the current DsRect object by a specific size.
Definition ds_geometry.h:2286
DsFRect erodeVertical(float size) const
Erodes the current DsRect object by a specific size in the vertical direction only.
Definition ds_geometry.h:2367
DsFRect(float x, float y, float w, float h)
Creates a DsPoint object initialized to (x, y, w, h).
Definition ds_geometry.h:2087
DsFRect erodeHorizontal(float size) const
Erodes the current DsRect object by a specific size in the horizontal direction.
Definition ds_geometry.h:2309
DsFRect erodeRight(float size) const
Erodes the current DsRect object by a specific size on the right side only.
Definition ds_geometry.h:2349
DsFRect getLeftRegion(float split_line)
Splits the rectangle in two using a vertical line and returns the left rectangle.
Definition ds_geometry.h:2526
bool contains(const DsFPoint &p) const
Does the rectangle contain a specific point?
Definition ds_geometry.h:2180
DsFRect(const DsRect &r)
Creates a DsFRect object from a DsRect object.
Definition ds_geometry.h:2075
DsFSize is class that represents the 2D size of a graphic object (width, height) as floating point va...
Definition ds_geometry.h:1110
DsFSize(const DsSize &s)
Creates a DsFSize object from a DsSize object.
Definition ds_geometry.h:1156
bool operator!=(const DsFSize &rhs) const
Comparison operator.
Definition ds_geometry.h:1177
DsFSize swap(void)
Returns a DsFSize object with the width and height swapped.
Definition ds_geometry.h:1379
DsFSize(const DsFPoint &p)
Creates a DsFSize object using the X and Y coordinates of a point as width and height.
Definition ds_geometry.h:1146
DsFSize saturateMin(const DsFSize &min)
Saturates the current DsFSize object components to the minimum specified.
Definition ds_geometry.h:1393
DsFSize saturateMax(const DsFSize &max)
Saturates the current DsFSize object components to the maximum specified.
Definition ds_geometry.h:1414
DsFSize(const DsPoint &p)
Creates a DsFSize object using the X and Y coordinates of a point as width and height.
Definition ds_geometry.h:1136
DsFSize saturate(const DsFSize &min, const DsFSize &max)
Saturates the current DsFSize object components to the minimum and maximum specified.
Definition ds_geometry.h:1436
bool operator==(const DsFSize &rhs) const
Comparison operator.
Definition ds_geometry.h:1166
DsFSize(float w, float h)
Creates a DsFSize object of size (w, h).
Definition ds_geometry.h:1126
DsFSize operator-() const
Unary minus operator. Reverses the signs of both the W and H of the current DsFSize object.
Definition ds_geometry.h:1188
friend DsFSize operator/(const DsFSize &lhs, const DsFSize &rhs)
Division operator - divides both W and H components of a DsFSize object by the same divisor.
Definition ds_geometry.h:1354
float w
Width component.
Definition ds_geometry.h:1484
DsFSize & operator-=(const DsFSize &rhs)
Subtraction operator - subtracts a DsFSize object from the current DsFSize object.
Definition ds_geometry.h:1295
friend DsFSize operator*(const DsFSize &lhs, const DsFSize &rhs)
Multiplication operator - multiplies both W and H components of a DsFSize object with the (W,...
Definition ds_geometry.h:1340
friend DsFSize operator+(const DsFSize &lhs, float rhs)
Addition operator - adds two DsFSize objects.
Definition ds_geometry.h:1221
DsFSize()
Creates a DsFSize object of size (0, 0).
Definition ds_geometry.h:1115
float h
Height component.
Definition ds_geometry.h:1485
friend DsFSize operator*(const DsFSize &lhs, float multiplier)
Multiplication operator - multiplies both W and H components of a DsFSize object with the same multip...
Definition ds_geometry.h:1326
DsFSize & operator+=(const DsFSize &rhs)
Addition operator - adds a DsFSize object to the current DsFSize object.
Definition ds_geometry.h:1235
friend DsFSize operator-(const DsFSize &lhs, const DsFSize &rhs)
Subtraction operator - subtracts two DsFSize objects.
Definition ds_geometry.h:1266
DsFSize & operator-=(float rhs)
Subtraction operator - subtracts an integer from the current DsFSize object.
Definition ds_geometry.h:1310
friend DsFSize operator-(const DsFSize &lhs, float rhs)
Subtraction operator - subtracts an integer from a DsFSize object.
Definition ds_geometry.h:1281
friend DsFSize operator+(const DsFSize &lhs, const DsFSize &rhs)
Addition operator - adds two DsFSize objects.
Definition ds_geometry.h:1206
DsFSize & operator+=(float rhs)
Addition operator - adds an integer to the current DsFSize object (add to both w and h).
Definition ds_geometry.h:1250
friend DsFSize operator/(const DsFSize &lhs, float divisor)
Division operator - divides both W and H components of a DsFSize object by the (W,...
Definition ds_geometry.h:1368
DsPoint is a class that represents the X and Y 2D coordinates of a point as integer numbers.
Definition ds_geometry.h:24
DsPoint & operator=(const DsFPoint &rhs)
Assignment operator from a DsFPoint object.
friend DsPoint operator/(const DsPoint &lhs, int32_t divisor)
Integer division operator - divides both X and Y coordinates of a DsPoint object by the same divisor.
Definition ds_geometry.h:238
friend float distance(const DsPoint &p1, const DsPoint &p2)
Calculates the Euclidian distance between two DsPoint objects.
Definition ds_geometry.h:378
int32_t y
Y component.
Definition ds_geometry.h:387
int32_t x
X component.
Definition ds_geometry.h:386
DsPoint operator-() const
Unary minus operator. Reverses the signs of both the X and Y coordinates of the current DsPoint objec...
Definition ds_geometry.h:80
bool operator==(const DsPoint &rhs)
Comparison operator.
Definition ds_geometry.h:69
DsPoint saturateMax(const DsPoint &max)
Saturates the current DsPoint object coordinates to the maximum specified.
Definition ds_geometry.h:288
DsPoint & operator-=(int32_t rhs)
Subtraction operator - subtract a number from the current DsPoint object.
Definition ds_geometry.h:206
DsPoint & operator+=(const DsPoint &rhs)
Addition operator - adds a DsPoint object to the current DsPoint object.
Definition ds_geometry.h:128
friend DsPoint operator-(const DsPoint &lhs, int32_t rhs)
Subtraction operator - subtract a number from a DsPoint object.
Definition ds_geometry.h:176
float distance(const DsPoint &p) const
Calculates the Euclidian distance between the current DsPoint object and a second DsPoint object.
Definition ds_geometry.h:335
friend DsPoint operator+(const DsPoint &lhs, int32_t rhs)
Addition operator - adds a number to both the X and Y coordinates of a DsPoint object.
Definition ds_geometry.h:114
DsPoint & operator-=(const DsPoint &rhs)
Subtraction operator - subtract a DsPoint object from the current DsPoint object.
Definition ds_geometry.h:190
DsPoint(int32_t x, int32_t y)
Creates a DsPoint object initialized to (x, y).
Definition ds_geometry.h:40
friend DsPoint operator-(const DsPoint &lhs, const DsPoint &rhs)
Subtraction operator - subtract two DsPoint objects.
Definition ds_geometry.h:161
friend DsPoint operator*(const DsPoint &lhs, int32_t multiplier)
Multiplication operator - multiplies both X and Y coordinates of a DsPoint object with the same multi...
Definition ds_geometry.h:223
float distanceY(const DsPoint &p) const
Calculates the Y component of the Euclidian distance between the current DsPoint object and a second ...
Definition ds_geometry.h:364
friend DsPoint operator+(const DsPoint &lhs, const DsPoint &rhs)
Addition operator - adds two DsPoint objects.
Definition ds_geometry.h:99
void swap(void)
Swaps the X and Y coordinates of the current DsPoint object.
Definition ds_geometry.h:56
DsPoint & operator+=(int32_t rhs)
Addition operator - adds a number to both the X and Y coordinates of the current DsPoint object.
Definition ds_geometry.h:144
float distanceX(const DsPoint &p) const
Calculates the X component of the Euclidian distance between the current DsPoint object and a second ...
Definition ds_geometry.h:351
DsPoint saturateMin(const DsPoint &min)
Saturates the current DsPoint object coordinates to the minimum specified.
Definition ds_geometry.h:267
friend DsPoint operator/(const DsPoint &lhs, float divisor)
Integer division operator - divides both X and Y coordinates of a DsPoint object by the same divisor.
Definition ds_geometry.h:253
DsPoint()
Creates a DsPoint object initialized to (0, 0).
Definition ds_geometry.h:29
DsPoint saturate(const DsPoint &min, const DsPoint &max)
Saturates the current DsPoint object coordinates to the minimum and maximum specified.
Definition ds_geometry.h:310
DsRect is a class that represents a 2D rectangle (X, Y, W, H)
Definition ds_geometry.h:1507
DsRect dilateRight(uint32_t size)
Dilates the current DsRect object by a specific size on the right side only.
Definition ds_geometry.h:1941
DsRect erodeBottom(uint32_t size) const
Erodes the current DsRect object by a specific size on the bottom side only.
Definition ds_geometry.h:1851
DsRect dilateTop(uint32_t size)
Dilates the current DsRect object by a specific size on the top side only.
Definition ds_geometry.h:1888
int32_t h
Height of the rectangle in pixels.
Definition ds_geometry.h:2050
DsRect getRightRegion(int32_t split_line)
Splits the rectangle in two using a vertical line and returns the right rectangle.
Definition ds_geometry.h:1973
DsRect getBottomRegion(int32_t split_line)
Splits the rectangle in two using a horizontal line and returns the bottom rectangle.
Definition ds_geometry.h:2004
DsPoint getPosition(void) const
Gets the position of the rectangle (top left corner).
Definition ds_geometry.h:1545
DsRect getLeftRegion(int32_t split_line)
Splits the rectangle in two using a vertical line and returns the left rectangle.
Definition ds_geometry.h:1958
int32_t x
X coordinate of the top left corner.
Definition ds_geometry.h:2047
void setPosition(const DsFPoint &pos)
Sets the position of the rectangle (top left corner).
Definition ds_geometry.h:1567
DsRect dilateBotom(uint32_t size)
Dilates the current DsRect object by a specific size on the bottom side only.
Definition ds_geometry.h:1906
DsFRect move(const DsFPoint &offset) override final
Moves the current DsRect object by a specified 2D offset.
DsRect()
Creates a DsRect object initialized to (0, 0, 0, 0).
Definition ds_geometry.h:1513
int32_t y
Y coordinate of the top left corner.
Definition ds_geometry.h:2048
DsSize getSize(void) const
Gets the size of the rectangle.
Definition ds_geometry.h:1579
DsRect dilateLeft(uint32_t size)
Dilates the current DsRect object by a specific size on the left side only.
Definition ds_geometry.h:1923
DsRect & align(const DsRect &boundary, const DsAlignment &alignment, const DsPoint &offset=DsPoint())
Changes the X and Y components of the current rectangle to align it in the specified parent rectangle...
Definition ds_geometry.h:2022
DsRect erodeLeft(uint32_t size) const
Erodes the current DsRect object by a specific size on the left side only.
Definition ds_geometry.h:1782
void setPosition(const DsPoint &pos)
Sets the position of the rectangle (top left corner).
Definition ds_geometry.h:1555
DsRect intersect(const DsRect &r) const
Gets the intersection rectangle of the current DsRect object with another rectangle.
Definition ds_geometry.h:1644
DsRect erodeHorizontal(uint32_t size) const
Erodes the current DsRect object by a specific size in the horizontal direction.
Definition ds_geometry.h:1765
friend DsRect operator+(const DsRect &lhs, const DsRect &rhs)
Addition operator - concatenates two DsRect objects.
Definition ds_geometry.h:1720
DsRect erode(uint32_t size) const
Erodes the current DsRect object by a specific size.
Definition ds_geometry.h:1744
uint32_t area(void) const
Gets the area of rectangle.
Definition ds_geometry.h:1617
DsRect erodeRight(uint32_t size) const
Erodes the current DsRect object by a specific size on the right side only.
Definition ds_geometry.h:1799
DsRect getTopRegion(int32_t split_line)
Splits the rectangle in two using a horizontal line and returns the top rectangle.
Definition ds_geometry.h:1989
int32_t w
Width of the rectangle in pixels.
Definition ds_geometry.h:2049
DsRect erodeTop(uint32_t size) const
Erodes the current DsRect object by a specific size on the top side only.
Definition ds_geometry.h:1833
DsFPoint getCenter(void) const
Gets the position of the center of the rectangle.
Definition ds_geometry.h:1601
DsRect dilate(uint32_t size)
Dilates the current DsRect object by a specific size.
Definition ds_geometry.h:1868
void setSize(const DsSize &size)
Sets the size of the rectangle.
Definition ds_geometry.h:1589
bool contains(const DsPoint &p) const
Does the rectangle contain a specific point?
Definition ds_geometry.h:1630
DsRect erodeVertical(uint32_t size) const
Erodes the current DsRect object by a specific size in the vertical direction only.
Definition ds_geometry.h:1816
DsRect & move(const DsPoint &offset)
Moves the current DsRect object by a specified 2D offset.
Definition ds_geometry.h:1666
DsRect(const DsPoint &pos, const DsSize &size)
Creates a DsPoint object initialized to (x, y, w, h).
Definition ds_geometry.h:1535
DsRect(int32_t x, int32_t y, int32_t w, int32_t h)
Creates a DsPoint object initialized to (x, y, w, h).
Definition ds_geometry.h:1525
DsRect & cat(const DsRect &r)
Concatenates the current DsRect object with another rectangle.
Definition ds_geometry.h:1690
Definition ds_geometry.h:1492
DsSize is class that represents the 2D size of a graphic object (width, height) as integer values.
Definition ds_geometry.h:780
friend DsSize operator-(const DsSize &lhs, int32_t rhs)
Subtraction operator - subtracts an integer from a DsSize object.
Definition ds_geometry.h:931
DsSize operator-() const
Unary minus operator. Reverses the signs of both the W and H of the current DsSize object.
Definition ds_geometry.h:838
friend DsSize operator+(const DsSize &lhs, const DsSize &rhs)
Addition operator - adds two DsSize objects.
Definition ds_geometry.h:856
DsSize & operator+=(const DsSize &rhs)
Addition operator - adds a DsSize object to the current DsSize object.
Definition ds_geometry.h:885
DsSize saturateMax(const DsSize &max)
Saturates the current DsSize object components to the maximum specified.
Definition ds_geometry.h:1026
friend DsSize operator-(const DsSize &lhs, const DsSize &rhs)
Subtraction operator - subtracts two DsSize objects.
Definition ds_geometry.h:916
DsSize swap(void)
Returns a DsSize object with the width and height swapped.
Definition ds_geometry.h:1046
DsSize & operator+=(int32_t rhs)
Addition operator - adds an integer to the current DsSize object (add to both w and h).
Definition ds_geometry.h:900
int32_t h
Height component.
Definition ds_geometry.h:1101
DsSize & operator-=(const DsSize &rhs)
Subtraction operator - subtracts a DsSize object from the current DsSize object.
Definition ds_geometry.h:945
DsSize(int32_t w, int32_t h)
Creates a DsSize object of size (w, h).
Definition ds_geometry.h:796
DsSize saturate(const DsSize &min, const DsSize &max)
Saturates the current DsSize object components to the minimum and maximum specified.
Definition ds_geometry.h:1062
friend DsSize operator/(const DsSize &lhs, float divisor)
Division operator - divides both W and H components of a DsSize object by the same divisor.
Definition ds_geometry.h:991
DsSize(const DsPoint &p)
Creates a DsSize object using the X and Y coordinates of a point as width and height.
Definition ds_geometry.h:806
DsSize saturateMin(const DsSize &min)
Saturates the current DsSize object components to the minimum specified.
Definition ds_geometry.h:1005
friend DsSize operator*(const DsSize &lhs, float multiplier)
Multiplication operator - multiplies both W and H components of a DsSize object with the same multipl...
Definition ds_geometry.h:976
friend DsSize operator+(const DsSize &lhs, int32_t rhs)
Addition operator - adds two DsSize objects.
Definition ds_geometry.h:871
DsSize & operator-=(int32_t rhs)
Subtraction operator - subtracts an integer from the current DsSize object.
Definition ds_geometry.h:960
int32_t w
Width component.
Definition ds_geometry.h:1100
DsSize()
Creates a DsSize object of size (0, 0).
Definition ds_geometry.h:785
bool operator!=(const DsSize &rhs) const
Comparison operator.
Definition ds_geometry.h:827
bool operator==(const DsSize &rhs) const
Comparison operator.
Definition ds_geometry.h:816
DsSurface is a class that represents a drawing surface.
Definition ds_surface.h:30
pair is a class that represents a pair of two values.
Definition ds_types_pair.h:20