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
20
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
70constexpr auto operator<=>(const PointRaw& lhs, const PointRaw& rhs) noexcept
71{
72 if (lhs.x != rhs.x) return lhs.x <=> rhs.x;
73 return lhs.y <=> rhs.y;
74}
75
77constexpr auto operator<=>(const FPointRaw& lhs, const FPointRaw& rhs) noexcept
78{
79 if (lhs.x != rhs.x) return lhs.x <=> rhs.x;
80 return lhs.y <=> rhs.y;
81}
82
97{
103 constexpr Point(const PointRaw& p = {}) noexcept
104 : PointRaw(p)
105 {
106 }
107
114 constexpr Point(int x, int y) noexcept
115 : PointRaw{x, y}
116 {
117 }
118
124 constexpr explicit Point(const FPointRaw& p)
125 : SDL_Point{int(p.x), int(p.y)}
126 {
127 }
128
134 constexpr explicit operator bool() const noexcept
135 {
136 return *this != PointRaw{};
137 }
138
144 constexpr int GetX() const noexcept { return x; }
145
152 constexpr Point& SetX(int newX) noexcept
153 {
154 x = newX;
155 return *this;
156 }
157
163 constexpr int GetY() const noexcept { return y; }
164
171 constexpr Point& SetY(int newY) noexcept
172 {
173 y = newY;
174 return *this;
175 }
176
197 bool InRect(const RectRaw& r) const;
198
205 constexpr Point operator-() const { return Point(-x, -y); }
206
215 constexpr Point operator+(const Point& other) const
216 {
217 return Point(x + other.x, y + other.y);
218 }
219
228 constexpr Point operator-(const Point& other) const
229 {
230 return Point(x - other.x, y - other.y);
231 }
232
242 constexpr Point operator/(int value) const
243 {
244 return Point(x / value, y / value);
245 }
246
256 constexpr FPoint operator/(float value) const;
257
267 constexpr Point operator/(const Point& other) const
268 {
269 return Point(x / other.x, y / other.y);
270 }
271
282 constexpr Point operator%(int value) const
283 {
284 return Point(x % value, y % value);
285 }
286
297 constexpr Point operator%(const Point& other) const
298 {
299 return Point(x % other.x, y % other.y);
300 }
301
312 constexpr Point operator*(int value) const
313 {
314 return Point(x * value, y * value);
315 }
316
327 constexpr FPoint operator*(float value) const;
328
339 constexpr Point operator*(const Point& other) const
340 {
341 return Point(x * other.x, y * other.y);
342 }
343
352 constexpr Point& operator+=(const Point& other)
353 {
354 x += other.x;
355 y += other.y;
356 return *this;
357 }
358
367 constexpr Point& operator-=(const Point& other)
368 {
369 x -= other.x;
370 y -= other.y;
371 return *this;
372 }
373
382 constexpr Point& operator/=(int value)
383 {
384 x /= value;
385 y /= value;
386 return *this;
387 }
388
397 constexpr Point& operator/=(const Point& other)
398 {
399 x /= other.x;
400 y /= other.y;
401 return *this;
402 }
403
412 constexpr Point& operator%=(int value)
413 {
414 x %= value;
415 y %= value;
416 return *this;
417 }
418
428 constexpr Point& operator%=(const Point& other)
429 {
430 x %= other.x;
431 y %= other.y;
432 return *this;
433 }
434
443 constexpr Point& operator*=(int value)
444 {
445 x *= value;
446 y *= value;
447 return *this;
448 }
449
458 constexpr Point& operator*=(const Point& other)
459 {
460 x *= other.x;
461 y *= other.y;
462 return *this;
463 }
464
474 constexpr Point GetClamped(const Rect& rect) const;
475
485 constexpr Point& Clamp(const Rect& rect);
486
495 constexpr Point GetWrapped(const Rect& rect) const;
496
505 constexpr Point& Wrap(const Rect& rect);
506
512 constexpr operator FPoint() const;
513};
514
526{
532 constexpr FPoint(const FPointRaw& p = {}) noexcept
533 : FPointRaw(p)
534 {
535 }
536
543 constexpr FPoint(float x, float y) noexcept
544 : FPointRaw{x, y}
545 {
546 }
547
553 constexpr explicit operator bool() const noexcept
554 {
555 return *this != FPointRaw{};
556 }
557
563 constexpr float GetX() const noexcept { return x; }
564
571 constexpr FPoint& SetX(float newX) noexcept
572 {
573 x = newX;
574 return *this;
575 }
576
582 constexpr float GetY() const noexcept { return y; }
583
590 constexpr FPoint& SetY(float newY) noexcept
591 {
592 y = newY;
593 return *this;
594 }
595
616 bool InRect(const FRectRaw& r) const;
617
624 constexpr FPoint operator-() const { return FPoint(-x, -y); }
625
634 constexpr FPoint operator+(const FPoint& other) const
635 {
636 return FPoint(x + other.x, y + other.y);
637 }
638
647 constexpr FPoint operator-(const FPoint& other) const
648 {
649 return FPoint(x - other.x, y - other.y);
650 }
651
661 constexpr FPoint operator/(float value) const
662 {
663 return FPoint(x / value, y / value);
664 }
665
675 constexpr FPoint operator/(const FPoint& other) const
676 {
677 return FPoint(x / other.x, y / other.y);
678 }
679
690 constexpr FPoint operator*(float value) const
691 {
692 return FPoint(x * value, y * value);
693 }
694
705 constexpr FPoint operator*(const FPoint& other) const
706 {
707 return FPoint(x * other.x, y * other.y);
708 }
709
718 constexpr FPoint& operator+=(const FPoint& other)
719 {
720 x += other.x;
721 y += other.y;
722 return *this;
723 }
724
733 constexpr FPoint& operator-=(const FPoint& other)
734 {
735 x -= other.x;
736 y -= other.y;
737 return *this;
738 }
739
748 constexpr FPoint& operator/=(float value)
749 {
750 x /= value;
751 y /= value;
752 return *this;
753 }
754
763 constexpr FPoint& operator/=(const FPoint& other)
764 {
765 x /= other.x;
766 y /= other.y;
767 return *this;
768 }
769
778 constexpr FPoint& operator*=(float value)
779 {
780 x *= value;
781 y *= value;
782 return *this;
783 }
784
793 constexpr FPoint& operator*=(const FPoint& other)
794 {
795 x *= other.x;
796 y *= other.y;
797 return *this;
798 }
799
809 constexpr FPoint GetClamped(const FRect& rect) const;
810
820 constexpr FPoint& Clamp(const FRect& rect);
821
830 constexpr FPoint GetWrapped(const FRect& rect) const;
831
840 constexpr FPoint& Wrap(const FRect& rect);
841};
842
858struct Rect : RectRaw
859{
865 constexpr Rect(const RectRaw& r = {}) noexcept
866 : RectRaw(r)
867 {
868 }
869
878 constexpr Rect(int x, int y, int w, int h) noexcept
879 : RectRaw{x, y, w, h}
880 {
881 }
882
889 constexpr Rect(const PointRaw& corner, const PointRaw& size)
890 : Rect{corner.x, corner.y, size.x, size.y}
891 {
892 }
893
895 bool operator==(const RectRaw& other) const { return Equal(other); }
896
898 bool operator==(const Rect& other) const
899 {
900 return *this == (const RectRaw&)(other);
901 }
902
904 explicit operator bool() const { return !Empty(); }
905
911 constexpr int GetX() const noexcept { return x; }
912
919 constexpr Rect& SetX(int newX) noexcept
920 {
921 x = newX;
922 return *this;
923 }
924
930 constexpr int GetY() const noexcept { return y; }
931
938 constexpr Rect& SetY(int newY) noexcept
939 {
940 y = newY;
941 return *this;
942 }
943
949 constexpr int GetW() const noexcept { return w; }
950
957 constexpr Rect& SetW(int newW) noexcept
958 {
959 w = newW;
960 return *this;
961 }
962
968 constexpr int GetH() const noexcept { return h; }
969
976 constexpr Rect& SetH(int newH) noexcept
977 {
978 h = newH;
979 return *this;
980 }
981
1000 static Rect GetEnclosingPoints(
1002 OptionalRef<const RectRaw> clip = std::nullopt);
1003
1013 static constexpr Rect FromCenter(int cx, int cy, int w, int h)
1014 {
1015 return Rect(cx - w / 2, cy - h / 2, w, h);
1016 }
1017
1025 static constexpr Rect FromCenter(Point center, Point size)
1026 {
1027 return Rect(center - size / 2, size);
1028 }
1029
1039 static constexpr Rect FromCorners(int x1, int y1, int x2, int y2)
1040 {
1041 return Rect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
1042 }
1043
1051 static constexpr Rect FromCorners(Point p1, Point p2)
1052 {
1053 return Rect(p1, p2 - p1 + Point(1, 1));
1054 }
1055
1062 constexpr int GetX2() const { return x + w - 1; }
1063
1074 constexpr Rect& SetX2(int x2)
1075 {
1076 w = x2 - x + 1;
1077 return *this;
1078 }
1079
1086 constexpr int GetY2() const { return y + h - 1; }
1087
1098 constexpr Rect& SetY2(int y2)
1099 {
1100 h = y2 - y + 1;
1101 return *this;
1102 }
1103
1110 constexpr Point GetTopLeft() const { return Point(x, y); }
1111
1118 constexpr Point GetTopRight() const { return Point(GetX2(), y); }
1119
1126 constexpr Point GetBottomLeft() const { return Point(x, GetY2()); }
1127
1134 constexpr Point GetBottomRight() const { return Point(GetX2(), GetY2()); }
1135
1142 constexpr Point GetSize() const { return Point(w, h); }
1143
1150 constexpr Point GetCentroid() const { return Point(x + w / 2, y + h / 2); }
1151
1169 {
1170 return GetLineIntersection(p1 ? &p1->x : nullptr,
1171 p1 ? &p1->y : nullptr,
1172 p2 ? &p2->x : nullptr,
1173 p2 ? &p2->y : nullptr);
1174 }
1175
1195 bool GetLineIntersection(int* X1, int* Y1, int* X2, int* Y2) const;
1196
1207 operator SDL_FRect() const;
1208
1210 constexpr operator FRect() const;
1211
1229 bool Empty() const;
1230
1249 bool Equal(const RectRaw& other) const;
1250
1259 bool Contains(const PointRaw& p) const { return SDL_PointInRect(&p, this); }
1260
1269 bool Contains(const RectRaw& other) const { return GetUnion(other) == *this; }
1270
1283 bool HasIntersection(const RectRaw& other) const;
1284
1300 Rect GetIntersection(const RectRaw& other) const;
1301
1313 constexpr Rect GetUnion(const RectRaw& other) const;
1314
1323 constexpr Rect GetExtension(unsigned int amount) const
1324 {
1325 Rect r = *this;
1326 r.Extend(amount);
1327 return r;
1328 }
1329
1341 constexpr Rect GetExtension(unsigned int hAmount, unsigned int vAmount) const
1342 {
1343 Rect r = *this;
1344 r.Extend(hAmount, vAmount);
1345 return r;
1346 }
1347
1356 constexpr Rect& Extend(unsigned int amount) { return Extend(amount, amount); }
1357
1369 constexpr Rect& Extend(unsigned int hAmount, unsigned int vAmount)
1370 {
1371 x -= hAmount;
1372 y -= vAmount;
1373 w += hAmount * 2;
1374 h += vAmount * 2;
1375 return *this;
1376 }
1377
1386 constexpr Rect operator+(const Point& offset) const
1387 {
1388 return Rect(x + offset.x, y + offset.y, w, h);
1389 }
1390
1399 constexpr Rect operator-(const Point& offset) const
1400 {
1401 return Rect(x - offset.x, y - offset.y, w, h);
1402 }
1403
1412 constexpr Rect& operator+=(const Point& offset)
1413 {
1414 x += offset.x;
1415 y += offset.y;
1416 return *this;
1417 }
1418
1427 constexpr Rect& operator-=(const Point& offset)
1428 {
1429 x -= offset.x;
1430 y -= offset.y;
1431 return *this;
1432 }
1433};
1434
1457{
1463 constexpr FRect(const FRectRaw& r = {}) noexcept
1464 : FRectRaw(r)
1465 {
1466 }
1467
1476 constexpr FRect(float x, float y, float w, float h) noexcept
1477 : FRectRaw{x, y, w, h}
1478 {
1479 }
1480
1484 constexpr FRect(const FPointRaw& corner, const FPointRaw& size)
1485 : FRect{corner.x, corner.y, size.x, size.y}
1486 {
1487 }
1488
1490 operator bool() const { return !Empty(); }
1491
1497 constexpr float GetX() const noexcept { return x; }
1498
1505 constexpr FRect& SetX(float newX) noexcept
1506 {
1507 x = newX;
1508 return *this;
1509 }
1510
1516 constexpr float GetY() const noexcept { return y; }
1517
1524 constexpr FRect& SetY(float newY) noexcept
1525 {
1526 y = newY;
1527 return *this;
1528 }
1529
1535 constexpr float GetW() const noexcept { return w; }
1536
1543 constexpr FRect& SetW(float newW) noexcept
1544 {
1545 w = newW;
1546 return *this;
1547 }
1548
1554 constexpr float GetH() const noexcept { return h; }
1555
1562 constexpr FRect& SetH(float newH) noexcept
1563 {
1564 h = newH;
1565 return *this;
1566 }
1567
1589 OptionalRef<const FRectRaw> clip = std::nullopt);
1590
1600 static constexpr FRect FromCenter(float cx, float cy, float w, float h)
1601 {
1602 return FRect(cx - w / 2, cy - h / 2, w, h);
1603 }
1604
1612 static constexpr FRect FromCenter(FPoint center, FPoint size)
1613 {
1614 return FRect(center - size / 2, size);
1615 }
1616
1626 static constexpr FRect FromCorners(float x1, float y1, float x2, float y2)
1627 {
1628 return FRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
1629 }
1630
1638 static constexpr FRect FromCorners(FPoint p1, FPoint p2)
1639 {
1640 return FRect(p1, p2 - p1 + FPoint(1, 1));
1641 }
1642
1649 constexpr float GetX2() const { return x + w - 1; }
1650
1661 constexpr FRect& SetX2(float x2)
1662 {
1663 w = x2 - x + 1;
1664 return *this;
1665 }
1666
1673 constexpr float GetY2() const { return y + h - 1; }
1674
1685 constexpr FRect& SetY2(float y2)
1686 {
1687 h = y2 - y + 1;
1688 return *this;
1689 }
1690
1697 constexpr FPoint GetTopLeft() const { return FPoint(x, y); }
1698
1705 constexpr FPoint GetTopRight() const { return FPoint(GetX2(), y); }
1706
1713 constexpr FPoint GetBottomLeft() const { return FPoint(x, GetY2()); }
1714
1721 constexpr FPoint GetBottomRight() const { return FPoint(GetX2(), GetY2()); }
1722
1729 constexpr FPoint GetSize() const { return FPoint(w, h); }
1730
1737 constexpr FPoint GetCentroid() const { return FPoint(x + w / 2, y + h / 2); }
1738
1759 bool GetLineIntersection(float* X1, float* Y1, float* X2, float* Y2) const;
1760
1777 bool GetLineIntersection(FPoint* p1, FPoint* p2) const
1778 {
1779 return GetLineIntersection(p1 ? &p1->x : nullptr,
1780 p1 ? &p1->y : nullptr,
1781 p2 ? &p2->x : nullptr,
1782 p2 ? &p2->y : nullptr);
1783 }
1784
1802 bool Empty() const;
1803
1828 bool EqualEpsilon(const FRectRaw& other, const float epsilon) const;
1829
1854 bool Equal(const FRectRaw& other) const;
1855
1864 bool Contains(const FPointRaw& p) const
1865 {
1866 return SDL_PointInRectFloat(&p, this);
1867 }
1868
1877 bool Contains(const FRectRaw& other) const
1878 {
1879 return GetUnion(other) == *this;
1880 }
1881
1894 bool HasIntersection(const FRectRaw& other) const;
1895
1911 FRect GetIntersection(const FRectRaw& other) const;
1912
1924 constexpr FRect GetUnion(const FRectRaw& other) const;
1925
1934 constexpr FRect GetExtension(unsigned int amount) const
1935 {
1936 FRect r = *this;
1937 r.Extend(float(amount));
1938 return r;
1939 }
1940
1952 constexpr FRect GetExtension(float hAmount, float vAmount) const
1953 {
1954 FRect r = *this;
1955 r.Extend(hAmount, vAmount);
1956 return r;
1957 }
1958
1967 constexpr FRect& Extend(float amount) { return Extend(amount, amount); }
1968
1980 constexpr FRect& Extend(float hAmount, float vAmount)
1981 {
1982 x -= hAmount;
1983 y -= vAmount;
1984 w += hAmount * 2;
1985 h += vAmount * 2;
1986 return *this;
1987 }
1988
1997 constexpr FRect operator+(const FPoint& offset) const
1998 {
1999 return FRect(x + offset.x, y + offset.y, w, h);
2000 }
2001
2010 constexpr FRect operator-(const FPoint& offset) const
2011 {
2012 return FRect(x - offset.x, y - offset.y, w, h);
2013 }
2014
2023 constexpr FRect& operator+=(const FPoint& offset)
2024 {
2025 x += offset.x;
2026 y += offset.y;
2027 return *this;
2028 }
2029
2038 constexpr FRect& operator-=(const FPoint& offset)
2039 {
2040 x -= offset.x;
2041 y -= offset.y;
2042 return *this;
2043 }
2044};
2045
2056inline FRect RectToFRect(const RectRaw& rect)
2057{
2058 FRect frect;
2059 SDL_RectToFRect(&rect, &frect);
2060 return frect;
2061}
2062
2063inline Rect::operator SDL_FRect() const { return SDL::RectToFRect(*this); }
2064
2086inline bool PointInRect(const PointRaw& p, const RectRaw& r)
2087{
2088 return SDL_PointInRect(&p, &r);
2089}
2090
2091inline bool Point::InRect(const RectRaw& r) const
2092{
2093 return SDL::PointInRect(*this, r);
2094}
2095
2114inline bool RectEmpty(const RectRaw& r) { return SDL_RectEmpty(&r); }
2115
2116inline bool Rect::Empty() const { return SDL::RectEmpty(*this); }
2117
2137inline bool RectsEqual(const RectRaw& a, const RectRaw& b)
2138{
2139 return SDL_RectsEqual(&a, &b);
2140}
2141
2142inline bool Rect::Equal(const RectRaw& other) const
2143{
2144 return SDL::RectsEqual(*this, other);
2145}
2146
2162inline bool HasRectIntersection(const RectRaw& A, const RectRaw& B)
2163{
2164 return SDL_HasRectIntersection(&A, &B);
2165}
2166
2167inline bool Rect::HasIntersection(const RectRaw& other) const
2168{
2169 return SDL::HasRectIntersection(*this, other);
2170}
2171
2188inline Rect GetRectIntersection(const RectRaw& A, const RectRaw& B)
2189{
2190 if (Rect result; SDL_GetRectIntersection(&A, &B, &result)) return result;
2191 return {};
2192}
2193
2194inline Rect Rect::GetIntersection(const RectRaw& other) const
2195{
2196 return SDL::GetRectIntersection(*this, other);
2197}
2198
2211constexpr Rect GetRectUnion(const RectRaw& A, const RectRaw& B)
2212{
2213 Rect r;
2214 CheckError(SDL_GetRectUnion(&A, &B, &r));
2215 return r;
2216}
2217
2218constexpr Rect Rect::GetUnion(const RectRaw& other) const
2219{
2220 return SDL::GetRectUnion(*this, other);
2221}
2222
2241 OptionalRef<const RectRaw> clip = std::nullopt)
2242{
2243 if (Rect result; SDL_GetRectEnclosingPoints(
2244 points.data(), narrowS32(points.size()), clip, &result)) {
2245 return result;
2246 }
2247 return {};
2248}
2249
2255
2276inline bool GetRectAndLineIntersection(const RectRaw& rect,
2277 int* X1,
2278 int* Y1,
2279 int* X2,
2280 int* Y2)
2281{
2282 return SDL_GetRectAndLineIntersection(&rect, X1, Y1, X2, Y2);
2283}
2284
2285inline bool Rect::GetLineIntersection(int* X1, int* Y1, int* X2, int* Y2) const
2286{
2287 return SDL::GetRectAndLineIntersection(*this, X1, Y1, X2, Y2);
2288}
2289
2311inline bool PointInRectFloat(const FPointRaw& p, const FRectRaw& r)
2312{
2313 return SDL_PointInRectFloat(&p, &r);
2314}
2315
2316inline bool FPoint::InRect(const FRectRaw& r) const
2317{
2318 return SDL::PointInRectFloat(*this, r);
2319}
2320
2339inline bool RectEmptyFloat(const FRectRaw& r) { return SDL_RectEmptyFloat(&r); }
2340
2341inline bool FRect::Empty() const { return SDL::RectEmptyFloat(*this); }
2342
2368inline bool RectsEqualEpsilon(const FRectRaw& a,
2369 const FRectRaw& b,
2370 const float epsilon)
2371{
2372 return SDL_RectsEqualEpsilon(&a, &b, epsilon);
2373}
2374
2375inline bool FRect::EqualEpsilon(const FRectRaw& other,
2376 const float epsilon) const
2377{
2378 return SDL::RectsEqualEpsilon(*this, other, epsilon);
2379}
2380
2406inline bool RectsEqualFloat(const FRectRaw& a, const FRectRaw& b)
2407{
2408 return SDL_RectsEqualFloat(&a, &b);
2409}
2410
2411inline bool FRect::Equal(const FRectRaw& other) const
2412{
2413 return SDL::RectsEqualFloat(*this, other);
2414}
2415
2431inline bool HasRectIntersectionFloat(const FRectRaw& A, const FRectRaw& B)
2432{
2433 return SDL_HasRectIntersectionFloat(&A, &B);
2434}
2435
2436inline bool FRect::HasIntersection(const FRectRaw& other) const
2437{
2438 return SDL::HasRectIntersectionFloat(*this, other);
2439}
2440
2458{
2459 if (FRect r; SDL_GetRectIntersectionFloat(&A, &B, &r)) return r;
2460 return {};
2461}
2462
2463inline FRect FRect::GetIntersection(const FRectRaw& other) const
2464{
2465 return SDL::GetRectIntersectionFloat(*this, other);
2466}
2467
2481constexpr FRect GetRectUnionFloat(const FRectRaw& A, const FRectRaw& B)
2482{
2483 FRect r;
2484 CheckError(SDL_GetRectUnionFloat(&A, &B, &r));
2485 return r;
2486}
2487
2488constexpr FRect FRect::GetUnion(const FRectRaw& other) const
2489{
2490 return SDL::GetRectUnionFloat(*this, other);
2491}
2492
2511 OptionalRef<const FRectRaw> clip = std::nullopt)
2512{
2513 if (FRect result; SDL_GetRectEnclosingPointsFloat(
2514 points.data(), narrowS32(points.size()), clip, &result)) {
2515 return result;
2516 }
2517 return {};
2518}
2519
2525
2548 float* X1,
2549 float* Y1,
2550 float* X2,
2551 float* Y2)
2552{
2553 return SDL_GetRectAndLineIntersectionFloat(&rect, X1, Y1, X2, Y2);
2554}
2555
2556inline bool FRect::GetLineIntersection(float* X1,
2557 float* Y1,
2558 float* X2,
2559 float* Y2) const
2560{
2561 return SDL::GetRectAndLineIntersectionFloat(*this, X1, Y1, X2, Y2);
2562}
2563
2565
2566constexpr Point::operator FPoint() const { return {float(x), float(y)}; }
2567
2568constexpr FPoint Point::operator/(float value) const
2569{
2570 return FPoint(*this) / value;
2571}
2572constexpr FPoint Point::operator*(float value) const
2573{
2574 return FPoint(*this) * value;
2575}
2576
2577constexpr Point Point::GetClamped(const Rect& rect) const
2578{
2579 Point p = *this;
2580 p.Clamp(rect);
2581 return p;
2582}
2583
2584constexpr Point& Point::Clamp(const Rect& rect)
2585{
2586 if (x < rect.x) x = rect.x;
2587 if (x > rect.GetX2()) x = rect.GetX2();
2588 if (y < rect.y) y = rect.y;
2589 if (y > rect.GetY2()) y = rect.GetY2();
2590 return *this;
2591}
2592
2593constexpr Point Point::GetWrapped(const Rect& rect) const
2594{
2595 Point p = *this;
2596 p.Wrap(rect);
2597 return p;
2598}
2599
2600constexpr Point& Point::Wrap(const Rect& rect)
2601{
2602 if (x < rect.x)
2603 x = rect.x + rect.w - 1 - (rect.x - x + rect.w - 1) % rect.w;
2604 else if (x >= rect.x + rect.w)
2605 x = rect.x + (x - rect.x - rect.w) % rect.w;
2606
2607 if (y < rect.y)
2608 y = rect.y + rect.h - 1 - (rect.y - y + rect.h - 1) % rect.h;
2609 else if (y >= rect.y + rect.h)
2610 y = rect.y + (y - rect.y - rect.h) % rect.h;
2611
2612 return *this;
2613}
2614
2615constexpr FPoint FPoint::GetClamped(const FRect& rect) const
2616{
2617 FPoint p = *this;
2618 p.Clamp(rect);
2619 return p;
2620}
2621
2622constexpr FPoint& FPoint::Clamp(const FRect& rect)
2623{
2624 if (x < rect.x) x = rect.x;
2625 if (x > rect.GetX2()) x = rect.GetX2();
2626 if (y < rect.y) y = rect.y;
2627 if (y > rect.GetY2()) y = rect.GetY2();
2628 return *this;
2629}
2630
2631constexpr FPoint FPoint::GetWrapped(const FRect& rect) const
2632{
2633 FPoint p = *this;
2634 p.Wrap(rect);
2635 return p;
2636}
2637
2638constexpr FPoint& FPoint::Wrap(const FRect& rect)
2639{
2640 if (x < rect.x)
2641 x = rect.x + rect.w - 1 - SDL::fmod(rect.x - x + rect.w - 1, rect.w);
2642 else if (x >= rect.x + rect.w)
2643 x = rect.x + SDL::fmod(x - rect.x - rect.w, rect.w);
2644
2645 if (y < rect.y)
2646 y = rect.y + rect.h - 1 - SDL::fmod(rect.y - y + rect.h - 1, rect.h);
2647 else if (y >= rect.y + rect.h)
2648 y = rect.y + SDL::fmod(y - rect.y - rect.h, rect.h);
2649
2650 return *this;
2651}
2652
2653constexpr Rect::operator FRect() const
2654{
2655 return {float(x), float(y), float(w), float(h)};
2656}
2657
2658} // namespace SDL
2659
2660#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:2103
constexpr auto operator<=>(ColorRaw lhs, ColorRaw rhs) noexcept
Spaceship operator for Color.
Definition SDL3pp_pixels.h:2115
FRect RectToFRect(const RectRaw &rect)
Convert an Rect to FRect.
Definition SDL3pp_rect.h:2056
bool Equal(const RectRaw &other) const
Determine whether two rectangles are equal.
Definition SDL3pp_rect.h:2142
Rect GetRectIntersection(const RectRaw &A, const RectRaw &B)
Calculate the intersection of two rectangles.
Definition SDL3pp_rect.h:2188
bool HasIntersection(const RectRaw &other) const
Determine whether two rectangles intersect.
Definition SDL3pp_rect.h:2167
constexpr FRect GetRectUnionFloat(const FRectRaw &A, const FRectRaw &B)
Calculate the union of two rectangles with float precision.
Definition SDL3pp_rect.h:2481
bool HasRectIntersection(const RectRaw &A, const RectRaw &B)
Determine whether two rectangles intersect.
Definition SDL3pp_rect.h:2162
bool InRect(const RectRaw &r) const
Determine whether a point resides inside a rectangle.
Definition SDL3pp_rect.h:2091
SDL_Rect RectRaw
Alias to raw representation for Rect.
Definition SDL3pp_rect.h:34
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:2375
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:2520
bool Equal(const FRectRaw &other) const
Determine whether two floating point rectangles are equal, within a default epsilon.
Definition SDL3pp_rect.h:2411
bool RectsEqual(const RectRaw &a, const RectRaw &b)
Determine whether two rectangles are equal.
Definition SDL3pp_rect.h:2137
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:2556
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:2239
SDL_FRect FRectRaw
Alias to raw representation for FRect.
Definition SDL3pp_rect.h:40
Rect GetIntersection(const RectRaw &other) const
Calculate the intersection of two rectangles.
Definition SDL3pp_rect.h:2194
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:2547
bool HasRectIntersectionFloat(const FRectRaw &A, const FRectRaw &B)
Determine whether two rectangles intersect with float precision.
Definition SDL3pp_rect.h:2431
FRect GetRectIntersectionFloat(const FRectRaw &A, const FRectRaw &B)
Calculate the intersection of two rectangles with float precision.
Definition SDL3pp_rect.h:2457
bool PointInRect(const PointRaw &p, const RectRaw &r)
Determine whether a point resides inside a rectangle.
Definition SDL3pp_rect.h:2086
bool RectEmptyFloat(const FRectRaw &r)
Determine whether a floating point rectangle takes no space.
Definition SDL3pp_rect.h:2339
bool InRect(const FRectRaw &r) const
Determine whether a point resides inside a floating point rectangle.
Definition SDL3pp_rect.h:2316
bool RectEmpty(const RectRaw &r)
Determine whether a rectangle has no area.
Definition SDL3pp_rect.h:2114
SDL_FPoint FPointRaw
Alias to raw representation for FPoint.
Definition SDL3pp_rect.h:28
constexpr Rect GetUnion(const RectRaw &other) const
Calculate the union of two rectangles.
Definition SDL3pp_rect.h:2218
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:2250
bool HasIntersection(const FRectRaw &other) const
Determine whether two rectangles intersect with float precision.
Definition SDL3pp_rect.h:2436
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:2368
bool Empty() const
Determine whether a rectangle has no area.
Definition SDL3pp_rect.h:2341
constexpr Rect GetRectUnion(const RectRaw &A, const RectRaw &B)
Calculate the union of two rectangles.
Definition SDL3pp_rect.h:2211
bool RectsEqualFloat(const FRectRaw &a, const FRectRaw &b)
Determine whether two floating point rectangles are equal, within a default epsilon.
Definition SDL3pp_rect.h:2406
FRect GetIntersection(const FRectRaw &other) const
Calculate the intersection of two rectangles with float precision.
Definition SDL3pp_rect.h:2463
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:2276
constexpr FRect GetUnion(const FRectRaw &other) const
Calculate the union of two rectangles with float precision.
Definition SDL3pp_rect.h:2488
bool PointInRectFloat(const FPointRaw &p, const FRectRaw &r)
Determine whether a point resides inside a floating point rectangle.
Definition SDL3pp_rect.h:2311
bool Empty() const
Determine whether a rectangle has no area.
Definition SDL3pp_rect.h:2116
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:2509
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:5201
Main include header for the SDL3pp library.
Sint32 narrowS32(T value)
Narrows to Sint32.
Definition SDL3pp_stdinc.h:6257
The structure that defines a point (using floating point values).
Definition SDL3pp_rect.h:526
constexpr float GetY() const noexcept
Get the y coordinate.
Definition SDL3pp_rect.h:582
constexpr FPoint operator/(const FPoint &other) const
Get point's memberwise division by another point.
Definition SDL3pp_rect.h:675
constexpr FPoint & Wrap(const FRect &rect)
Wrap point coordinates within a specified rect.
Definition SDL3pp_rect.h:2638
constexpr FPoint operator-() const
Get point's memberwise negation.
Definition SDL3pp_rect.h:624
constexpr FPoint & operator/=(const FPoint &other)
Memberwise divide by another point.
Definition SDL3pp_rect.h:763
constexpr float GetX() const noexcept
Get the x coordinate.
Definition SDL3pp_rect.h:563
constexpr FPoint operator/(float value) const
Get point's memberwise division by an float.
Definition SDL3pp_rect.h:661
constexpr FPoint operator-(const FPoint &other) const
Get point's memberwise subtraction with another point.
Definition SDL3pp_rect.h:647
constexpr FPoint operator*(float value) const
Get point's memberwise multiplication by an float.
Definition SDL3pp_rect.h:690
constexpr FPoint(float x, float y) noexcept
Constructs from its fields.
Definition SDL3pp_rect.h:543
constexpr FPoint & operator/=(float value)
Memberwise divide by an float.
Definition SDL3pp_rect.h:748
constexpr FPoint & SetX(float newX) noexcept
Set the x coordinate.
Definition SDL3pp_rect.h:571
constexpr FPoint GetClamped(const FRect &rect) const
Get a point with coordinates modified so it fits into a given rect.
Definition SDL3pp_rect.h:2615
constexpr FPoint & operator*=(const FPoint &other)
Memberwise multiply by another point.
Definition SDL3pp_rect.h:793
constexpr FPoint & SetY(float newY) noexcept
Set the y coordinate.
Definition SDL3pp_rect.h:590
constexpr FPoint GetWrapped(const FRect &rect) const
Get a point wrapped within a specified rect.
Definition SDL3pp_rect.h:2631
constexpr FPoint operator+(const FPoint &other) const
Get point's memberwise addition with another point.
Definition SDL3pp_rect.h:634
constexpr FPoint & Clamp(const FRect &rect)
Clamp point coordinates to make it fit into a given rect.
Definition SDL3pp_rect.h:2622
constexpr FPoint & operator*=(float value)
Memberwise multiply by an float.
Definition SDL3pp_rect.h:778
constexpr FPoint(const FPointRaw &p={}) noexcept
Wraps FPoint.
Definition SDL3pp_rect.h:532
constexpr FPoint & operator-=(const FPoint &other)
Memberwise subtract another point.
Definition SDL3pp_rect.h:733
constexpr FPoint operator*(const FPoint &other) const
Get point's memberwise multiplication by another point.
Definition SDL3pp_rect.h:705
constexpr FPoint & operator+=(const FPoint &other)
Memberwise add another point.
Definition SDL3pp_rect.h:718
A rectangle stored using floating point values.
Definition SDL3pp_rect.h:1457
constexpr FRect & Extend(float hAmount, float vAmount)
Extend a rect by specified amount of pixels.
Definition SDL3pp_rect.h:1980
constexpr FRect operator+(const FPoint &offset) const
Get rectangle moved by a given offset.
Definition SDL3pp_rect.h:1997
constexpr FRect & SetX(float newX) noexcept
Set the left x coordinate.
Definition SDL3pp_rect.h:1505
static constexpr FRect FromCorners(FPoint p1, FPoint p2)
Construct the rect from given centers coordinates.
Definition SDL3pp_rect.h:1638
constexpr FRect(float x, float y, float w, float h) noexcept
Constructs from its fields.
Definition SDL3pp_rect.h:1476
constexpr float GetH() const noexcept
Get height of the rect.
Definition SDL3pp_rect.h:1554
constexpr float GetY() const noexcept
Get top y coordinate.
Definition SDL3pp_rect.h:1516
constexpr FPoint GetTopRight() const
Get top right corner of the rect.
Definition SDL3pp_rect.h:1705
constexpr FRect operator-(const FPoint &offset) const
Get rectangle moved by an opposite of given offset.
Definition SDL3pp_rect.h:2010
bool Contains(const FPointRaw &p) const
Check whether the rect contains given point.
Definition SDL3pp_rect.h:1864
constexpr FRect & operator+=(const FPoint &offset)
Move by then given offset.
Definition SDL3pp_rect.h:2023
constexpr float GetX() const noexcept
Get left x coordinate.
Definition SDL3pp_rect.h:1497
static constexpr FRect FromCenter(FPoint center, FPoint size)
Construct the rect from given center coordinates and size.
Definition SDL3pp_rect.h:1612
bool Contains(const FRectRaw &other) const
Check whether the rect contains given point.
Definition SDL3pp_rect.h:1877
constexpr FRect & operator-=(const FPoint &offset)
Move by an opposite of the given offset.
Definition SDL3pp_rect.h:2038
constexpr FPoint GetBottomRight() const
Get bottom right corner of the rect.
Definition SDL3pp_rect.h:1721
constexpr FPoint GetBottomLeft() const
Get bottom left corner of the rect.
Definition SDL3pp_rect.h:1713
constexpr FRect(const FPointRaw &corner, const FPointRaw &size)
Constructs from top-left corner plus size.
Definition SDL3pp_rect.h:1484
constexpr float GetX2() const
Get X coordinate of the rect second corner.
Definition SDL3pp_rect.h:1649
constexpr FRect GetExtension(unsigned int amount) const
Get a rect extended by specified amount of pixels.
Definition SDL3pp_rect.h:1934
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:1600
constexpr float GetY2() const
Get Y coordinate of the rect second corner.
Definition SDL3pp_rect.h:1673
constexpr FRect & SetH(float newH) noexcept
Set the height of the rect.
Definition SDL3pp_rect.h:1562
constexpr FRect & SetY2(float y2)
Set Y coordinate of the rect second corner.
Definition SDL3pp_rect.h:1685
constexpr float GetW() const noexcept
Get width of the rect.
Definition SDL3pp_rect.h:1535
constexpr FRect & SetX2(float x2)
Set X coordinate of the rect second corner.
Definition SDL3pp_rect.h:1661
static constexpr FRect FromCorners(float x1, float y1, float x2, float y2)
Construct the rect from given corners coordinates.
Definition SDL3pp_rect.h:1626
constexpr FRect & Extend(float amount)
Extend a rect by specified amount of pixels.
Definition SDL3pp_rect.h:1967
constexpr FRect & SetY(float newY) noexcept
Set the top y coordinate.
Definition SDL3pp_rect.h:1524
constexpr FRect & SetW(float newW) noexcept
Set the width of the rect.
Definition SDL3pp_rect.h:1543
constexpr FRect GetExtension(float hAmount, float vAmount) const
Get a rect extended by specified amount of pixels.
Definition SDL3pp_rect.h:1952
constexpr FPoint GetCentroid() const
Get centroid of the rect.
Definition SDL3pp_rect.h:1737
bool GetLineIntersection(FPoint *p1, FPoint *p2) const
Determine whether a floating point rectangle takes no space.
Definition SDL3pp_rect.h:1777
constexpr FPoint GetTopLeft() const
Get top left corner of the rect.
Definition SDL3pp_rect.h:1697
constexpr FRect(const FRectRaw &r={}) noexcept
Wraps FRect.
Definition SDL3pp_rect.h:1463
constexpr FPoint GetSize() const
Get size of the rect.
Definition SDL3pp_rect.h:1729
The structure that defines a point (using integers).
Definition SDL3pp_rect.h:97
constexpr Point & operator/=(int value)
Memberwise divide by an integer.
Definition SDL3pp_rect.h:382
constexpr Point & operator%=(const Point &other)
Memberwise remainder from division by another point.
Definition SDL3pp_rect.h:428
constexpr Point(const PointRaw &p={}) noexcept
Wraps Point.
Definition SDL3pp_rect.h:103
constexpr Point operator/(int value) const
Get point's memberwise division by an integer.
Definition SDL3pp_rect.h:242
constexpr Point GetClamped(const Rect &rect) const
Get a point with coordinates modified so it fits into a given rect.
Definition SDL3pp_rect.h:2577
constexpr Point operator-(const Point &other) const
Get point's memberwise subtraction with another point.
Definition SDL3pp_rect.h:228
constexpr Point(int x, int y) noexcept
Constructs from its fields.
Definition SDL3pp_rect.h:114
constexpr Point operator+(const Point &other) const
Get point's memberwise addition with another point.
Definition SDL3pp_rect.h:215
constexpr Point & Clamp(const Rect &rect)
Clamp point coordinates to make it fit into a given rect.
Definition SDL3pp_rect.h:2584
constexpr Point operator*(const Point &other) const
Get point's memberwise multiplication by another point.
Definition SDL3pp_rect.h:339
constexpr Point & SetX(int newX) noexcept
Set the x coordinate.
Definition SDL3pp_rect.h:152
constexpr Point operator%(int value) const
Get point's memberwise remainder from division by an integer.
Definition SDL3pp_rect.h:282
constexpr Point & SetY(int newY) noexcept
Set the y coordinate.
Definition SDL3pp_rect.h:171
constexpr Point & operator*=(const Point &other)
Memberwise multiply by another point.
Definition SDL3pp_rect.h:458
constexpr Point & operator-=(const Point &other)
Memberwise subtract another point.
Definition SDL3pp_rect.h:367
constexpr Point operator*(int value) const
Get point's memberwise multiplication by an integer.
Definition SDL3pp_rect.h:312
constexpr int GetY() const noexcept
Get y coordinate.
Definition SDL3pp_rect.h:163
constexpr Point & operator/=(const Point &other)
Memberwise divide by another point.
Definition SDL3pp_rect.h:397
constexpr Point operator%(const Point &other) const
Get point's memberwise remainder from division by another point.
Definition SDL3pp_rect.h:297
constexpr int GetX() const noexcept
Get x coordinate.
Definition SDL3pp_rect.h:144
constexpr Point GetWrapped(const Rect &rect) const
Get a point wrapped within a specified rect.
Definition SDL3pp_rect.h:2593
constexpr Point & Wrap(const Rect &rect)
Wrap point coordinates within a specified rect.
Definition SDL3pp_rect.h:2600
constexpr Point & operator%=(int value)
Memberwise remainder from division by an integer.
Definition SDL3pp_rect.h:412
constexpr Point operator/(const Point &other) const
Get point's memberwise division by another point.
Definition SDL3pp_rect.h:267
constexpr Point & operator+=(const Point &other)
Memberwise add another point.
Definition SDL3pp_rect.h:352
constexpr Point operator-() const
Get point's memberwise negation.
Definition SDL3pp_rect.h:205
constexpr Point(const FPointRaw &p)
Wraps Point.
Definition SDL3pp_rect.h:124
constexpr Point & operator*=(int value)
Memberwise multiply by an integer.
Definition SDL3pp_rect.h:443
A rectangle, with the origin at the upper left (using integers).
Definition SDL3pp_rect.h:859
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:1013
bool Contains(const RectRaw &other) const
Check whether the rect contains given point.
Definition SDL3pp_rect.h:1269
constexpr Rect(const PointRaw &corner, const PointRaw &size)
Construct from offset and size.
Definition SDL3pp_rect.h:889
constexpr Rect & operator-=(const Point &offset)
Move by an opposite of the given offset.
Definition SDL3pp_rect.h:1427
bool GetLineIntersection(PointRaw *p1, PointRaw *p2) const
Calculate the intersection of a rectangle and line segment.
Definition SDL3pp_rect.h:1168
bool operator==(const RectRaw &other) const
Compares with the underlying type.
Definition SDL3pp_rect.h:895
constexpr Rect GetExtension(unsigned int hAmount, unsigned int vAmount) const
Get a rect extended by specified amount of pixels.
Definition SDL3pp_rect.h:1341
constexpr Point GetTopLeft() const
Get top left corner of the rect.
Definition SDL3pp_rect.h:1110
constexpr Rect & Extend(unsigned int hAmount, unsigned int vAmount)
Extend a rect by specified amount of pixels.
Definition SDL3pp_rect.h:1369
constexpr int GetY() const noexcept
Get top y coordinate.
Definition SDL3pp_rect.h:930
constexpr int GetH() const noexcept
Get height of the rect.
Definition SDL3pp_rect.h:968
constexpr Rect operator+(const Point &offset) const
Get rectangle moved by a given offset.
Definition SDL3pp_rect.h:1386
constexpr Rect & operator+=(const Point &offset)
Move by then given offset.
Definition SDL3pp_rect.h:1412
constexpr Rect(const RectRaw &r={}) noexcept
Wraps Rect.
Definition SDL3pp_rect.h:865
constexpr Rect GetExtension(unsigned int amount) const
Get a rect extended by specified amount of pixels.
Definition SDL3pp_rect.h:1323
constexpr Rect & SetY(int newY) noexcept
Set the top y coordinate.
Definition SDL3pp_rect.h:938
constexpr Rect & SetW(int newW) noexcept
Set the width of the rect.
Definition SDL3pp_rect.h:957
constexpr Rect & Extend(unsigned int amount)
Extend a rect by specified amount of pixels.
Definition SDL3pp_rect.h:1356
constexpr Point GetCentroid() const
Get centroid of the rect.
Definition SDL3pp_rect.h:1150
constexpr Point GetBottomLeft() const
Get bottom left corner of the rect.
Definition SDL3pp_rect.h:1126
constexpr Rect & SetX2(int x2)
Set X coordinate of the rect second corner.
Definition SDL3pp_rect.h:1074
static constexpr Rect FromCorners(Point p1, Point p2)
Construct the rect from given centers coordinates.
Definition SDL3pp_rect.h:1051
bool Contains(const PointRaw &p) const
Check whether the rect contains given point.
Definition SDL3pp_rect.h:1259
bool operator==(const Rect &other) const
Compares with the underlying type.
Definition SDL3pp_rect.h:898
static constexpr Rect FromCorners(int x1, int y1, int x2, int y2)
Construct the rect from given corners coordinates.
Definition SDL3pp_rect.h:1039
constexpr Rect(int x, int y, int w, int h) noexcept
Constructs from its fields.
Definition SDL3pp_rect.h:878
constexpr Point GetSize() const
Get size of the rect.
Definition SDL3pp_rect.h:1142
constexpr Rect operator-(const Point &offset) const
Get rectangle moved by an opposite of given offset.
Definition SDL3pp_rect.h:1399
constexpr Point GetBottomRight() const
Get bottom right corner of the rect.
Definition SDL3pp_rect.h:1134
constexpr int GetY2() const
Get Y coordinate of the rect second corner.
Definition SDL3pp_rect.h:1086
static constexpr Rect FromCenter(Point center, Point size)
Construct the rect from given center coordinates and size.
Definition SDL3pp_rect.h:1025
constexpr Rect & SetH(int newH) noexcept
Set the height of the rect.
Definition SDL3pp_rect.h:976
constexpr int GetW() const noexcept
Get width of the rect.
Definition SDL3pp_rect.h:949
constexpr Rect & SetX(int newX) noexcept
Set the left x coordinate.
Definition SDL3pp_rect.h:919
constexpr Rect & SetY2(int y2)
Set Y coordinate of the rect second corner.
Definition SDL3pp_rect.h:1098
constexpr int GetX() const noexcept
Get left x coordinate.
Definition SDL3pp_rect.h:911
constexpr Point GetTopRight() const
Get top right corner of the rect.
Definition SDL3pp_rect.h:1118
constexpr int GetX2() const
Get X coordinate of the rect second corner.
Definition SDL3pp_rect.h:1062