SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_rect.h
1#ifndef SDL3PP_RECT_H_
2#define SDL3PP_RECT_H_
3
4#include <optional>
5#include <span>
6#include <SDL3/SDL_rect.h>
7#include "SDL3pp_error.h"
8#include "SDL3pp_optionalRef.h"
9#include "SDL3pp_spanRef.h"
10#include "SDL3pp_stdinc.h"
11
12namespace SDL {
13
23// Forward decl
24struct FPoint;
25
26// Forward decl
27struct Rect;
28
29// Forward decl
30struct FRect;
31
45struct Point : SDL_Point
46{
52 constexpr Point(const SDL_Point& p = {})
53 : SDL_Point(p)
54 {
55 }
56
63 constexpr Point(int x, int y)
64 : SDL_Point{x, y}
65 {
66 }
67
71 constexpr explicit Point(const SDL_FPoint& p)
72 : SDL_Point{int(p.x), int(p.y)}
73 {
74 }
75
79 constexpr bool operator==(const Point& other) const
80 {
81 return x == other.x && y == other.y;
82 }
83
87 constexpr bool operator==(const SDL_Point& p) const
88 {
89 return operator==(Point(p));
90 }
96 constexpr explicit operator bool() const { return x != 0 && y != 0; }
97
104 constexpr int GetX() const { return x; }
105
112 constexpr Point& SetX(int newX)
113 {
114 x = newX;
115 return *this;
116 }
117
124 constexpr int GetY() const { return y; }
125
132 constexpr Point& SetY(int newY)
133 {
134 y = newY;
135 return *this;
136 }
137
158 constexpr bool IsInRect(const Rect& r) const;
159
166 constexpr Point operator-() const { return Point(-x, -y); }
167
176 constexpr Point operator+(const Point& other) const
177 {
178 return Point(x + other.x, y + other.y);
179 }
180
189 constexpr Point operator-(const Point& other) const
190 {
191 return Point(x - other.x, y - other.y);
192 }
193
203 constexpr Point operator/(int value) const
204 {
205 return Point(x / value, y / value);
206 }
207
217 constexpr FPoint operator/(float value) const;
218
228 constexpr Point operator/(const Point& other) const
229 {
230 return Point(x / other.x, y / other.y);
231 }
232
243 constexpr Point operator%(int value) const
244 {
245 return Point(x % value, y % value);
246 }
247
258 constexpr Point operator%(const Point& other) const
259 {
260 return Point(x % other.x, y % other.y);
261 }
262
273 constexpr Point operator*(int value) const
274 {
275 return Point(x * value, y * value);
276 }
277
288 constexpr FPoint operator*(float value) const;
289
300 constexpr Point operator*(const Point& other) const
301 {
302 return Point(x * other.x, y * other.y);
303 }
304
313 constexpr Point& operator+=(const Point& other)
314 {
315 x += other.x;
316 y += other.y;
317 return *this;
318 }
319
328 constexpr Point& operator-=(const Point& other)
329 {
330 x -= other.x;
331 y -= other.y;
332 return *this;
333 }
334
343 constexpr Point& operator/=(int value)
344 {
345 x /= value;
346 y /= value;
347 return *this;
348 }
349
358 constexpr Point& operator/=(const Point& other)
359 {
360 x /= other.x;
361 y /= other.y;
362 return *this;
363 }
364
373 constexpr Point& operator%=(int value)
374 {
375 x %= value;
376 y %= value;
377 return *this;
378 }
379
389 constexpr Point& operator%=(const Point& other)
390 {
391 x %= other.x;
392 y %= other.y;
393 return *this;
394 }
395
404 constexpr Point& operator*=(int value)
405 {
406 x *= value;
407 y *= value;
408 return *this;
409 }
410
419 constexpr Point& operator*=(const Point& other)
420 {
421 x *= other.x;
422 y *= other.y;
423 return *this;
424 }
425
435 constexpr Point GetClamped(const Rect& rect) const;
436
446 constexpr Point& Clamp(const Rect& rect);
447
456 constexpr Point GetWrapped(const Rect& rect) const;
457
466 constexpr Point& Wrap(const Rect& rect);
467
473 constexpr operator FPoint() const;
474};
475
486struct FPoint : SDL_FPoint
487{
493 constexpr FPoint(const SDL_FPoint& p = {})
494 : SDL_FPoint(p)
495 {
496 }
497
504 constexpr FPoint(float x, float y)
505 : SDL_FPoint{x, y}
506 {
507 }
508
512 constexpr bool operator==(const FPoint& other) const
513 {
514 return x == other.x && y == other.y;
515 }
516
520 constexpr bool operator==(const SDL_FPoint& p) const
521 {
522 return operator==(FPoint(p));
523 }
524
530 constexpr explicit operator bool() const { return x != 0 && y != 0; }
531
537 constexpr float GetX() const { return x; }
538
545 constexpr FPoint& SetX(float newX)
546 {
547 x = newX;
548 return *this;
549 }
550
556 constexpr float GetY() const { return y; }
557
564 constexpr FPoint& SetY(float newY)
565 {
566 y = newY;
567 return *this;
568 }
569
590 constexpr bool IsInRect(const FRect& r) const;
591
598 constexpr FPoint operator-() const { return FPoint(-x, -y); }
599
608 constexpr FPoint operator+(const FPoint& other) const
609 {
610 return FPoint(x + other.x, y + other.y);
611 }
612
621 constexpr FPoint operator-(const FPoint& other) const
622 {
623 return FPoint(x - other.x, y - other.y);
624 }
625
635 constexpr FPoint operator/(float value) const
636 {
637 return FPoint(x / value, y / value);
638 }
639
649 constexpr FPoint operator/(const FPoint& other) const
650 {
651 return FPoint(x / other.x, y / other.y);
652 }
653
664 constexpr FPoint operator*(float value) const
665 {
666 return FPoint(x * value, y * value);
667 }
668
679 constexpr FPoint operator*(const FPoint& other) const
680 {
681 return FPoint(x * other.x, y * other.y);
682 }
683
692 constexpr FPoint& operator+=(const FPoint& other)
693 {
694 x += other.x;
695 y += other.y;
696 return *this;
697 }
698
707 constexpr FPoint& operator-=(const FPoint& other)
708 {
709 x -= other.x;
710 y -= other.y;
711 return *this;
712 }
713
722 constexpr FPoint& operator/=(float value)
723 {
724 x /= value;
725 y /= value;
726 return *this;
727 }
728
737 constexpr FPoint& operator/=(const FPoint& other)
738 {
739 x /= other.x;
740 y /= other.y;
741 return *this;
742 }
743
752 constexpr FPoint& operator*=(float value)
753 {
754 x *= value;
755 y *= value;
756 return *this;
757 }
758
767 constexpr FPoint& operator*=(const FPoint& other)
768 {
769 x *= other.x;
770 y *= other.y;
771 return *this;
772 }
773
783 constexpr FPoint GetClamped(const FRect& rect) const;
784
794 constexpr FPoint& Clamp(const FRect& rect);
795
804 constexpr FPoint GetWrapped(const FRect& rect) const;
805
814 constexpr FPoint& Wrap(const FRect& rect);
815};
816
832struct Rect : SDL_Rect
833{
839 constexpr Rect(const SDL_Rect& r = {})
840 : SDL_Rect(r)
841 {
842 }
843
852 constexpr Rect(int x, int y, int w, int h)
853 : SDL_Rect({x, y, w, h})
854 {
855 }
856
863 constexpr Rect(const SDL_Point& corner, const SDL_Point& size)
864 : Rect{corner.x, corner.y, size.x, size.y}
865 {
866 }
867
871 constexpr bool operator==(const Rect& other) const { return Equal(other); }
872
876 constexpr bool operator==(const SDL_Rect& r) const
877 {
878 return operator==(Rect(r));
879 }
880
884 constexpr operator bool() const { return !Empty(); }
885
892 constexpr int GetX() const { return x; }
893
900 constexpr Rect& SetX(int newX)
901 {
902 x = newX;
903 return *this;
904 }
905
912 constexpr int GetY() const { return y; }
913
920 constexpr Rect& SetY(int newY)
921 {
922 y = newY;
923 return *this;
924 }
925
932 constexpr int GetW() const { return w; }
933
940 constexpr Rect& SetW(int newW)
941 {
942 w = newW;
943 return *this;
944 }
945
952 constexpr int GetH() const { return h; }
953
960 constexpr Rect& SetH(int newH)
961 {
962 h = newH;
963 return *this;
964 }
965
984 OptionalRef<const SDL_Rect> clip = std::nullopt)
985 {
986 Rect result;
987 if (SDL_GetRectEnclosingPoints(
988 points.data(), points.size(), clip, &result)) {
989 return result;
990 }
991 return {};
992 }
993
1003 static constexpr Rect FromCenter(int cx, int cy, int w, int h)
1004 {
1005 return Rect(cx - w / 2, cy - h / 2, w, h);
1006 }
1007
1015 static constexpr Rect FromCenter(const Point& center, const Point& size)
1016 {
1017 return Rect(center - size / 2, size);
1018 }
1019
1029 static constexpr Rect FromCorners(int x1, int y1, int x2, int y2)
1030 {
1031 return Rect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
1032 }
1033
1041 static constexpr Rect FromCorners(const Point& p1, const Point& p2)
1042 {
1043 return Rect(p1, p2 - p1 + Point(1, 1));
1044 }
1045
1052 constexpr int GetX2() const { return x + w - 1; }
1053
1064 constexpr Rect& SetX2(int x2)
1065 {
1066 w = x2 - x + 1;
1067 return *this;
1068 }
1069
1076 constexpr int GetY2() const { return y + h - 1; }
1077
1088 constexpr Rect& SetY2(int y2)
1089 {
1090 h = y2 - y + 1;
1091 return *this;
1092 }
1093
1100 constexpr Point GetTopLeft() const { return Point(x, y); }
1101
1108 constexpr Point GetTopRight() const { return Point(GetX2(), y); }
1109
1116 constexpr Point GetBottomLeft() const { return Point(x, GetY2()); }
1117
1124 constexpr Point GetBottomRight() const { return Point(GetX2(), GetY2()); }
1125
1132 constexpr Point GetSize() const { return Point(w, h); }
1133
1140 constexpr Point GetCentroid() const { return Point(x + w / 2, y + h / 2); }
1141
1159 bool IntersectLine(int* X1, int* Y1, int* X2, int* Y2) const
1160 {
1161 return SDL_GetRectAndLineIntersection(this, X1, Y1, X2, Y2);
1162 }
1163
1180 bool IntersectLine(Point* p1, Point* p2) const
1181 {
1182 return IntersectLine(p1 ? &p1->x : nullptr,
1183 p1 ? &p1->y : nullptr,
1184 p2 ? &p2->x : nullptr,
1185 p2 ? &p2->y : nullptr);
1186 }
1187
1198 constexpr operator FRect() const;
1199
1203 constexpr operator SDL_FRect() const
1204 {
1205 return {float(x), float(y), float(w), float(h)};
1206 }
1207
1225 constexpr bool Empty() const { return SDL_RectEmpty(this); }
1226
1245 constexpr bool Equal(const Rect& other) const
1246 {
1247 return SDL_RectsEqual(this, &other);
1248 }
1249
1258 constexpr bool Contains(const Point& p) const
1259 {
1260 return SDL_PointInRect(&p, this);
1261 }
1262
1271 constexpr bool Contains(const Rect& other) const
1272 {
1273 return GetUnion(other) == *this;
1274 }
1275
1288 bool HasIntersection(const Rect& other) const
1289 {
1290 return SDL_HasRectIntersection(this, &other);
1291 }
1292
1306 constexpr std::optional<Rect> GetIntersection(const Rect& other) const
1307 {
1308 if (Rect result; SDL_GetRectIntersection(this, &other, &result)) {
1309 return result;
1310 }
1311 return std::nullopt;
1312 }
1313
1323 constexpr Rect GetUnion(const Rect& other) const
1324 {
1325 Rect result;
1326 CheckError(SDL_GetRectUnion(this, &other, &result));
1327 return result;
1328 }
1329
1338 constexpr Rect GetExtension(unsigned int amount) const
1339 {
1340 Rect r = *this;
1341 r.Extend(amount);
1342 return r;
1343 }
1344
1356 constexpr Rect GetExtension(unsigned int hAmount, unsigned int vAmount) const
1357 {
1358 Rect r = *this;
1359 r.Extend(hAmount, vAmount);
1360 return r;
1361 }
1362
1371 constexpr Rect& Extend(unsigned int amount) { return Extend(amount, amount); }
1372
1384 constexpr Rect& Extend(unsigned int hAmount, unsigned int vAmount)
1385 {
1386 x -= hAmount;
1387 y -= vAmount;
1388 w += hAmount * 2;
1389 h += vAmount * 2;
1390 return *this;
1391 }
1392
1401 constexpr Rect operator+(const Point& offset) const
1402 {
1403 return Rect(x + offset.x, y + offset.y, w, h);
1404 }
1405
1414 constexpr Rect operator-(const Point& offset) const
1415 {
1416 return Rect(x - offset.x, y - offset.y, w, h);
1417 }
1418
1427 constexpr Rect& operator+=(const Point& offset)
1428 {
1429 x += offset.x;
1430 y += offset.y;
1431 return *this;
1432 }
1433
1442 constexpr Rect& operator-=(const Point& offset)
1443 {
1444 x -= offset.x;
1445 y -= offset.y;
1446 return *this;
1447 }
1448};
1449
1468struct FRect : SDL_FRect
1469{
1475 constexpr FRect(const SDL_FRect& r = {})
1476 : SDL_FRect{r}
1477 {
1478 }
1479
1488 constexpr FRect(float x, float y, float w, float h)
1489 : SDL_FRect{x, y, w, h}
1490 {
1491 }
1492
1494 constexpr FRect(const SDL_FPoint& corner, const SDL_FPoint& size)
1495 : FRect{corner.x, corner.y, size.x, size.y}
1496 {
1497 }
1498
1502 constexpr bool operator==(const FRect& other) const { return Equal(other); }
1503
1507 constexpr bool operator==(const SDL_FRect& r) const
1508 {
1509 return operator==(FRect(r));
1510 }
1511
1515 constexpr operator bool() const { return !Empty(); }
1516
1523 constexpr float GetX() const { return x; }
1524
1531 constexpr FRect& SetX(float newX)
1532 {
1533 x = newX;
1534 return *this;
1535 }
1536
1543 constexpr float GetY() const { return y; }
1544
1551 constexpr FRect& SetY(float newY)
1552 {
1553 y = newY;
1554 return *this;
1555 }
1556
1563 constexpr float GetW() const { return w; }
1564
1571 constexpr FRect& SetW(float newW)
1572 {
1573 w = newW;
1574 return *this;
1575 }
1576
1583 constexpr float GetH() const { return h; }
1584
1591 constexpr FRect& SetH(float newH)
1592 {
1593 h = newH;
1594 return *this;
1595 }
1596
1616 OptionalRef<const SDL_FRect> clip = std::nullopt)
1617 {
1618 if (FRect result; SDL_GetRectEnclosingPointsFloat(
1619 points.data(), points.size(), clip, &result)) {
1620 return result;
1621 }
1622 return {};
1623 }
1624
1634 static constexpr FRect FromCenter(float cx, float cy, float w, float h)
1635 {
1636 return FRect(cx - w / 2, cy - h / 2, w, h);
1637 }
1638
1646 static constexpr FRect FromCenter(const FPoint& center, const FPoint& size)
1647 {
1648 return FRect(center - size / 2, size);
1649 }
1650
1660 static constexpr FRect FromCorners(float x1, float y1, float x2, float y2)
1661 {
1662 return FRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
1663 }
1664
1672 static constexpr FRect FromCorners(const FPoint& p1, const FPoint& p2)
1673 {
1674 return FRect(p1, p2 - p1 + FPoint(1, 1));
1675 }
1676
1683 constexpr float GetX2() const { return x + w - 1; }
1684
1695 constexpr FRect& SetX2(float x2)
1696 {
1697 w = x2 - x + 1;
1698 return *this;
1699 }
1700
1707 constexpr float GetY2() const { return y + h - 1; }
1708
1719 constexpr FRect& SetY2(float y2)
1720 {
1721 h = y2 - y + 1;
1722 return *this;
1723 }
1724
1731 constexpr FPoint GetTopLeft() const { return FPoint(x, y); }
1732
1739 constexpr FPoint GetTopRight() const { return FPoint(GetX2(), y); }
1740
1747 constexpr FPoint GetBottomLeft() const { return FPoint(x, GetY2()); }
1748
1755 constexpr FPoint GetBottomRight() const { return FPoint(GetX2(), GetY2()); }
1756
1763 constexpr FPoint GetSize() const { return FPoint(w, h); }
1764
1771 constexpr FPoint GetCentroid() const { return FPoint(x + w / 2, y + h / 2); }
1772
1791 bool IntersectLine(float* X1, float* Y1, float* X2, float* Y2) const
1792 {
1793 return SDL_GetRectAndLineIntersectionFloat(this, X1, Y1, X2, Y2);
1794 }
1795
1812 bool IntersectLine(FPoint* p1, FPoint* p2) const
1813 {
1814 return IntersectLine(p1 ? &p1->x : nullptr,
1815 p1 ? &p1->y : nullptr,
1816 p2 ? &p2->x : nullptr,
1817 p2 ? &p2->y : nullptr);
1818 }
1819
1837 constexpr bool Empty() const { return SDL_RectEmptyFloat(this); }
1838
1863 constexpr bool EqualEpsilon(const FRect& other, const float epsilon) const
1864 {
1865 return SDL_RectsEqualEpsilon(this, &other, epsilon);
1866 }
1867
1886 constexpr bool Equal(const FRect& other) const
1887 {
1888 return SDL_RectsEqualFloat(this, &other);
1889 }
1890
1899 constexpr bool Contains(const FPoint& p) const
1900 {
1901 return SDL_PointInRectFloat(&p, this);
1902 }
1903
1912 constexpr bool Contains(const FRect& other) const
1913 {
1914 return GetUnion(other) == *this;
1915 }
1916
1929 bool HasIntersection(const FRect& other) const
1930 {
1931 return SDL_HasRectIntersectionFloat(this, &other);
1932 }
1933
1947 FRect GetIntersection(const FRect& other) const
1948 {
1949 if (FRect result; SDL_GetRectIntersectionFloat(this, &other, &result)) {
1950 return result;
1951 }
1952 return {};
1953 }
1954
1964 FRect GetUnion(const FRect& other) const
1965 {
1966 FRect result;
1967 CheckError(SDL_GetRectUnionFloat(this, &other, &result));
1968 return result;
1969 }
1970
1979 constexpr FRect GetExtension(unsigned int amount) const
1980 {
1981 FRect r = *this;
1982 r.Extend(amount);
1983 return r;
1984 }
1985
1997 constexpr FRect GetExtension(float hAmount, float vAmount) const
1998 {
1999 FRect r = *this;
2000 r.Extend(hAmount, vAmount);
2001 return r;
2002 }
2003
2012 constexpr FRect& Extend(float amount) { return Extend(amount, amount); }
2013
2025 constexpr FRect& Extend(float hAmount, float vAmount)
2026 {
2027 x -= hAmount;
2028 y -= vAmount;
2029 w += hAmount * 2;
2030 h += vAmount * 2;
2031 return *this;
2032 }
2033
2042 constexpr FRect operator+(const FPoint& offset) const
2043 {
2044 return FRect(x + offset.x, y + offset.y, w, h);
2045 }
2046
2055 constexpr FRect operator-(const FPoint& offset) const
2056 {
2057 return FRect(x - offset.x, y - offset.y, w, h);
2058 }
2059
2068 constexpr FRect& operator+=(const FPoint& offset)
2069 {
2070 x += offset.x;
2071 y += offset.y;
2072 return *this;
2073 }
2074
2083 constexpr FRect& operator-=(const FPoint& offset)
2084 {
2085 x -= offset.x;
2086 y -= offset.y;
2087 return *this;
2088 }
2089};
2090
2091constexpr bool Point::IsInRect(const Rect& r) const
2092{
2093 return r.Contains(*this);
2094}
2095
2096constexpr bool FPoint::IsInRect(const FRect& r) const
2097{
2098 return r.Contains(*this);
2099}
2100
2101#pragma region impl
2103
2104constexpr Point::operator FPoint() const { return {float(x), float(y)}; }
2105
2106constexpr FPoint Point::operator/(float value) const
2107{
2108 return FPoint(*this) / value;
2109}
2110constexpr FPoint Point::operator*(float value) const
2111{
2112 return FPoint(*this) * value;
2113}
2114
2115constexpr Point Point::GetClamped(const Rect& rect) const
2116{
2117 Point p = *this;
2118 p.Clamp(rect);
2119 return p;
2120}
2121
2122constexpr Point& Point::Clamp(const Rect& rect)
2123{
2124 if (x < rect.x) x = rect.x;
2125 if (x > rect.GetX2()) x = rect.GetX2();
2126 if (y < rect.y) y = rect.y;
2127 if (y > rect.GetY2()) y = rect.GetY2();
2128 return *this;
2129}
2130
2131constexpr Point Point::GetWrapped(const Rect& rect) const
2132{
2133 Point p = *this;
2134 p.Wrap(rect);
2135 return p;
2136}
2137
2138constexpr Point& Point::Wrap(const Rect& rect)
2139{
2140 if (x < rect.x)
2141 x = rect.x + rect.w - 1 - (rect.x - x + rect.w - 1) % rect.w;
2142 else if (x >= rect.x + rect.w)
2143 x = rect.x + (x - rect.x - rect.w) % rect.w;
2144
2145 if (y < rect.y)
2146 y = rect.y + rect.h - 1 - (rect.y - y + rect.h - 1) % rect.h;
2147 else if (y >= rect.y + rect.h)
2148 y = rect.y + (y - rect.y - rect.h) % rect.h;
2149
2150 return *this;
2151}
2152
2153constexpr FPoint FPoint::GetClamped(const FRect& rect) const
2154{
2155 FPoint p = *this;
2156 p.Clamp(rect);
2157 return p;
2158}
2159
2160constexpr FPoint& FPoint::Clamp(const FRect& rect)
2161{
2162 if (x < rect.x) x = rect.x;
2163 if (x > rect.GetX2()) x = rect.GetX2();
2164 if (y < rect.y) y = rect.y;
2165 if (y > rect.GetY2()) y = rect.GetY2();
2166 return *this;
2167}
2168
2169constexpr FPoint FPoint::GetWrapped(const FRect& rect) const
2170{
2171 FPoint p = *this;
2172 p.Wrap(rect);
2173 return p;
2174}
2175
2176constexpr FPoint& FPoint::Wrap(const FRect& rect)
2177{
2178 if (x < rect.x)
2179 x = rect.x + rect.w - 1 - fmod(rect.x - x + rect.w - 1, rect.w);
2180 else if (x >= rect.x + rect.w)
2181 x = rect.x + fmod(x - rect.x - rect.w, rect.w);
2182
2183 if (y < rect.y)
2184 y = rect.y + rect.h - 1 - fmod(rect.y - y + rect.h - 1, rect.h);
2185 else if (y >= rect.y + rect.h)
2186 y = rect.y + fmod(y - rect.y - rect.h, rect.h);
2187
2188 return *this;
2189}
2190
2191constexpr Rect::operator FRect() const
2192{
2193 return {float(x), float(y), float(w), float(h)};
2194}
2195
2196#pragma endregion impl
2197
2198} // namespace SDL
2199
2200#endif /* SDL3PP_RECT_H_ */
Optional-like shim for references.
Definition SDL3pp_optionalRef.h:20
span-like for empty-derived structs
Definition SDL3pp_spanRef.h:24
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
constexpr bool IsInRect(const Rect &r) const
Determine whether a point resides inside a rectangle.
Definition SDL3pp_rect.h:2091
constexpr bool IsInRect(const FRect &r) const
Determine whether a point resides inside a floating point rectangle.
Definition SDL3pp_rect.h:2096
double fmod(double x, double y)
Return the floating-point remainder of x / y
Definition SDL3pp_stdinc.h:4585
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
The structure that defines a point (using floating point values).
Definition SDL3pp_rect.h:487
constexpr FPoint operator/(const FPoint &other) const
Get point's memberwise division by another point.
Definition SDL3pp_rect.h:649
constexpr FPoint(float x, float y)
Constructs from its fields.
Definition SDL3pp_rect.h:504
constexpr FPoint & Wrap(const FRect &rect)
Wrap point coordinates within a specified rect.
Definition SDL3pp_rect.h:2176
constexpr float GetX() const
Get the x coordinate.
Definition SDL3pp_rect.h:537
constexpr float GetY() const
Get the y coordinate.
Definition SDL3pp_rect.h:556
constexpr FPoint operator-() const
Get point's memberwise negation.
Definition SDL3pp_rect.h:598
constexpr FPoint & operator/=(const FPoint &other)
Memberwise divide by another point.
Definition SDL3pp_rect.h:737
constexpr FPoint(const SDL_FPoint &p={})
Wraps FPoint.
Definition SDL3pp_rect.h:493
constexpr FPoint operator/(float value) const
Get point's memberwise division by an float.
Definition SDL3pp_rect.h:635
constexpr FPoint operator-(const FPoint &other) const
Get point's memberwise subtraction with another point.
Definition SDL3pp_rect.h:621
constexpr FPoint operator*(float value) const
Get point's memberwise multiplication by an float.
Definition SDL3pp_rect.h:664
constexpr FPoint & operator/=(float value)
Memberwise divide by an float.
Definition SDL3pp_rect.h:722
constexpr FPoint & SetX(float newX)
Set the x coordinate.
Definition SDL3pp_rect.h:545
constexpr FPoint GetClamped(const FRect &rect) const
Get a point with coordinates modified so it fits into a given rect.
Definition SDL3pp_rect.h:2153
constexpr bool operator==(const SDL_FPoint &p) const
Compares with the underlying type.
Definition SDL3pp_rect.h:520
constexpr FPoint & operator*=(const FPoint &other)
Memberwise multiply by another point.
Definition SDL3pp_rect.h:767
constexpr FPoint GetWrapped(const FRect &rect) const
Get a point wrapped within a specified rect.
Definition SDL3pp_rect.h:2169
constexpr FPoint operator+(const FPoint &other) const
Get point's memberwise addition with another point.
Definition SDL3pp_rect.h:608
constexpr FPoint & SetY(float newY)
Set the y coordinate.
Definition SDL3pp_rect.h:564
constexpr FPoint & Clamp(const FRect &rect)
Clamp point coordinates to make it fit into a given rect.
Definition SDL3pp_rect.h:2160
constexpr FPoint & operator*=(float value)
Memberwise multiply by an float.
Definition SDL3pp_rect.h:752
constexpr FPoint & operator-=(const FPoint &other)
Memberwise subtract another point.
Definition SDL3pp_rect.h:707
constexpr bool operator==(const FPoint &other) const
Default comparison operator.
Definition SDL3pp_rect.h:512
constexpr FPoint operator*(const FPoint &other) const
Get point's memberwise multiplication by another point.
Definition SDL3pp_rect.h:679
constexpr FPoint & operator+=(const FPoint &other)
Memberwise add another point.
Definition SDL3pp_rect.h:692
A rectangle, with the origin at the upper left (using floating point values).
Definition SDL3pp_rect.h:1469
constexpr float GetH() const
Get height of the rect.
Definition SDL3pp_rect.h:1583
constexpr bool EqualEpsilon(const FRect &other, const float epsilon) const
Determine whether two floating point rectangles are equal, within some given epsilon.
Definition SDL3pp_rect.h:1863
FRect GetIntersection(const FRect &other) const
Calculate the intersection of two rectangles with float precision.
Definition SDL3pp_rect.h:1947
bool HasIntersection(const FRect &other) const
Determine whether two rectangles intersect.
Definition SDL3pp_rect.h:1929
constexpr bool Equal(const FRect &other) const
Determine whether two rectangles are equal.
Definition SDL3pp_rect.h:1886
constexpr FRect & Extend(float hAmount, float vAmount)
Extend a rect by specified amount of pixels.
Definition SDL3pp_rect.h:2025
static constexpr FRect FromCenter(const FPoint &center, const FPoint &size)
Construct the rect from given center coordinates and size.
Definition SDL3pp_rect.h:1646
constexpr FRect & SetH(float newH)
Set the height of the rect.
Definition SDL3pp_rect.h:1591
constexpr FRect & SetW(float newW)
Set the width of the rect.
Definition SDL3pp_rect.h:1571
constexpr bool Contains(const FPoint &p) const
Check whether the rect contains given point.
Definition SDL3pp_rect.h:1899
constexpr float GetY() const
Get top y coordinate.
Definition SDL3pp_rect.h:1543
constexpr FRect operator+(const FPoint &offset) const
Get rectangle moved by a given offset.
Definition SDL3pp_rect.h:2042
constexpr bool operator==(const FRect &other) const
Definition SDL3pp_rect.h:1502
constexpr FPoint GetTopRight() const
Get top right corner of the rect.
Definition SDL3pp_rect.h:1739
constexpr FRect operator-(const FPoint &offset) const
Get rectangle moved by an opposite of given offset.
Definition SDL3pp_rect.h:2055
constexpr float GetW() const
Get width of the rect.
Definition SDL3pp_rect.h:1563
constexpr FRect & operator+=(const FPoint &offset)
Move by then given offset.
Definition SDL3pp_rect.h:2068
bool IntersectLine(FPoint *p1, FPoint *p2) const
Calculate the intersection of a rectangle and line segment.
Definition SDL3pp_rect.h:1812
constexpr bool operator==(const SDL_FRect &r) const
Compares with the underlying type.
Definition SDL3pp_rect.h:1507
constexpr FRect & operator-=(const FPoint &offset)
Move by an opposite of the given offset.
Definition SDL3pp_rect.h:2083
constexpr FPoint GetBottomRight() const
Get bottom right corner of the rect.
Definition SDL3pp_rect.h:1755
constexpr FPoint GetBottomLeft() const
Get bottom left corner of the rect.
Definition SDL3pp_rect.h:1747
constexpr bool Empty() const
Determine whether a rectangle has no area.
Definition SDL3pp_rect.h:1837
constexpr float GetX2() const
Get X coordinate of the rect second corner.
Definition SDL3pp_rect.h:1683
constexpr FRect GetExtension(unsigned int amount) const
Get a rect extended by specified amount of pixels.
Definition SDL3pp_rect.h:1979
static constexpr FRect FromCenter(float cx, float cy, float w, float h)
Construct the rect from given center coordinates, width and height.
Definition SDL3pp_rect.h:1634
constexpr float GetY2() const
Get Y coordinate of the rect second corner.
Definition SDL3pp_rect.h:1707
constexpr FRect & SetY2(float y2)
Set Y coordinate of the rect second corner.
Definition SDL3pp_rect.h:1719
constexpr FRect & SetY(float newY)
Set the top y coordinate.
Definition SDL3pp_rect.h:1551
constexpr FRect(const SDL_FRect &r={})
Wraps FRect.
Definition SDL3pp_rect.h:1475
constexpr FRect & SetX2(float x2)
Set X coordinate of the rect second corner.
Definition SDL3pp_rect.h:1695
static constexpr FRect FromCorners(float x1, float y1, float x2, float y2)
Construct the rect from given corners coordinates.
Definition SDL3pp_rect.h:1660
constexpr FRect(const SDL_FPoint &corner, const SDL_FPoint &size)
Constructs from top-left corner plus size.
Definition SDL3pp_rect.h:1494
bool IntersectLine(float *X1, float *Y1, float *X2, float *Y2) const
Calculate the intersection of a rectangle and line segment with float precision.
Definition SDL3pp_rect.h:1791
constexpr FRect & SetX(float newX)
Set the left x coordinate.
Definition SDL3pp_rect.h:1531
constexpr FRect & Extend(float amount)
Extend a rect by specified amount of pixels.
Definition SDL3pp_rect.h:2012
static constexpr FRect FromCorners(const FPoint &p1, const FPoint &p2)
Construct the rect from given centers coordinates.
Definition SDL3pp_rect.h:1672
static FRect GetEnclosingPoints(SpanRef< const SDL_FPoint > points, OptionalRef< const SDL_FRect > clip=std::nullopt)
Calculate a minimal rectangle enclosing a set of points with float precision.
Definition SDL3pp_rect.h:1614
FRect GetUnion(const FRect &other) const
Calculate the union of two rectangles with float precision.
Definition SDL3pp_rect.h:1964
constexpr FRect GetExtension(float hAmount, float vAmount) const
Get a rect extended by specified amount of pixels.
Definition SDL3pp_rect.h:1997
constexpr FPoint GetCentroid() const
Get centroid of the rect.
Definition SDL3pp_rect.h:1771
constexpr FRect(float x, float y, float w, float h)
Constructs from its fields.
Definition SDL3pp_rect.h:1488
constexpr FPoint GetTopLeft() const
Get top left corner of the rect.
Definition SDL3pp_rect.h:1731
constexpr FPoint GetSize() const
Get size of the rect.
Definition SDL3pp_rect.h:1763
constexpr bool Contains(const FRect &other) const
Check whether the rect contains given point.
Definition SDL3pp_rect.h:1912
constexpr float GetX() const
Get left x coordinate.
Definition SDL3pp_rect.h:1523
The structure that defines a point (using integers).
Definition SDL3pp_rect.h:46
constexpr Point & operator/=(int value)
Memberwise divide by an integer.
Definition SDL3pp_rect.h:343
constexpr Point & operator%=(const Point &other)
Memberwise remainder from division by another point.
Definition SDL3pp_rect.h:389
constexpr Point operator/(int value) const
Get point's memberwise division by an integer.
Definition SDL3pp_rect.h:203
constexpr Point GetClamped(const Rect &rect) const
Get a point with coordinates modified so it fits into a given rect.
Definition SDL3pp_rect.h:2115
constexpr Point operator-(const Point &other) const
Get point's memberwise subtraction with another point.
Definition SDL3pp_rect.h:189
constexpr int GetX() const
Get x coordinate.
Definition SDL3pp_rect.h:104
constexpr Point operator+(const Point &other) const
Get point's memberwise addition with another point.
Definition SDL3pp_rect.h:176
constexpr Point & Clamp(const Rect &rect)
Clamp point coordinates to make it fit into a given rect.
Definition SDL3pp_rect.h:2122
constexpr Point operator*(const Point &other) const
Get point's memberwise multiplication by another point.
Definition SDL3pp_rect.h:300
constexpr Point operator%(int value) const
Get point's memberwise remainder from division by an integer.
Definition SDL3pp_rect.h:243
constexpr Point & operator*=(const Point &other)
Memberwise multiply by another point.
Definition SDL3pp_rect.h:419
constexpr Point & SetX(int newX)
Set the x coordinate.
Definition SDL3pp_rect.h:112
constexpr bool operator==(const SDL_Point &p) const
Compares with the underlying type.
Definition SDL3pp_rect.h:87
constexpr Point & operator-=(const Point &other)
Memberwise subtract another point.
Definition SDL3pp_rect.h:328
constexpr Point(const SDL_Point &p={})
Wraps Point.
Definition SDL3pp_rect.h:52
constexpr Point(const SDL_FPoint &p)
Explicit conversion from FPoint.
Definition SDL3pp_rect.h:71
constexpr Point operator*(int value) const
Get point's memberwise multiplication by an integer.
Definition SDL3pp_rect.h:273
constexpr Point & operator/=(const Point &other)
Memberwise divide by another point.
Definition SDL3pp_rect.h:358
constexpr bool operator==(const Point &other) const
Default comparison operator.
Definition SDL3pp_rect.h:79
constexpr Point operator%(const Point &other) const
Get point's memberwise remainder from division by another point.
Definition SDL3pp_rect.h:258
constexpr Point GetWrapped(const Rect &rect) const
Get a point wrapped within a specified rect.
Definition SDL3pp_rect.h:2131
constexpr Point(int x, int y)
Constructs from its fields.
Definition SDL3pp_rect.h:63
constexpr Point & Wrap(const Rect &rect)
Wrap point coordinates within a specified rect.
Definition SDL3pp_rect.h:2138
constexpr int GetY() const
Get y coordinate.
Definition SDL3pp_rect.h:124
constexpr Point & SetY(int newY)
Set the y.
Definition SDL3pp_rect.h:132
constexpr Point & operator%=(int value)
Memberwise remainder from division by an integer.
Definition SDL3pp_rect.h:373
constexpr Point operator/(const Point &other) const
Get point's memberwise division by another point.
Definition SDL3pp_rect.h:228
constexpr Point & operator+=(const Point &other)
Memberwise add another point.
Definition SDL3pp_rect.h:313
constexpr Point operator-() const
Get point's memberwise negation.
Definition SDL3pp_rect.h:166
constexpr Point & operator*=(int value)
Memberwise multiply by an integer.
Definition SDL3pp_rect.h:404
A rectangle, with the origin at the upper left (using integers).
Definition SDL3pp_rect.h:833
static constexpr Rect FromCenter(int cx, int cy, int w, int h)
Construct the rect from given center coordinates, width and height.
Definition SDL3pp_rect.h:1003
constexpr bool Equal(const Rect &other) const
Determine whether two rectangles are equal.
Definition SDL3pp_rect.h:1245
constexpr int GetX() const
Get left x coordinate.
Definition SDL3pp_rect.h:892
constexpr Rect & operator-=(const Point &offset)
Move by an opposite of the given offset.
Definition SDL3pp_rect.h:1442
constexpr int GetW() const
Get width of the rect.
Definition SDL3pp_rect.h:932
static constexpr Rect FromCenter(const Point &center, const Point &size)
Construct the rect from given center coordinates and size.
Definition SDL3pp_rect.h:1015
constexpr Rect GetExtension(unsigned int hAmount, unsigned int vAmount) const
Get a rect extended by specified amount of pixels.
Definition SDL3pp_rect.h:1356
constexpr Rect(int x, int y, int w, int h)
Constructs from its fields.
Definition SDL3pp_rect.h:852
constexpr Rect(const SDL_Rect &r={})
Wraps Rect.
Definition SDL3pp_rect.h:839
constexpr Rect & SetY(int newY)
Set the top y coordinate.
Definition SDL3pp_rect.h:920
constexpr Point GetTopLeft() const
Get top left corner of the rect.
Definition SDL3pp_rect.h:1100
constexpr bool Contains(const Point &p) const
Check whether the rect contains given point.
Definition SDL3pp_rect.h:1258
constexpr std::optional< Rect > GetIntersection(const Rect &other) const
Calculate the intersection of two rectangles.
Definition SDL3pp_rect.h:1306
constexpr Rect & Extend(unsigned int hAmount, unsigned int vAmount)
Extend a rect by specified amount of pixels.
Definition SDL3pp_rect.h:1384
constexpr bool operator==(const SDL_Rect &r) const
Compares with the underlying type.
Definition SDL3pp_rect.h:876
constexpr Rect operator+(const Point &offset) const
Get rectangle moved by a given offset.
Definition SDL3pp_rect.h:1401
bool IntersectLine(Point *p1, Point *p2) const
Calculate the intersection of a rectangle and line segment.
Definition SDL3pp_rect.h:1180
constexpr bool Empty() const
Determine whether a rectangle has no area.
Definition SDL3pp_rect.h:1225
constexpr Rect & operator+=(const Point &offset)
Move by then given offset.
Definition SDL3pp_rect.h:1427
constexpr bool operator==(const Rect &other) const
Definition SDL3pp_rect.h:871
constexpr Rect(const SDL_Point &corner, const SDL_Point &size)
Construct from offset and size.
Definition SDL3pp_rect.h:863
constexpr Rect GetExtension(unsigned int amount) const
Get a rect extended by specified amount of pixels.
Definition SDL3pp_rect.h:1338
constexpr Rect & Extend(unsigned int amount)
Extend a rect by specified amount of pixels.
Definition SDL3pp_rect.h:1371
constexpr Rect GetUnion(const Rect &other) const
Calculate the union of two rectangles.
Definition SDL3pp_rect.h:1323
constexpr Rect & SetW(int newW)
Set the width of the rect.
Definition SDL3pp_rect.h:940
static Rect GetEnclosingPoints(SpanRef< const SDL_Point > points, OptionalRef< const SDL_Rect > clip=std::nullopt)
Calculate a minimal rectangle enclosing a set of points.
Definition SDL3pp_rect.h:982
constexpr Point GetCentroid() const
Get centroid of the rect.
Definition SDL3pp_rect.h:1140
constexpr Point GetBottomLeft() const
Get bottom left corner of the rect.
Definition SDL3pp_rect.h:1116
constexpr int GetH() const
Get height of the rect.
Definition SDL3pp_rect.h:952
constexpr Rect & SetX2(int x2)
Set X coordinate of the rect second corner.
Definition SDL3pp_rect.h:1064
constexpr Rect & SetH(int newH)
Set the height of the rect.
Definition SDL3pp_rect.h:960
static constexpr Rect FromCorners(int x1, int y1, int x2, int y2)
Construct the rect from given corners coordinates.
Definition SDL3pp_rect.h:1029
constexpr Point GetSize() const
Get size of the rect.
Definition SDL3pp_rect.h:1132
constexpr Rect operator-(const Point &offset) const
Get rectangle moved by an opposite of given offset.
Definition SDL3pp_rect.h:1414
constexpr Point GetBottomRight() const
Get bottom right corner of the rect.
Definition SDL3pp_rect.h:1124
constexpr int GetY2() const
Get Y coordinate of the rect second corner.
Definition SDL3pp_rect.h:1076
static constexpr Rect FromCorners(const Point &p1, const Point &p2)
Construct the rect from given centers coordinates.
Definition SDL3pp_rect.h:1041
bool HasIntersection(const Rect &other) const
Determine whether two rectangles intersect.
Definition SDL3pp_rect.h:1288
constexpr int GetY() const
Get top y coordinate.
Definition SDL3pp_rect.h:912
constexpr Rect & SetX(int newX)
Set the left x coordinate.
Definition SDL3pp_rect.h:900
constexpr bool Contains(const Rect &other) const
Check whether the rect contains given point.
Definition SDL3pp_rect.h:1271
constexpr Rect & SetY2(int y2)
Set Y coordinate of the rect second corner.
Definition SDL3pp_rect.h:1088
bool IntersectLine(int *X1, int *Y1, int *X2, int *Y2) const
Calculate the intersection of a rectangle and line segment.
Definition SDL3pp_rect.h:1159
constexpr Point GetTopRight() const
Get top right corner of the rect.
Definition SDL3pp_rect.h:1108
constexpr int GetX2() const
Get X coordinate of the rect second corner.
Definition SDL3pp_rect.h:1052