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 <SDL3/SDL_rect.h>
5#include "SDL3pp_error.h"
6#include "SDL3pp_optionalRef.h"
7#include "SDL3pp_spanRef.h"
8#include "SDL3pp_stdinc.h"
9
10namespace SDL {
11
22using PointRaw = SDL_Point;
23
24// Forward decl
25struct Point;
26
28using FPointRaw = SDL_FPoint;
29
30// Forward decl
31struct FPoint;
32
34using RectRaw = SDL_Rect;
35
36// Forward decl
37struct Rect;
38
40using FRectRaw = SDL_FRect;
41
42// Forward decl
43struct FRect;
44
46constexpr bool operator==(const PointRaw& lhs, const PointRaw& rhs) noexcept
47{
48 return lhs.x == rhs.x && lhs.y == rhs.y;
49}
50
52constexpr bool operator==(const FPointRaw& lhs, const FPointRaw& rhs) noexcept
53{
54 return lhs.x == rhs.x && lhs.y == rhs.y;
55}
56
58inline bool operator==(const RectRaw& lhs, const RectRaw& rhs) noexcept
59{
60 return SDL_RectsEqual(&lhs, &rhs);
61}
62
64inline bool operator==(const FRectRaw& lhs, const FRectRaw& rhs) noexcept
65{
66 return SDL_RectsEqualFloat(&lhs, &rhs);
67}
68
83{
89 constexpr Point(const PointRaw& p = {}) noexcept
90 : PointRaw(p)
91 {
92 }
93
100 constexpr Point(int x, int y) noexcept
101 : PointRaw{x, y}
102 {
103 }
104
110 constexpr explicit Point(const FPointRaw& p)
111 : SDL_Point{int(p.x), int(p.y)}
112 {
113 }
114
120 constexpr explicit operator bool() const noexcept
121 {
122 return *this != PointRaw{};
123 }
124
130 constexpr int GetX() const noexcept { return x; }
131
138 constexpr Point& SetX(int newX) noexcept
139 {
140 x = newX;
141 return *this;
142 }
143
149 constexpr int GetY() const noexcept { return y; }
150
157 constexpr Point& SetY(int newY) noexcept
158 {
159 y = newY;
160 return *this;
161 }
162
183 bool InRect(const RectRaw& r) const;
184
191 constexpr Point operator-() const { return Point(-x, -y); }
192
201 constexpr Point operator+(const Point& other) const
202 {
203 return Point(x + other.x, y + other.y);
204 }
205
214 constexpr Point operator-(const Point& other) const
215 {
216 return Point(x - other.x, y - other.y);
217 }
218
228 constexpr Point operator/(int value) const
229 {
230 return Point(x / value, y / value);
231 }
232
242 constexpr FPoint operator/(float value) const;
243
253 constexpr Point operator/(const Point& other) const
254 {
255 return Point(x / other.x, y / other.y);
256 }
257
268 constexpr Point operator%(int value) const
269 {
270 return Point(x % value, y % value);
271 }
272
283 constexpr Point operator%(const Point& other) const
284 {
285 return Point(x % other.x, y % other.y);
286 }
287
298 constexpr Point operator*(int value) const
299 {
300 return Point(x * value, y * value);
301 }
302
313 constexpr FPoint operator*(float value) const;
314
325 constexpr Point operator*(const Point& other) const
326 {
327 return Point(x * other.x, y * other.y);
328 }
329
338 constexpr Point& operator+=(const Point& other)
339 {
340 x += other.x;
341 y += other.y;
342 return *this;
343 }
344
353 constexpr Point& operator-=(const Point& other)
354 {
355 x -= other.x;
356 y -= other.y;
357 return *this;
358 }
359
368 constexpr Point& operator/=(int value)
369 {
370 x /= value;
371 y /= value;
372 return *this;
373 }
374
383 constexpr Point& operator/=(const Point& other)
384 {
385 x /= other.x;
386 y /= other.y;
387 return *this;
388 }
389
398 constexpr Point& operator%=(int value)
399 {
400 x %= value;
401 y %= value;
402 return *this;
403 }
404
414 constexpr Point& operator%=(const Point& other)
415 {
416 x %= other.x;
417 y %= other.y;
418 return *this;
419 }
420
429 constexpr Point& operator*=(int value)
430 {
431 x *= value;
432 y *= value;
433 return *this;
434 }
435
444 constexpr Point& operator*=(const Point& other)
445 {
446 x *= other.x;
447 y *= other.y;
448 return *this;
449 }
450
460 constexpr Point GetClamped(const Rect& rect) const;
461
471 constexpr Point& Clamp(const Rect& rect);
472
481 constexpr Point GetWrapped(const Rect& rect) const;
482
491 constexpr Point& Wrap(const Rect& rect);
492
498 constexpr operator FPoint() const;
499};
500
512{
518 constexpr FPoint(const FPointRaw& p = {}) noexcept
519 : FPointRaw(p)
520 {
521 }
522
529 constexpr FPoint(float x, float y) noexcept
530 : FPointRaw{x, y}
531 {
532 }
533
539 constexpr explicit operator bool() const noexcept
540 {
541 return *this != FPointRaw{};
542 }
543
549 constexpr float GetX() const noexcept { return x; }
550
557 constexpr FPoint& SetX(float newX) noexcept
558 {
559 x = newX;
560 return *this;
561 }
562
568 constexpr float GetY() const noexcept { return y; }
569
576 constexpr FPoint& SetY(float newY) noexcept
577 {
578 y = newY;
579 return *this;
580 }
581
602 bool InRect(const FRectRaw& r) const;
603
610 constexpr FPoint operator-() const { return FPoint(-x, -y); }
611
620 constexpr FPoint operator+(const FPoint& other) const
621 {
622 return FPoint(x + other.x, y + other.y);
623 }
624
633 constexpr FPoint operator-(const FPoint& other) const
634 {
635 return FPoint(x - other.x, y - other.y);
636 }
637
647 constexpr FPoint operator/(float value) const
648 {
649 return FPoint(x / value, y / value);
650 }
651
661 constexpr FPoint operator/(const FPoint& other) const
662 {
663 return FPoint(x / other.x, y / other.y);
664 }
665
676 constexpr FPoint operator*(float value) const
677 {
678 return FPoint(x * value, y * value);
679 }
680
691 constexpr FPoint operator*(const FPoint& other) const
692 {
693 return FPoint(x * other.x, y * other.y);
694 }
695
704 constexpr FPoint& operator+=(const FPoint& other)
705 {
706 x += other.x;
707 y += other.y;
708 return *this;
709 }
710
719 constexpr FPoint& operator-=(const FPoint& other)
720 {
721 x -= other.x;
722 y -= other.y;
723 return *this;
724 }
725
734 constexpr FPoint& operator/=(float value)
735 {
736 x /= value;
737 y /= value;
738 return *this;
739 }
740
749 constexpr FPoint& operator/=(const FPoint& other)
750 {
751 x /= other.x;
752 y /= other.y;
753 return *this;
754 }
755
764 constexpr FPoint& operator*=(float value)
765 {
766 x *= value;
767 y *= value;
768 return *this;
769 }
770
779 constexpr FPoint& operator*=(const FPoint& other)
780 {
781 x *= other.x;
782 y *= other.y;
783 return *this;
784 }
785
795 constexpr FPoint GetClamped(const FRect& rect) const;
796
806 constexpr FPoint& Clamp(const FRect& rect);
807
816 constexpr FPoint GetWrapped(const FRect& rect) const;
817
826 constexpr FPoint& Wrap(const FRect& rect);
827};
828
844struct Rect : RectRaw
845{
851 constexpr Rect(const RectRaw& r = {}) noexcept
852 : RectRaw(r)
853 {
854 }
855
864 constexpr Rect(int x, int y, int w, int h) noexcept
865 : RectRaw{x, y, w, h}
866 {
867 }
868
875 constexpr Rect(const PointRaw& corner, const PointRaw& size)
876 : Rect{corner.x, corner.y, size.x, size.y}
877 {
878 }
879
881 bool operator==(const RectRaw& other) const { return Equal(other); }
882
884 bool operator==(const Rect& other) const
885 {
886 return *this == (const RectRaw&)(other);
887 }
888
890 explicit operator bool() const { return !Empty(); }
891
897 constexpr int GetX() const noexcept { return x; }
898
905 constexpr Rect& SetX(int newX) noexcept
906 {
907 x = newX;
908 return *this;
909 }
910
916 constexpr int GetY() const noexcept { return y; }
917
924 constexpr Rect& SetY(int newY) noexcept
925 {
926 y = newY;
927 return *this;
928 }
929
935 constexpr int GetW() const noexcept { return w; }
936
943 constexpr Rect& SetW(int newW) noexcept
944 {
945 w = newW;
946 return *this;
947 }
948
954 constexpr int GetH() const noexcept { return h; }
955
962 constexpr Rect& SetH(int newH) noexcept
963 {
964 h = newH;
965 return *this;
966 }
967
988 OptionalRef<const RectRaw> clip = std::nullopt);
989
999 static constexpr Rect FromCenter(int cx, int cy, int w, int h)
1000 {
1001 return Rect(cx - w / 2, cy - h / 2, w, h);
1002 }
1003
1011 static constexpr Rect FromCenter(Point center, Point size)
1012 {
1013 return Rect(center - size / 2, size);
1014 }
1015
1025 static constexpr Rect FromCorners(int x1, int y1, int x2, int y2)
1026 {
1027 return Rect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
1028 }
1029
1037 static constexpr Rect FromCorners(Point p1, Point p2)
1038 {
1039 return Rect(p1, p2 - p1 + Point(1, 1));
1040 }
1041
1048 constexpr int GetX2() const { return x + w - 1; }
1049
1060 constexpr Rect& SetX2(int x2)
1061 {
1062 w = x2 - x + 1;
1063 return *this;
1064 }
1065
1072 constexpr int GetY2() const { return y + h - 1; }
1073
1084 constexpr Rect& SetY2(int y2)
1085 {
1086 h = y2 - y + 1;
1087 return *this;
1088 }
1089
1096 constexpr Point GetTopLeft() const { return Point(x, y); }
1097
1104 constexpr Point GetTopRight() const { return Point(GetX2(), y); }
1105
1112 constexpr Point GetBottomLeft() const { return Point(x, GetY2()); }
1113
1120 constexpr Point GetBottomRight() const { return Point(GetX2(), GetY2()); }
1121
1128 constexpr Point GetSize() const { return Point(w, h); }
1129
1136 constexpr Point GetCentroid() const { return Point(x + w / 2, y + h / 2); }
1137
1155 {
1156 return GetLineIntersection(p1 ? &p1->x : nullptr,
1157 p1 ? &p1->y : nullptr,
1158 p2 ? &p2->x : nullptr,
1159 p2 ? &p2->y : nullptr);
1160 }
1161
1181 bool GetLineIntersection(int* X1, int* Y1, int* X2, int* Y2) const;
1182
1193 operator SDL_FRect() const;
1194
1196 constexpr operator FRect() const;
1197
1215 bool Empty() const;
1216
1235 bool Equal(const RectRaw& other) const;
1236
1245 bool Contains(const PointRaw& p) const { return SDL_PointInRect(&p, this); }
1246
1255 bool Contains(const RectRaw& other) const { return GetUnion(other) == *this; }
1256
1269 bool HasIntersection(const RectRaw& other) const;
1270
1286 Rect GetIntersection(const RectRaw& other) const;
1287
1299 constexpr Rect GetUnion(const RectRaw& other) const;
1300
1309 constexpr Rect GetExtension(unsigned int amount) const
1310 {
1311 Rect r = *this;
1312 r.Extend(amount);
1313 return r;
1314 }
1315
1327 constexpr Rect GetExtension(unsigned int hAmount, unsigned int vAmount) const
1328 {
1329 Rect r = *this;
1330 r.Extend(hAmount, vAmount);
1331 return r;
1332 }
1333
1342 constexpr Rect& Extend(unsigned int amount) { return Extend(amount, amount); }
1343
1355 constexpr Rect& Extend(unsigned int hAmount, unsigned int vAmount)
1356 {
1357 x -= hAmount;
1358 y -= vAmount;
1359 w += hAmount * 2;
1360 h += vAmount * 2;
1361 return *this;
1362 }
1363
1372 constexpr Rect operator+(const Point& offset) const
1373 {
1374 return Rect(x + offset.x, y + offset.y, w, h);
1375 }
1376
1385 constexpr Rect operator-(const Point& offset) const
1386 {
1387 return Rect(x - offset.x, y - offset.y, w, h);
1388 }
1389
1398 constexpr Rect& operator+=(const Point& offset)
1399 {
1400 x += offset.x;
1401 y += offset.y;
1402 return *this;
1403 }
1404
1413 constexpr Rect& operator-=(const Point& offset)
1414 {
1415 x -= offset.x;
1416 y -= offset.y;
1417 return *this;
1418 }
1419};
1420
1443{
1449 constexpr FRect(const FRectRaw& r = {}) noexcept
1450 : FRectRaw(r)
1451 {
1452 }
1453
1462 constexpr FRect(float x, float y, float w, float h) noexcept
1463 : FRectRaw{x, y, w, h}
1464 {
1465 }
1466
1470 constexpr FRect(const FPointRaw& corner, const FPointRaw& size)
1471 : FRect{corner.x, corner.y, size.x, size.y}
1472 {
1473 }
1474
1476 operator bool() const { return !Empty(); }
1477
1483 constexpr float GetX() const noexcept { return x; }
1484
1491 constexpr FRect& SetX(float newX) noexcept
1492 {
1493 x = newX;
1494 return *this;
1495 }
1496
1502 constexpr float GetY() const noexcept { return y; }
1503
1510 constexpr FRect& SetY(float newY) noexcept
1511 {
1512 y = newY;
1513 return *this;
1514 }
1515
1521 constexpr float GetW() const noexcept { return w; }
1522
1529 constexpr FRect& SetW(float newW) noexcept
1530 {
1531 w = newW;
1532 return *this;
1533 }
1534
1540 constexpr float GetH() const noexcept { return h; }
1541
1548 constexpr FRect& SetH(float newH) noexcept
1549 {
1550 h = newH;
1551 return *this;
1552 }
1553
1575 OptionalRef<const FRectRaw> clip = std::nullopt);
1576
1586 static constexpr FRect FromCenter(float cx, float cy, float w, float h)
1587 {
1588 return FRect(cx - w / 2, cy - h / 2, w, h);
1589 }
1590
1598 static constexpr FRect FromCenter(FPoint center, FPoint size)
1599 {
1600 return FRect(center - size / 2, size);
1601 }
1602
1612 static constexpr FRect FromCorners(float x1, float y1, float x2, float y2)
1613 {
1614 return FRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
1615 }
1616
1624 static constexpr FRect FromCorners(FPoint p1, FPoint p2)
1625 {
1626 return FRect(p1, p2 - p1 + FPoint(1, 1));
1627 }
1628
1635 constexpr float GetX2() const { return x + w - 1; }
1636
1647 constexpr FRect& SetX2(float x2)
1648 {
1649 w = x2 - x + 1;
1650 return *this;
1651 }
1652
1659 constexpr float GetY2() const { return y + h - 1; }
1660
1671 constexpr FRect& SetY2(float y2)
1672 {
1673 h = y2 - y + 1;
1674 return *this;
1675 }
1676
1683 constexpr FPoint GetTopLeft() const { return FPoint(x, y); }
1684
1691 constexpr FPoint GetTopRight() const { return FPoint(GetX2(), y); }
1692
1699 constexpr FPoint GetBottomLeft() const { return FPoint(x, GetY2()); }
1700
1707 constexpr FPoint GetBottomRight() const { return FPoint(GetX2(), GetY2()); }
1708
1715 constexpr FPoint GetSize() const { return FPoint(w, h); }
1716
1723 constexpr FPoint GetCentroid() const { return FPoint(x + w / 2, y + h / 2); }
1724
1745 bool GetLineIntersection(float* X1, float* Y1, float* X2, float* Y2) const;
1746
1763 bool GetLineIntersection(FPoint* p1, FPoint* p2) const
1764 {
1765 return GetLineIntersection(p1 ? &p1->x : nullptr,
1766 p1 ? &p1->y : nullptr,
1767 p2 ? &p2->x : nullptr,
1768 p2 ? &p2->y : nullptr);
1769 }
1770
1788 bool Empty() const;
1789
1814 bool EqualEpsilon(const FRectRaw& other, const float epsilon) const;
1815
1840 bool Equal(const FRectRaw& other) const;
1841
1850 bool Contains(const FPointRaw& p) const
1851 {
1852 return SDL_PointInRectFloat(&p, this);
1853 }
1854
1863 bool Contains(const FRectRaw& other) const
1864 {
1865 return GetUnion(other) == *this;
1866 }
1867
1880 bool HasIntersection(const FRectRaw& other) const;
1881
1897 FRect GetIntersection(const FRectRaw& other) const;
1898
1910 constexpr FRect GetUnion(const FRectRaw& other) const;
1911
1920 constexpr FRect GetExtension(unsigned int amount) const
1921 {
1922 FRect r = *this;
1923 r.Extend(float(amount));
1924 return r;
1925 }
1926
1938 constexpr FRect GetExtension(float hAmount, float vAmount) const
1939 {
1940 FRect r = *this;
1941 r.Extend(hAmount, vAmount);
1942 return r;
1943 }
1944
1953 constexpr FRect& Extend(float amount) { return Extend(amount, amount); }
1954
1966 constexpr FRect& Extend(float hAmount, float vAmount)
1967 {
1968 x -= hAmount;
1969 y -= vAmount;
1970 w += hAmount * 2;
1971 h += vAmount * 2;
1972 return *this;
1973 }
1974
1983 constexpr FRect operator+(const FPoint& offset) const
1984 {
1985 return FRect(x + offset.x, y + offset.y, w, h);
1986 }
1987
1996 constexpr FRect operator-(const FPoint& offset) const
1997 {
1998 return FRect(x - offset.x, y - offset.y, w, h);
1999 }
2000
2009 constexpr FRect& operator+=(const FPoint& offset)
2010 {
2011 x += offset.x;
2012 y += offset.y;
2013 return *this;
2014 }
2015
2024 constexpr FRect& operator-=(const FPoint& offset)
2025 {
2026 x -= offset.x;
2027 y -= offset.y;
2028 return *this;
2029 }
2030};
2031
2042inline FRect RectToFRect(const RectRaw& rect)
2043{
2044 FRect frect;
2045 SDL_RectToFRect(&rect, &frect);
2046 return frect;
2047}
2048
2049inline Rect::operator SDL_FRect() const { return SDL::RectToFRect(*this); }
2050
2072inline bool PointInRect(const PointRaw& p, const RectRaw& r)
2073{
2074 return SDL_PointInRect(&p, &r);
2075}
2076
2077inline bool Point::InRect(const RectRaw& r) const
2078{
2079 return SDL::PointInRect(*this, r);
2080}
2081
2100inline bool RectEmpty(const RectRaw& r) { return SDL_RectEmpty(&r); }
2101
2102inline bool Rect::Empty() const { return SDL::RectEmpty(*this); }
2103
2123inline bool RectsEqual(const RectRaw& a, const RectRaw& b)
2124{
2125 return SDL_RectsEqual(&a, &b);
2126}
2127
2128inline bool Rect::Equal(const RectRaw& other) const
2129{
2130 return SDL::RectsEqual(*this, other);
2131}
2132
2148inline bool HasRectIntersection(const RectRaw& A, const RectRaw& B)
2149{
2150 return SDL_HasRectIntersection(&A, &B);
2151}
2152
2153inline bool Rect::HasIntersection(const RectRaw& other) const
2154{
2155 return SDL::HasRectIntersection(*this, other);
2156}
2157
2174inline Rect GetRectIntersection(const RectRaw& A, const RectRaw& B)
2175{
2176 if (Rect result; SDL_GetRectIntersection(&A, &B, &result)) return result;
2177 return {};
2178}
2179
2180inline Rect Rect::GetIntersection(const RectRaw& other) const
2181{
2182 return SDL::GetRectIntersection(*this, other);
2183}
2184
2197constexpr Rect GetRectUnion(const RectRaw& A, const RectRaw& B)
2198{
2199 Rect r;
2200 CheckError(SDL_GetRectUnion(&A, &B, &r));
2201 return r;
2202}
2203
2204constexpr Rect Rect::GetUnion(const RectRaw& other) const
2205{
2206 return SDL::GetRectUnion(*this, other);
2207}
2208
2227 OptionalRef<const RectRaw> clip = std::nullopt)
2228{
2229 if (Rect result; SDL_GetRectEnclosingPoints(
2230 points.data(), narrowS32(points.size()), clip, &result)) {
2231 return result;
2232 }
2233 return {};
2234}
2235
2238{
2239 return SDL::GetRectEnclosingPoints(points, clip);
2240}
2241
2262inline bool GetRectAndLineIntersection(const RectRaw& rect,
2263 int* X1,
2264 int* Y1,
2265 int* X2,
2266 int* Y2)
2267{
2268 return SDL_GetRectAndLineIntersection(&rect, X1, Y1, X2, Y2);
2269}
2270
2271inline bool Rect::GetLineIntersection(int* X1, int* Y1, int* X2, int* Y2) const
2272{
2273 return SDL::GetRectAndLineIntersection(*this, X1, Y1, X2, Y2);
2274}
2275
2297inline bool PointInRectFloat(const FPointRaw& p, const FRectRaw& r)
2298{
2299 return SDL_PointInRectFloat(&p, &r);
2300}
2301
2302inline bool FPoint::InRect(const FRectRaw& r) const
2303{
2304 return SDL::PointInRectFloat(*this, r);
2305}
2306
2325inline bool RectEmptyFloat(const FRectRaw& r) { return SDL_RectEmptyFloat(&r); }
2326
2327inline bool FRect::Empty() const { return SDL::RectEmptyFloat(*this); }
2328
2354inline bool RectsEqualEpsilon(const FRectRaw& a,
2355 const FRectRaw& b,
2356 const float epsilon)
2357{
2358 return SDL_RectsEqualEpsilon(&a, &b, epsilon);
2359}
2360
2361inline bool FRect::EqualEpsilon(const FRectRaw& other,
2362 const float epsilon) const
2363{
2364 return SDL::RectsEqualEpsilon(*this, other, epsilon);
2365}
2366
2392inline bool RectsEqualFloat(const FRectRaw& a, const FRectRaw& b)
2393{
2394 return SDL_RectsEqualFloat(&a, &b);
2395}
2396
2397inline bool FRect::Equal(const FRectRaw& other) const
2398{
2399 return SDL::RectsEqualFloat(*this, other);
2400}
2401
2417inline bool HasRectIntersectionFloat(const FRectRaw& A, const FRectRaw& B)
2418{
2419 return SDL_HasRectIntersectionFloat(&A, &B);
2420}
2421
2422inline bool FRect::HasIntersection(const FRectRaw& other) const
2423{
2424 return SDL::HasRectIntersectionFloat(*this, other);
2425}
2426
2444{
2445 if (FRect r; SDL_GetRectIntersectionFloat(&A, &B, &r)) return r;
2446 return {};
2447}
2448
2449inline FRect FRect::GetIntersection(const FRectRaw& other) const
2450{
2451 return SDL::GetRectIntersectionFloat(*this, other);
2452}
2453
2467constexpr FRect GetRectUnionFloat(const FRectRaw& A, const FRectRaw& B)
2468{
2469 FRect r;
2470 CheckError(SDL_GetRectUnionFloat(&A, &B, &r));
2471 return r;
2472}
2473
2474constexpr FRect FRect::GetUnion(const FRectRaw& other) const
2475{
2476 return SDL::GetRectUnionFloat(*this, other);
2477}
2478
2497 OptionalRef<const FRectRaw> clip = std::nullopt)
2498{
2499 if (FRect result; SDL_GetRectEnclosingPointsFloat(
2500 points.data(), narrowS32(points.size()), clip, &result)) {
2501 return result;
2502 }
2503 return {};
2504}
2505
2508{
2509 return SDL::GetRectEnclosingPointsFloat(points, clip);
2510}
2511
2534 float* X1,
2535 float* Y1,
2536 float* X2,
2537 float* Y2)
2538{
2539 return SDL_GetRectAndLineIntersectionFloat(&rect, X1, Y1, X2, Y2);
2540}
2541
2542inline bool FRect::GetLineIntersection(float* X1,
2543 float* Y1,
2544 float* X2,
2545 float* Y2) const
2546{
2547 return SDL::GetRectAndLineIntersectionFloat(*this, X1, Y1, X2, Y2);
2548}
2549
2551
2552constexpr Point::operator FPoint() const { return {float(x), float(y)}; }
2553
2554constexpr FPoint Point::operator/(float value) const
2555{
2556 return FPoint(*this) / value;
2557}
2558constexpr FPoint Point::operator*(float value) const
2559{
2560 return FPoint(*this) * value;
2561}
2562
2563constexpr Point Point::GetClamped(const Rect& rect) const
2564{
2565 Point p = *this;
2566 p.Clamp(rect);
2567 return p;
2568}
2569
2570constexpr Point& Point::Clamp(const Rect& rect)
2571{
2572 if (x < rect.x) x = rect.x;
2573 if (x > rect.GetX2()) x = rect.GetX2();
2574 if (y < rect.y) y = rect.y;
2575 if (y > rect.GetY2()) y = rect.GetY2();
2576 return *this;
2577}
2578
2579constexpr Point Point::GetWrapped(const Rect& rect) const
2580{
2581 Point p = *this;
2582 p.Wrap(rect);
2583 return p;
2584}
2585
2586constexpr Point& Point::Wrap(const Rect& rect)
2587{
2588 if (x < rect.x)
2589 x = rect.x + rect.w - 1 - (rect.x - x + rect.w - 1) % rect.w;
2590 else if (x >= rect.x + rect.w)
2591 x = rect.x + (x - rect.x - rect.w) % rect.w;
2592
2593 if (y < rect.y)
2594 y = rect.y + rect.h - 1 - (rect.y - y + rect.h - 1) % rect.h;
2595 else if (y >= rect.y + rect.h)
2596 y = rect.y + (y - rect.y - rect.h) % rect.h;
2597
2598 return *this;
2599}
2600
2601constexpr FPoint FPoint::GetClamped(const FRect& rect) const
2602{
2603 FPoint p = *this;
2604 p.Clamp(rect);
2605 return p;
2606}
2607
2608constexpr FPoint& FPoint::Clamp(const FRect& rect)
2609{
2610 if (x < rect.x) x = rect.x;
2611 if (x > rect.GetX2()) x = rect.GetX2();
2612 if (y < rect.y) y = rect.y;
2613 if (y > rect.GetY2()) y = rect.GetY2();
2614 return *this;
2615}
2616
2617constexpr FPoint FPoint::GetWrapped(const FRect& rect) const
2618{
2619 FPoint p = *this;
2620 p.Wrap(rect);
2621 return p;
2622}
2623
2624constexpr FPoint& FPoint::Wrap(const FRect& rect)
2625{
2626 if (x < rect.x)
2627 x = rect.x + rect.w - 1 - SDL::fmod(rect.x - x + rect.w - 1, rect.w);
2628 else if (x >= rect.x + rect.w)
2629 x = rect.x + SDL::fmod(x - rect.x - rect.w, rect.w);
2630
2631 if (y < rect.y)
2632 y = rect.y + rect.h - 1 - SDL::fmod(rect.y - y + rect.h - 1, rect.h);
2633 else if (y >= rect.y + rect.h)
2634 y = rect.y + SDL::fmod(y - rect.y - rect.h, rect.h);
2635
2636 return *this;
2637}
2638
2639constexpr Rect::operator FRect() const
2640{
2641 return {float(x), float(y), float(w), float(h)};
2642}
2643
2644} // namespace SDL
2645
2646#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 T * data() const
Retrieves contained data.
Definition: SDL3pp_spanRef.h:75
constexpr size_t size() const
Retrieves contained size.
Definition: SDL3pp_spanRef.h:69
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:199
constexpr bool operator==(ColorRaw lhs, ColorRaw rhs) noexcept
Comparison operator for Color.
Definition: SDL3pp_pixels.h:2100
FRect RectToFRect(const RectRaw &rect)
Convert an Rect to FRect.
Definition: SDL3pp_rect.h:2042
bool Equal(const RectRaw &other) const
Determine whether two rectangles are equal.
Definition: SDL3pp_rect.h:2128
Rect GetRectIntersection(const RectRaw &A, const RectRaw &B)
Calculate the intersection of two rectangles.
Definition: SDL3pp_rect.h:2174
bool HasIntersection(const RectRaw &other) const
Determine whether two rectangles intersect.
Definition: SDL3pp_rect.h:2153
constexpr FRect GetRectUnionFloat(const FRectRaw &A, const FRectRaw &B)
Calculate the union of two rectangles with float precision.
Definition: SDL3pp_rect.h:2467
bool HasRectIntersection(const RectRaw &A, const RectRaw &B)
Determine whether two rectangles intersect.
Definition: SDL3pp_rect.h:2148
bool InRect(const RectRaw &r) const
Determine whether a point resides inside a rectangle.
Definition: SDL3pp_rect.h:2077
bool EqualEpsilon(const FRectRaw &other, const float epsilon) const
Determine whether two floating point rectangles are equal, within some given epsilon.
Definition: SDL3pp_rect.h:2361
static FRect GetEnclosingPoints(SpanRef< const FPointRaw > points, OptionalRef< const FRectRaw > clip=std::nullopt)
Calculate a minimal rectangle enclosing a set of points with float precision.
Definition: SDL3pp_rect.h:2506
bool Equal(const FRectRaw &other) const
Determine whether two floating point rectangles are equal, within a default epsilon.
Definition: SDL3pp_rect.h:2397
bool RectsEqual(const RectRaw &a, const RectRaw &b)
Determine whether two rectangles are equal.
Definition: SDL3pp_rect.h:2123
bool GetLineIntersection(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:2542
Rect GetRectEnclosingPoints(SpanRef< const PointRaw > points, OptionalRef< const RectRaw > clip=std::nullopt)
Calculate a minimal rectangle enclosing a set of points.
Definition: SDL3pp_rect.h:2225
Rect GetIntersection(const RectRaw &other) const
Calculate the intersection of two rectangles.
Definition: SDL3pp_rect.h:2180
bool GetRectAndLineIntersectionFloat(const FRectRaw &rect, float *X1, float *Y1, float *X2, float *Y2)
Calculate the intersection of a rectangle and line segment with float precision.
Definition: SDL3pp_rect.h:2533
SDL_FPoint FPointRaw
Alias to raw representation for FPoint.
Definition: SDL3pp_rect.h:28
bool HasRectIntersectionFloat(const FRectRaw &A, const FRectRaw &B)
Determine whether two rectangles intersect with float precision.
Definition: SDL3pp_rect.h:2417
FRect GetRectIntersectionFloat(const FRectRaw &A, const FRectRaw &B)
Calculate the intersection of two rectangles with float precision.
Definition: SDL3pp_rect.h:2443
bool PointInRect(const PointRaw &p, const RectRaw &r)
Determine whether a point resides inside a rectangle.
Definition: SDL3pp_rect.h:2072
bool RectEmptyFloat(const FRectRaw &r)
Determine whether a floating point rectangle takes no space.
Definition: SDL3pp_rect.h:2325
bool InRect(const FRectRaw &r) const
Determine whether a point resides inside a floating point rectangle.
Definition: SDL3pp_rect.h:2302
bool RectEmpty(const RectRaw &r)
Determine whether a rectangle has no area.
Definition: SDL3pp_rect.h:2100
constexpr Rect GetUnion(const RectRaw &other) const
Calculate the union of two rectangles.
Definition: SDL3pp_rect.h:2204
static Rect GetEnclosingPoints(SpanRef< const PointRaw > points, OptionalRef< const RectRaw > clip=std::nullopt)
Calculate a minimal rectangle enclosing a set of points.
Definition: SDL3pp_rect.h:2236
bool HasIntersection(const FRectRaw &other) const
Determine whether two rectangles intersect with float precision.
Definition: SDL3pp_rect.h:2422
bool RectsEqualEpsilon(const FRectRaw &a, const FRectRaw &b, const float epsilon)
Determine whether two floating point rectangles are equal, within some given epsilon.
Definition: SDL3pp_rect.h:2354
bool Empty() const
Determine whether a rectangle has no area.
Definition: SDL3pp_rect.h:2327
constexpr Rect GetRectUnion(const RectRaw &A, const RectRaw &B)
Calculate the union of two rectangles.
Definition: SDL3pp_rect.h:2197
bool RectsEqualFloat(const FRectRaw &a, const FRectRaw &b)
Determine whether two floating point rectangles are equal, within a default epsilon.
Definition: SDL3pp_rect.h:2392
FRect GetIntersection(const FRectRaw &other) const
Calculate the intersection of two rectangles with float precision.
Definition: SDL3pp_rect.h:2449
bool GetRectAndLineIntersection(const RectRaw &rect, int *X1, int *Y1, int *X2, int *Y2)
Calculate the intersection of a rectangle and line segment.
Definition: SDL3pp_rect.h:2262
constexpr FRect GetUnion(const FRectRaw &other) const
Calculate the union of two rectangles with float precision.
Definition: SDL3pp_rect.h:2474
SDL_Rect RectRaw
Alias to raw representation for Rect.
Definition: SDL3pp_rect.h:34
SDL_FRect FRectRaw
Alias to raw representation for FRect.
Definition: SDL3pp_rect.h:40
bool PointInRectFloat(const FPointRaw &p, const FRectRaw &r)
Determine whether a point resides inside a floating point rectangle.
Definition: SDL3pp_rect.h:2297
bool Empty() const
Determine whether a rectangle has no area.
Definition: SDL3pp_rect.h:2102
FRect GetRectEnclosingPointsFloat(SpanRef< const FPointRaw > points, OptionalRef< const FRectRaw > clip=std::nullopt)
Calculate a minimal rectangle enclosing a set of points with float precision.
Definition: SDL3pp_rect.h:2495
SDL_Point PointRaw
Alias to raw representation for Point.
Definition: SDL3pp_rect.h:22
double fmod(double x, double y)
Return the floating-point remainder of x / y
Definition: SDL3pp_stdinc.h:5282
Main include header for the SDL3pp library.
Sint32 narrowS32(T value)
Narrows to Sint32.
Definition: SDL3pp_stdinc.h:6425
The structure that defines a point (using floating point values).
Definition: SDL3pp_rect.h:512
constexpr float GetY() const noexcept
Get the y coordinate.
Definition: SDL3pp_rect.h:568
constexpr FPoint operator/(const FPoint &other) const
Get point's memberwise division by another point.
Definition: SDL3pp_rect.h:661
constexpr FPoint & Wrap(const FRect &rect)
Wrap point coordinates within a specified rect.
Definition: SDL3pp_rect.h:2624
constexpr FPoint operator-() const
Get point's memberwise negation.
Definition: SDL3pp_rect.h:610
constexpr FPoint & operator/=(const FPoint &other)
Memberwise divide by another point.
Definition: SDL3pp_rect.h:749
constexpr float GetX() const noexcept
Get the x coordinate.
Definition: SDL3pp_rect.h:549
constexpr FPoint operator/(float value) const
Get point's memberwise division by an float.
Definition: SDL3pp_rect.h:647
constexpr FPoint operator-(const FPoint &other) const
Get point's memberwise subtraction with another point.
Definition: SDL3pp_rect.h:633
constexpr FPoint operator*(float value) const
Get point's memberwise multiplication by an float.
Definition: SDL3pp_rect.h:676
constexpr FPoint(float x, float y) noexcept
Constructs from its fields.
Definition: SDL3pp_rect.h:529
constexpr FPoint & operator/=(float value)
Memberwise divide by an float.
Definition: SDL3pp_rect.h:734
constexpr FPoint & SetX(float newX) noexcept
Set the x coordinate.
Definition: SDL3pp_rect.h:557
constexpr FPoint GetClamped(const FRect &rect) const
Get a point with coordinates modified so it fits into a given rect.
Definition: SDL3pp_rect.h:2601
constexpr FPoint & operator*=(const FPoint &other)
Memberwise multiply by another point.
Definition: SDL3pp_rect.h:779
constexpr FPoint & SetY(float newY) noexcept
Set the y coordinate.
Definition: SDL3pp_rect.h:576
constexpr FPoint GetWrapped(const FRect &rect) const
Get a point wrapped within a specified rect.
Definition: SDL3pp_rect.h:2617
constexpr FPoint operator+(const FPoint &other) const
Get point's memberwise addition with another point.
Definition: SDL3pp_rect.h:620
constexpr FPoint & Clamp(const FRect &rect)
Clamp point coordinates to make it fit into a given rect.
Definition: SDL3pp_rect.h:2608
constexpr FPoint & operator*=(float value)
Memberwise multiply by an float.
Definition: SDL3pp_rect.h:764
constexpr FPoint(const FPointRaw &p={}) noexcept
Wraps FPoint.
Definition: SDL3pp_rect.h:518
constexpr FPoint & operator-=(const FPoint &other)
Memberwise subtract another point.
Definition: SDL3pp_rect.h:719
constexpr FPoint operator*(const FPoint &other) const
Get point's memberwise multiplication by another point.
Definition: SDL3pp_rect.h:691
constexpr FPoint & operator+=(const FPoint &other)
Memberwise add another point.
Definition: SDL3pp_rect.h:704
A rectangle stored using floating point values.
Definition: SDL3pp_rect.h:1443
constexpr FRect & Extend(float hAmount, float vAmount)
Extend a rect by specified amount of pixels.
Definition: SDL3pp_rect.h:1966
constexpr FRect operator+(const FPoint &offset) const
Get rectangle moved by a given offset.
Definition: SDL3pp_rect.h:1983
constexpr FRect & SetX(float newX) noexcept
Set the left x coordinate.
Definition: SDL3pp_rect.h:1491
static constexpr FRect FromCorners(FPoint p1, FPoint p2)
Construct the rect from given centers coordinates.
Definition: SDL3pp_rect.h:1624
constexpr FRect(float x, float y, float w, float h) noexcept
Constructs from its fields.
Definition: SDL3pp_rect.h:1462
constexpr float GetH() const noexcept
Get height of the rect.
Definition: SDL3pp_rect.h:1540
constexpr float GetY() const noexcept
Get top y coordinate.
Definition: SDL3pp_rect.h:1502
constexpr FPoint GetTopRight() const
Get top right corner of the rect.
Definition: SDL3pp_rect.h:1691
constexpr FRect operator-(const FPoint &offset) const
Get rectangle moved by an opposite of given offset.
Definition: SDL3pp_rect.h:1996
bool Contains(const FPointRaw &p) const
Check whether the rect contains given point.
Definition: SDL3pp_rect.h:1850
constexpr FRect & operator+=(const FPoint &offset)
Move by then given offset.
Definition: SDL3pp_rect.h:2009
constexpr float GetX() const noexcept
Get left x coordinate.
Definition: SDL3pp_rect.h:1483
static constexpr FRect FromCenter(FPoint center, FPoint size)
Construct the rect from given center coordinates and size.
Definition: SDL3pp_rect.h:1598
bool Contains(const FRectRaw &other) const
Check whether the rect contains given point.
Definition: SDL3pp_rect.h:1863
constexpr FRect & operator-=(const FPoint &offset)
Move by an opposite of the given offset.
Definition: SDL3pp_rect.h:2024
constexpr FPoint GetBottomRight() const
Get bottom right corner of the rect.
Definition: SDL3pp_rect.h:1707
constexpr FPoint GetBottomLeft() const
Get bottom left corner of the rect.
Definition: SDL3pp_rect.h:1699
constexpr FRect(const FPointRaw &corner, const FPointRaw &size)
Constructs from top-left corner plus size.
Definition: SDL3pp_rect.h:1470
constexpr float GetX2() const
Get X coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1635
constexpr FRect GetExtension(unsigned int amount) const
Get a rect extended by specified amount of pixels.
Definition: SDL3pp_rect.h:1920
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:1586
constexpr float GetY2() const
Get Y coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1659
constexpr FRect & SetH(float newH) noexcept
Set the height of the rect.
Definition: SDL3pp_rect.h:1548
constexpr FRect & SetY2(float y2)
Set Y coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1671
constexpr float GetW() const noexcept
Get width of the rect.
Definition: SDL3pp_rect.h:1521
constexpr FRect & SetX2(float x2)
Set X coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1647
static constexpr FRect FromCorners(float x1, float y1, float x2, float y2)
Construct the rect from given corners coordinates.
Definition: SDL3pp_rect.h:1612
constexpr FRect & Extend(float amount)
Extend a rect by specified amount of pixels.
Definition: SDL3pp_rect.h:1953
constexpr FRect & SetY(float newY) noexcept
Set the top y coordinate.
Definition: SDL3pp_rect.h:1510
constexpr FRect & SetW(float newW) noexcept
Set the width of the rect.
Definition: SDL3pp_rect.h:1529
constexpr FRect GetExtension(float hAmount, float vAmount) const
Get a rect extended by specified amount of pixels.
Definition: SDL3pp_rect.h:1938
constexpr FPoint GetCentroid() const
Get centroid of the rect.
Definition: SDL3pp_rect.h:1723
bool GetLineIntersection(FPoint *p1, FPoint *p2) const
Determine whether a floating point rectangle takes no space.
Definition: SDL3pp_rect.h:1763
constexpr FPoint GetTopLeft() const
Get top left corner of the rect.
Definition: SDL3pp_rect.h:1683
constexpr FRect(const FRectRaw &r={}) noexcept
Wraps FRect.
Definition: SDL3pp_rect.h:1449
constexpr FPoint GetSize() const
Get size of the rect.
Definition: SDL3pp_rect.h:1715
The structure that defines a point (using integers).
Definition: SDL3pp_rect.h:83
constexpr Point & operator/=(int value)
Memberwise divide by an integer.
Definition: SDL3pp_rect.h:368
constexpr Point & operator%=(const Point &other)
Memberwise remainder from division by another point.
Definition: SDL3pp_rect.h:414
constexpr Point(const PointRaw &p={}) noexcept
Wraps Point.
Definition: SDL3pp_rect.h:89
constexpr Point operator/(int value) const
Get point's memberwise division by an integer.
Definition: SDL3pp_rect.h:228
constexpr Point GetClamped(const Rect &rect) const
Get a point with coordinates modified so it fits into a given rect.
Definition: SDL3pp_rect.h:2563
constexpr Point operator-(const Point &other) const
Get point's memberwise subtraction with another point.
Definition: SDL3pp_rect.h:214
constexpr Point(int x, int y) noexcept
Constructs from its fields.
Definition: SDL3pp_rect.h:100
constexpr Point operator+(const Point &other) const
Get point's memberwise addition with another point.
Definition: SDL3pp_rect.h:201
constexpr Point & Clamp(const Rect &rect)
Clamp point coordinates to make it fit into a given rect.
Definition: SDL3pp_rect.h:2570
constexpr Point operator*(const Point &other) const
Get point's memberwise multiplication by another point.
Definition: SDL3pp_rect.h:325
constexpr Point & SetX(int newX) noexcept
Set the x coordinate.
Definition: SDL3pp_rect.h:138
constexpr Point operator%(int value) const
Get point's memberwise remainder from division by an integer.
Definition: SDL3pp_rect.h:268
constexpr Point & SetY(int newY) noexcept
Set the y coordinate.
Definition: SDL3pp_rect.h:157
constexpr Point & operator*=(const Point &other)
Memberwise multiply by another point.
Definition: SDL3pp_rect.h:444
constexpr Point & operator-=(const Point &other)
Memberwise subtract another point.
Definition: SDL3pp_rect.h:353
constexpr Point operator*(int value) const
Get point's memberwise multiplication by an integer.
Definition: SDL3pp_rect.h:298
constexpr int GetY() const noexcept
Get y coordinate.
Definition: SDL3pp_rect.h:149
constexpr Point & operator/=(const Point &other)
Memberwise divide by another point.
Definition: SDL3pp_rect.h:383
constexpr Point operator%(const Point &other) const
Get point's memberwise remainder from division by another point.
Definition: SDL3pp_rect.h:283
constexpr int GetX() const noexcept
Get x coordinate.
Definition: SDL3pp_rect.h:130
constexpr Point GetWrapped(const Rect &rect) const
Get a point wrapped within a specified rect.
Definition: SDL3pp_rect.h:2579
constexpr Point & Wrap(const Rect &rect)
Wrap point coordinates within a specified rect.
Definition: SDL3pp_rect.h:2586
constexpr Point & operator%=(int value)
Memberwise remainder from division by an integer.
Definition: SDL3pp_rect.h:398
constexpr Point operator/(const Point &other) const
Get point's memberwise division by another point.
Definition: SDL3pp_rect.h:253
constexpr Point & operator+=(const Point &other)
Memberwise add another point.
Definition: SDL3pp_rect.h:338
constexpr Point operator-() const
Get point's memberwise negation.
Definition: SDL3pp_rect.h:191
constexpr Point(const FPointRaw &p)
Wraps Point.
Definition: SDL3pp_rect.h:110
constexpr Point & operator*=(int value)
Memberwise multiply by an integer.
Definition: SDL3pp_rect.h:429
A rectangle, with the origin at the upper left (using integers).
Definition: SDL3pp_rect.h:845
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:999
bool Contains(const RectRaw &other) const
Check whether the rect contains given point.
Definition: SDL3pp_rect.h:1255
constexpr Rect(const PointRaw &corner, const PointRaw &size)
Construct from offset and size.
Definition: SDL3pp_rect.h:875
constexpr Rect & operator-=(const Point &offset)
Move by an opposite of the given offset.
Definition: SDL3pp_rect.h:1413
bool GetLineIntersection(PointRaw *p1, PointRaw *p2) const
Calculate the intersection of a rectangle and line segment.
Definition: SDL3pp_rect.h:1154
bool operator==(const RectRaw &other) const
Compares with the underlying type.
Definition: SDL3pp_rect.h:881
constexpr Rect GetExtension(unsigned int hAmount, unsigned int vAmount) const
Get a rect extended by specified amount of pixels.
Definition: SDL3pp_rect.h:1327
constexpr Point GetTopLeft() const
Get top left corner of the rect.
Definition: SDL3pp_rect.h:1096
constexpr Rect & Extend(unsigned int hAmount, unsigned int vAmount)
Extend a rect by specified amount of pixels.
Definition: SDL3pp_rect.h:1355
constexpr int GetY() const noexcept
Get top y coordinate.
Definition: SDL3pp_rect.h:916
constexpr int GetH() const noexcept
Get height of the rect.
Definition: SDL3pp_rect.h:954
constexpr Rect operator+(const Point &offset) const
Get rectangle moved by a given offset.
Definition: SDL3pp_rect.h:1372
constexpr Rect & operator+=(const Point &offset)
Move by then given offset.
Definition: SDL3pp_rect.h:1398
constexpr Rect(const RectRaw &r={}) noexcept
Wraps Rect.
Definition: SDL3pp_rect.h:851
constexpr Rect GetExtension(unsigned int amount) const
Get a rect extended by specified amount of pixels.
Definition: SDL3pp_rect.h:1309
constexpr Rect & SetY(int newY) noexcept
Set the top y coordinate.
Definition: SDL3pp_rect.h:924
constexpr Rect & SetW(int newW) noexcept
Set the width of the rect.
Definition: SDL3pp_rect.h:943
constexpr Rect & Extend(unsigned int amount)
Extend a rect by specified amount of pixels.
Definition: SDL3pp_rect.h:1342
constexpr Point GetCentroid() const
Get centroid of the rect.
Definition: SDL3pp_rect.h:1136
constexpr Point GetBottomLeft() const
Get bottom left corner of the rect.
Definition: SDL3pp_rect.h:1112
constexpr Rect & SetX2(int x2)
Set X coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1060
static constexpr Rect FromCorners(Point p1, Point p2)
Construct the rect from given centers coordinates.
Definition: SDL3pp_rect.h:1037
bool Contains(const PointRaw &p) const
Check whether the rect contains given point.
Definition: SDL3pp_rect.h:1245
bool operator==(const Rect &other) const
Compares with the underlying type.
Definition: SDL3pp_rect.h:884
static constexpr Rect FromCorners(int x1, int y1, int x2, int y2)
Construct the rect from given corners coordinates.
Definition: SDL3pp_rect.h:1025
constexpr Rect(int x, int y, int w, int h) noexcept
Constructs from its fields.
Definition: SDL3pp_rect.h:864
constexpr Point GetSize() const
Get size of the rect.
Definition: SDL3pp_rect.h:1128
constexpr Rect operator-(const Point &offset) const
Get rectangle moved by an opposite of given offset.
Definition: SDL3pp_rect.h:1385
constexpr Point GetBottomRight() const
Get bottom right corner of the rect.
Definition: SDL3pp_rect.h:1120
constexpr int GetY2() const
Get Y coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1072
static constexpr Rect FromCenter(Point center, Point size)
Construct the rect from given center coordinates and size.
Definition: SDL3pp_rect.h:1011
constexpr Rect & SetH(int newH) noexcept
Set the height of the rect.
Definition: SDL3pp_rect.h:962
constexpr int GetW() const noexcept
Get width of the rect.
Definition: SDL3pp_rect.h:935
constexpr Rect & SetX(int newX) noexcept
Set the left x coordinate.
Definition: SDL3pp_rect.h:905
constexpr Rect & SetY2(int y2)
Set Y coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1084
constexpr int GetX() const noexcept
Get left x coordinate.
Definition: SDL3pp_rect.h:897
constexpr Point GetTopRight() const
Get top right corner of the rect.
Definition: SDL3pp_rect.h:1104
constexpr int GetX2() const
Get X coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1048