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 Point(int v) noexcept
125 : PointRaw{v, v}
126 {
127 }
128
134 constexpr explicit Point(const FPointRaw& p)
135 : SDL_Point{int(p.x), int(p.y)}
136 {
137 }
138
144 constexpr explicit operator bool() const noexcept
145 {
146 return *this != PointRaw{};
147 }
148
154 constexpr int GetX() const noexcept { return x; }
155
162 constexpr Point& SetX(int newX) noexcept
163 {
164 x = newX;
165 return *this;
166 }
167
173 constexpr int GetY() const noexcept { return y; }
174
181 constexpr Point& SetY(int newY) noexcept
182 {
183 y = newY;
184 return *this;
185 }
186
207 bool InRect(const RectRaw& r) const;
208
215 constexpr Point operator-() const { return Point(-x, -y); }
216
225 constexpr Point& operator+=(const Point& other)
226 {
227 x += other.x;
228 y += other.y;
229 return *this;
230 }
231
240 constexpr Point& operator-=(const Point& other)
241 {
242 x -= other.x;
243 y -= other.y;
244 return *this;
245 }
246
255 constexpr Point& operator/=(const Point& other)
256 {
257 x /= other.x;
258 y /= other.y;
259 return *this;
260 }
261
271 constexpr Point& operator%=(const Point& other)
272 {
273 x %= other.x;
274 y %= other.y;
275 return *this;
276 }
277
286 constexpr Point& operator*=(const Point& other)
287 {
288 x *= other.x;
289 y *= other.y;
290 return *this;
291 }
292
302 constexpr Point GetClamped(const Rect& rect) const;
303
313 constexpr Point& Clamp(const Rect& rect);
314
323 constexpr Point GetWrapped(const Rect& rect) const;
324
333 constexpr Point& Wrap(const Rect& rect);
334
340 constexpr operator FPoint() const;
341};
342
352constexpr Point operator+(const Point& lhs, const Point& rhs)
353{
354 return Point(lhs.x + rhs.x, lhs.y + rhs.y);
355}
356
366constexpr Point operator-(const Point& lhs, const Point& rhs)
367{
368 return Point(lhs.x - rhs.x, lhs.y - rhs.y);
369}
370
379constexpr Point operator/(const Point& lhs, const Point& rhs)
380{
381 return Point(lhs.x / rhs.x, lhs.y / rhs.y);
382}
383
392constexpr Point operator%(const Point& lhs, const Point& rhs)
393{
394 return Point(lhs.x % rhs.x, lhs.y % rhs.y);
395}
396
406constexpr Point operator*(const Point& lhs, const Point& rhs)
407{
408 return Point(lhs.x * rhs.x, lhs.y * rhs.y);
409}
410
422{
428 constexpr FPoint(const FPointRaw& p = {}) noexcept
429 : FPointRaw(p)
430 {
431 }
432
439 constexpr FPoint(float x, float y) noexcept
440 : FPointRaw{x, y}
441 {
442 }
443
449 constexpr FPoint(float v) noexcept
450 : FPointRaw{v, v}
451 {
452 }
453
459 constexpr explicit operator bool() const noexcept
460 {
461 return *this != FPointRaw{};
462 }
463
469 constexpr float GetX() const noexcept { return x; }
470
477 constexpr FPoint& SetX(float newX) noexcept
478 {
479 x = newX;
480 return *this;
481 }
482
488 constexpr float GetY() const noexcept { return y; }
489
496 constexpr FPoint& SetY(float newY) noexcept
497 {
498 y = newY;
499 return *this;
500 }
501
522 bool InRect(const FRectRaw& r) const;
523
530 constexpr FPoint operator-() const { return FPoint(-x, -y); }
531
540 constexpr FPoint& operator+=(const FPoint& other)
541 {
542 x += other.x;
543 y += other.y;
544 return *this;
545 }
546
555 constexpr FPoint& operator-=(const FPoint& other)
556 {
557 x -= other.x;
558 y -= other.y;
559 return *this;
560 }
561
570 constexpr FPoint& operator/=(const FPoint& other)
571 {
572 x /= other.x;
573 y /= other.y;
574 return *this;
575 }
576
585 constexpr FPoint& operator*=(const FPoint& other)
586 {
587 x *= other.x;
588 y *= other.y;
589 return *this;
590 }
591
601 constexpr FPoint GetClamped(const FRect& rect) const;
602
612 constexpr FPoint& Clamp(const FRect& rect);
613
622 constexpr FPoint GetWrapped(const FRect& rect) const;
623
632 constexpr FPoint& Wrap(const FRect& rect);
633};
634
644constexpr FPoint operator+(const FPoint& lhs, const FPoint& rhs)
645{
646 return FPoint(lhs.x + rhs.x, lhs.y + rhs.y);
647}
648
658constexpr FPoint operator-(const FPoint& lhs, const FPoint& rhs)
659{
660 return FPoint(lhs.x - rhs.x, lhs.y - rhs.y);
661}
662
671constexpr FPoint operator/(const FPoint& lhs, const FPoint& rhs)
672{
673 return FPoint(lhs.x / rhs.x, lhs.y / rhs.y);
674}
675
685constexpr FPoint operator*(const FPoint& lhs, const FPoint& rhs)
686{
687 return FPoint(lhs.x * rhs.x, lhs.y * rhs.y);
688}
689
705struct Rect : RectRaw
706{
712 constexpr Rect(const RectRaw& r = {}) noexcept
713 : RectRaw(r)
714 {
715 }
716
725 constexpr Rect(int x, int y, int w, int h) noexcept
726 : RectRaw{x, y, w, h}
727 {
728 }
729
735 constexpr explicit Rect(const FRectRaw& r)
736 : RectRaw{int(r.x), int(r.y), int(r.w), int(r.h)}
737 {
738 }
739
746 constexpr Rect(const Point& corner, const Point& size)
747 : RectRaw{corner.x, corner.y, size.x, size.y}
748 {
749 }
750
752 explicit operator bool() const { return !Empty(); }
753
755 const Point& position() const { return reinterpret_cast<const Point&>(x); }
756
758 Point& position() { return reinterpret_cast<Point&>(x); }
759
761 const Point& size() const { return reinterpret_cast<const Point&>(w); }
762
764 Point& size() { return reinterpret_cast<Point&>(w); }
765
771 constexpr int GetX() const noexcept { return x; }
772
779 constexpr Rect& SetX(int newX) noexcept
780 {
781 x = newX;
782 return *this;
783 }
784
790 constexpr int GetY() const noexcept { return y; }
791
798 constexpr Rect& SetY(int newY) noexcept
799 {
800 y = newY;
801 return *this;
802 }
803
809 constexpr int GetW() const noexcept { return w; }
810
817 constexpr Rect& SetW(int newW) noexcept
818 {
819 w = newW;
820 return *this;
821 }
822
828 constexpr int GetH() const noexcept { return h; }
829
836 constexpr Rect& SetH(int newH) noexcept
837 {
838 h = newH;
839 return *this;
840 }
841
862 OptionalRef<const RectRaw> clip = std::nullopt);
863
873 static constexpr Rect FromCenter(int cx, int cy, int w, int h)
874 {
875 return Rect(cx - w / 2, cy - h / 2, w, h);
876 }
877
885 static constexpr Rect FromCenter(Point center, Point size)
886 {
887 return Rect(center - size / 2, size);
888 }
889
899 static constexpr Rect FromCorners(int x1, int y1, int x2, int y2)
900 {
901 return Rect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
902 }
903
911 static constexpr Rect FromCorners(Point p1, Point p2)
912 {
913 return Rect(p1, p2 - p1 + Point(1, 1));
914 }
915
922 constexpr int GetX2() const { return x + w - 1; }
923
934 constexpr Rect& SetX2(int x2)
935 {
936 w = x2 - x + 1;
937 return *this;
938 }
939
946 constexpr int GetY2() const { return y + h - 1; }
947
958 constexpr Rect& SetY2(int y2)
959 {
960 h = y2 - y + 1;
961 return *this;
962 }
963
970 constexpr Point GetTopLeft() const { return Point(x, y); }
971
978 constexpr Point GetTopRight() const { return Point(GetX2(), y); }
979
986 constexpr Point GetBottomLeft() const { return Point(x, GetY2()); }
987
994 constexpr Point GetBottomRight() const { return Point(GetX2(), GetY2()); }
995
1001 constexpr Point GetPosition() const { return GetTopLeft(); }
1002
1010 constexpr Rect& SetPosition(const Point& position)
1011 {
1012 x = position.x;
1013 y = position.y;
1014 return *this;
1015 }
1016
1023 constexpr Point GetSize() const { return Point(w, h); }
1024
1031 constexpr Rect& SetSize(const Point& size)
1032 {
1033 w = size.x;
1034 h = size.y;
1035 return *this;
1036 }
1037
1044 constexpr Point GetCentroid() const { return Point(x + w / 2, y + h / 2); }
1045
1063 {
1064 return GetLineIntersection(p1 ? &p1->x : nullptr,
1065 p1 ? &p1->y : nullptr,
1066 p2 ? &p2->x : nullptr,
1067 p2 ? &p2->y : nullptr);
1068 }
1069
1089 bool GetLineIntersection(int* X1, int* Y1, int* X2, int* Y2) const;
1090
1101 operator SDL_FRect() const;
1102
1104 constexpr operator FRect() const;
1105
1123 bool Empty() const;
1124
1143 bool Equal(const RectRaw& other) const;
1144
1153 bool Contains(const PointRaw& p) const { return SDL_PointInRect(&p, this); }
1154
1163 bool Contains(const RectRaw& other) const { return GetUnion(other) == *this; }
1164
1177 bool HasIntersection(const RectRaw& other) const;
1178
1194 Rect GetIntersection(const RectRaw& other) const;
1195
1207 constexpr Rect GetUnion(const RectRaw& other) const;
1208
1217 constexpr Rect GetExtension(unsigned int amount) const
1218 {
1219 Rect r = *this;
1220 r.Extend(amount);
1221 return r;
1222 }
1223
1235 constexpr Rect GetExtension(unsigned int hAmount, unsigned int vAmount) const
1236 {
1237 Rect r = *this;
1238 r.Extend(hAmount, vAmount);
1239 return r;
1240 }
1241
1250 constexpr Rect& Extend(unsigned int amount) { return Extend(amount, amount); }
1251
1263 constexpr Rect& Extend(unsigned int hAmount, unsigned int vAmount)
1264 {
1265 x -= hAmount;
1266 y -= vAmount;
1267 w += hAmount * 2;
1268 h += vAmount * 2;
1269 return *this;
1270 }
1271
1280 constexpr Rect operator+(const Point& offset) const
1281 {
1282 return Rect(x + offset.x, y + offset.y, w, h);
1283 }
1284
1293 constexpr Rect operator-(const Point& offset) const
1294 {
1295 return Rect(x - offset.x, y - offset.y, w, h);
1296 }
1297
1306 constexpr Rect& operator+=(const Point& offset)
1307 {
1308 x += offset.x;
1309 y += offset.y;
1310 return *this;
1311 }
1312
1321 constexpr Rect& operator-=(const Point& offset)
1322 {
1323 x -= offset.x;
1324 y -= offset.y;
1325 return *this;
1326 }
1327};
1328
1351{
1357 constexpr FRect(const FRectRaw& r = {}) noexcept
1358 : FRectRaw(r)
1359 {
1360 }
1361
1370 constexpr FRect(float x, float y, float w, float h) noexcept
1371 : FRectRaw{x, y, w, h}
1372 {
1373 }
1374
1378 constexpr FRect(const FPoint& corner, const FPoint& size)
1379 : FRect{corner.x, corner.y, size.x, size.y}
1380 {
1381 }
1382
1384 operator bool() const { return !Empty(); }
1385
1387 const FPoint& position() const { return reinterpret_cast<const FPoint&>(x); }
1388
1390 FPoint& position() { return reinterpret_cast<FPoint&>(x); }
1391
1393 const FPoint& size() const { return reinterpret_cast<const FPoint&>(w); }
1394
1396 FPoint& size() { return reinterpret_cast<FPoint&>(w); }
1397
1403 constexpr float GetX() const noexcept { return x; }
1404
1411 constexpr FRect& SetX(float newX) noexcept
1412 {
1413 x = newX;
1414 return *this;
1415 }
1416
1422 constexpr float GetY() const noexcept { return y; }
1423
1430 constexpr FRect& SetY(float newY) noexcept
1431 {
1432 y = newY;
1433 return *this;
1434 }
1435
1441 constexpr float GetW() const noexcept { return w; }
1442
1449 constexpr FRect& SetW(float newW) noexcept
1450 {
1451 w = newW;
1452 return *this;
1453 }
1454
1460 constexpr float GetH() const noexcept { return h; }
1461
1468 constexpr FRect& SetH(float newH) noexcept
1469 {
1470 h = newH;
1471 return *this;
1472 }
1473
1495 OptionalRef<const FRectRaw> clip = std::nullopt);
1496
1506 static constexpr FRect FromCenter(float cx, float cy, float w, float h)
1507 {
1508 return FRect(cx - w / 2, cy - h / 2, w, h);
1509 }
1510
1518 static constexpr FRect FromCenter(FPoint center, FPoint size)
1519 {
1520 return FRect(center - size / 2, size);
1521 }
1522
1532 static constexpr FRect FromCorners(float x1, float y1, float x2, float y2)
1533 {
1534 return FRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
1535 }
1536
1544 static constexpr FRect FromCorners(FPoint p1, FPoint p2)
1545 {
1546 return FRect(p1, p2 - p1 + FPoint(1, 1));
1547 }
1548
1555 constexpr float GetX2() const { return x + w - 1; }
1556
1567 constexpr FRect& SetX2(float x2)
1568 {
1569 w = x2 - x + 1;
1570 return *this;
1571 }
1572
1579 constexpr float GetY2() const { return y + h - 1; }
1580
1591 constexpr FRect& SetY2(float y2)
1592 {
1593 h = y2 - y + 1;
1594 return *this;
1595 }
1596
1603 constexpr FPoint GetTopLeft() const { return FPoint(x, y); }
1604
1611 constexpr FPoint GetTopRight() const { return FPoint(GetX2(), y); }
1612
1619 constexpr FPoint GetBottomLeft() const { return FPoint(x, GetY2()); }
1620
1627 constexpr FPoint GetBottomRight() const { return FPoint(GetX2(), GetY2()); }
1628
1634 constexpr FPoint GetPosition() const { return GetTopLeft(); }
1635
1644 {
1645 x = position.x;
1646 y = position.y;
1647 return *this;
1648 }
1649
1656 constexpr FPoint GetSize() const { return FPoint(w, h); }
1657
1664 constexpr FRect& SetSize(const FPoint& size)
1665 {
1666 w = size.x;
1667 h = size.y;
1668 return *this;
1669 }
1670
1677 constexpr FPoint GetCentroid() const { return FPoint(x + w / 2, y + h / 2); }
1678
1699 bool GetLineIntersection(float* X1, float* Y1, float* X2, float* Y2) const;
1700
1717 bool GetLineIntersection(FPoint* p1, FPoint* p2) const
1718 {
1719 return GetLineIntersection(p1 ? &p1->x : nullptr,
1720 p1 ? &p1->y : nullptr,
1721 p2 ? &p2->x : nullptr,
1722 p2 ? &p2->y : nullptr);
1723 }
1724
1742 bool Empty() const;
1743
1768 bool EqualEpsilon(const FRectRaw& other, const float epsilon) const;
1769
1794 bool Equal(const FRectRaw& other) const;
1795
1804 bool Contains(const FPointRaw& p) const
1805 {
1806 return SDL_PointInRectFloat(&p, this);
1807 }
1808
1817 bool Contains(const FRectRaw& other) const
1818 {
1819 return GetUnion(other) == *this;
1820 }
1821
1834 bool HasIntersection(const FRectRaw& other) const;
1835
1851 FRect GetIntersection(const FRectRaw& other) const;
1852
1864 constexpr FRect GetUnion(const FRectRaw& other) const;
1865
1874 constexpr FRect GetExtension(unsigned int amount) const
1875 {
1876 FRect r = *this;
1877 r.Extend(float(amount));
1878 return r;
1879 }
1880
1892 constexpr FRect GetExtension(float hAmount, float vAmount) const
1893 {
1894 FRect r = *this;
1895 r.Extend(hAmount, vAmount);
1896 return r;
1897 }
1898
1907 constexpr FRect& Extend(float amount) { return Extend(amount, amount); }
1908
1920 constexpr FRect& Extend(float hAmount, float vAmount)
1921 {
1922 x -= hAmount;
1923 y -= vAmount;
1924 w += hAmount * 2;
1925 h += vAmount * 2;
1926 return *this;
1927 }
1928
1937 constexpr FRect operator+(const FPoint& offset) const
1938 {
1939 return FRect(x + offset.x, y + offset.y, w, h);
1940 }
1941
1950 constexpr FRect operator-(const FPoint& offset) const
1951 {
1952 return FRect(x - offset.x, y - offset.y, w, h);
1953 }
1954
1963 constexpr FRect& operator+=(const FPoint& offset)
1964 {
1965 x += offset.x;
1966 y += offset.y;
1967 return *this;
1968 }
1969
1978 constexpr FRect& operator-=(const FPoint& offset)
1979 {
1980 x -= offset.x;
1981 y -= offset.y;
1982 return *this;
1983 }
1984};
1985
1996inline FRect RectToFRect(const RectRaw& rect)
1997{
1998 FRect frect;
1999 SDL_RectToFRect(&rect, &frect);
2000 return frect;
2001}
2002
2003inline Rect::operator SDL_FRect() const { return SDL::RectToFRect(*this); }
2004
2026inline bool PointInRect(const PointRaw& p, const RectRaw& r)
2027{
2028 return SDL_PointInRect(&p, &r);
2029}
2030
2031inline bool Point::InRect(const RectRaw& r) const
2032{
2033 return SDL::PointInRect(*this, r);
2034}
2035
2054inline bool RectEmpty(const RectRaw& r) { return SDL_RectEmpty(&r); }
2055
2056inline bool Rect::Empty() const { return SDL::RectEmpty(*this); }
2057
2077inline bool RectsEqual(const RectRaw& a, const RectRaw& b)
2078{
2079 return SDL_RectsEqual(&a, &b);
2080}
2081
2082inline bool Rect::Equal(const RectRaw& other) const
2083{
2084 return SDL::RectsEqual(*this, other);
2085}
2086
2102inline bool HasRectIntersection(const RectRaw& A, const RectRaw& B)
2103{
2104 return SDL_HasRectIntersection(&A, &B);
2105}
2106
2107inline bool Rect::HasIntersection(const RectRaw& other) const
2108{
2109 return SDL::HasRectIntersection(*this, other);
2110}
2111
2128inline Rect GetRectIntersection(const RectRaw& A, const RectRaw& B)
2129{
2130 if (Rect result; SDL_GetRectIntersection(&A, &B, &result)) return result;
2131 return {};
2132}
2133
2134inline Rect Rect::GetIntersection(const RectRaw& other) const
2135{
2136 return SDL::GetRectIntersection(*this, other);
2137}
2138
2151constexpr Rect GetRectUnion(const RectRaw& A, const RectRaw& B)
2152{
2153 Rect r;
2154 CheckError(SDL_GetRectUnion(&A, &B, &r));
2155 return r;
2156}
2157
2158constexpr Rect Rect::GetUnion(const RectRaw& other) const
2159{
2160 return SDL::GetRectUnion(*this, other);
2161}
2162
2181 OptionalRef<const RectRaw> clip = std::nullopt)
2182{
2183 if (Rect result; SDL_GetRectEnclosingPoints(
2184 points.data(), narrowS32(points.size()), clip, &result)) {
2185 return result;
2186 }
2187 return {};
2188}
2189
2195
2216inline bool GetRectAndLineIntersection(const RectRaw& rect,
2217 int* X1,
2218 int* Y1,
2219 int* X2,
2220 int* Y2)
2221{
2222 return SDL_GetRectAndLineIntersection(&rect, X1, Y1, X2, Y2);
2223}
2224
2225inline bool Rect::GetLineIntersection(int* X1, int* Y1, int* X2, int* Y2) const
2226{
2227 return SDL::GetRectAndLineIntersection(*this, X1, Y1, X2, Y2);
2228}
2229
2251inline bool PointInRectFloat(const FPointRaw& p, const FRectRaw& r)
2252{
2253 return SDL_PointInRectFloat(&p, &r);
2254}
2255
2256inline bool FPoint::InRect(const FRectRaw& r) const
2257{
2258 return SDL::PointInRectFloat(*this, r);
2259}
2260
2279inline bool RectEmptyFloat(const FRectRaw& r) { return SDL_RectEmptyFloat(&r); }
2280
2281inline bool FRect::Empty() const { return SDL::RectEmptyFloat(*this); }
2282
2308inline bool RectsEqualEpsilon(const FRectRaw& a,
2309 const FRectRaw& b,
2310 const float epsilon)
2311{
2312 return SDL_RectsEqualEpsilon(&a, &b, epsilon);
2313}
2314
2315inline bool FRect::EqualEpsilon(const FRectRaw& other,
2316 const float epsilon) const
2317{
2318 return SDL::RectsEqualEpsilon(*this, other, epsilon);
2319}
2320
2346inline bool RectsEqualFloat(const FRectRaw& a, const FRectRaw& b)
2347{
2348 return SDL_RectsEqualFloat(&a, &b);
2349}
2350
2351inline bool FRect::Equal(const FRectRaw& other) const
2352{
2353 return SDL::RectsEqualFloat(*this, other);
2354}
2355
2371inline bool HasRectIntersectionFloat(const FRectRaw& A, const FRectRaw& B)
2372{
2373 return SDL_HasRectIntersectionFloat(&A, &B);
2374}
2375
2376inline bool FRect::HasIntersection(const FRectRaw& other) const
2377{
2378 return SDL::HasRectIntersectionFloat(*this, other);
2379}
2380
2398{
2399 if (FRect r; SDL_GetRectIntersectionFloat(&A, &B, &r)) return r;
2400 return {};
2401}
2402
2403inline FRect FRect::GetIntersection(const FRectRaw& other) const
2404{
2405 return SDL::GetRectIntersectionFloat(*this, other);
2406}
2407
2421constexpr FRect GetRectUnionFloat(const FRectRaw& A, const FRectRaw& B)
2422{
2423 FRect r;
2424 CheckError(SDL_GetRectUnionFloat(&A, &B, &r));
2425 return r;
2426}
2427
2428constexpr FRect FRect::GetUnion(const FRectRaw& other) const
2429{
2430 return SDL::GetRectUnionFloat(*this, other);
2431}
2432
2451 OptionalRef<const FRectRaw> clip = std::nullopt)
2452{
2453 if (FRect result; SDL_GetRectEnclosingPointsFloat(
2454 points.data(), narrowS32(points.size()), clip, &result)) {
2455 return result;
2456 }
2457 return {};
2458}
2459
2465
2488 float* X1,
2489 float* Y1,
2490 float* X2,
2491 float* Y2)
2492{
2493 return SDL_GetRectAndLineIntersectionFloat(&rect, X1, Y1, X2, Y2);
2494}
2495
2496inline bool FRect::GetLineIntersection(float* X1,
2497 float* Y1,
2498 float* X2,
2499 float* Y2) const
2500{
2501 return SDL::GetRectAndLineIntersectionFloat(*this, X1, Y1, X2, Y2);
2502}
2503
2505
2506constexpr Point::operator FPoint() const { return {float(x), float(y)}; }
2507
2508constexpr Point Point::GetClamped(const Rect& rect) const
2509{
2510 Point p = *this;
2511 p.Clamp(rect);
2512 return p;
2513}
2514
2515constexpr Point& Point::Clamp(const Rect& rect)
2516{
2517 if (x < rect.x) x = rect.x;
2518 if (x > rect.GetX2()) x = rect.GetX2();
2519 if (y < rect.y) y = rect.y;
2520 if (y > rect.GetY2()) y = rect.GetY2();
2521 return *this;
2522}
2523
2524constexpr Point Point::GetWrapped(const Rect& rect) const
2525{
2526 Point p = *this;
2527 p.Wrap(rect);
2528 return p;
2529}
2530
2531constexpr Point& Point::Wrap(const Rect& rect)
2532{
2533 if (x < rect.x)
2534 x = rect.x + rect.w - 1 - (rect.x - x + rect.w - 1) % rect.w;
2535 else if (x >= rect.x + rect.w)
2536 x = rect.x + (x - rect.x - rect.w) % rect.w;
2537
2538 if (y < rect.y)
2539 y = rect.y + rect.h - 1 - (rect.y - y + rect.h - 1) % rect.h;
2540 else if (y >= rect.y + rect.h)
2541 y = rect.y + (y - rect.y - rect.h) % rect.h;
2542
2543 return *this;
2544}
2545
2546constexpr FPoint FPoint::GetClamped(const FRect& rect) const
2547{
2548 FPoint p = *this;
2549 p.Clamp(rect);
2550 return p;
2551}
2552
2553constexpr FPoint& FPoint::Clamp(const FRect& rect)
2554{
2555 if (x < rect.x) x = rect.x;
2556 if (x > rect.GetX2()) x = rect.GetX2();
2557 if (y < rect.y) y = rect.y;
2558 if (y > rect.GetY2()) y = rect.GetY2();
2559 return *this;
2560}
2561
2562constexpr FPoint FPoint::GetWrapped(const FRect& rect) const
2563{
2564 FPoint p = *this;
2565 p.Wrap(rect);
2566 return p;
2567}
2568
2569constexpr FPoint& FPoint::Wrap(const FRect& rect)
2570{
2571 if (x < rect.x)
2572 x = rect.x + rect.w - 1 - SDL::fmod(rect.x - x + rect.w - 1, rect.w);
2573 else if (x >= rect.x + rect.w)
2574 x = rect.x + SDL::fmod(x - rect.x - rect.w, rect.w);
2575
2576 if (y < rect.y)
2577 y = rect.y + rect.h - 1 - SDL::fmod(rect.y - y + rect.h - 1, rect.h);
2578 else if (y >= rect.y + rect.h)
2579 y = rect.y + SDL::fmod(y - rect.y - rect.h, rect.h);
2580
2581 return *this;
2582}
2583
2584constexpr Rect::operator FRect() const
2585{
2586 return {float(x), float(y), float(w), float(h)};
2587}
2588
2589} // namespace SDL
2590
2591#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:2079
constexpr auto operator<=>(ColorRaw lhs, ColorRaw rhs) noexcept
Spaceship operator for Color.
Definition SDL3pp_pixels.h:2091
FRect RectToFRect(const RectRaw &rect)
Convert an Rect to FRect.
Definition SDL3pp_rect.h:1996
bool Equal(const RectRaw &other) const
Determine whether two rectangles are equal.
Definition SDL3pp_rect.h:2082
Rect GetRectIntersection(const RectRaw &A, const RectRaw &B)
Calculate the intersection of two rectangles.
Definition SDL3pp_rect.h:2128
bool HasIntersection(const RectRaw &other) const
Determine whether two rectangles intersect.
Definition SDL3pp_rect.h:2107
constexpr FRect GetRectUnionFloat(const FRectRaw &A, const FRectRaw &B)
Calculate the union of two rectangles with float precision.
Definition SDL3pp_rect.h:2421
bool HasRectIntersection(const RectRaw &A, const RectRaw &B)
Determine whether two rectangles intersect.
Definition SDL3pp_rect.h:2102
bool InRect(const RectRaw &r) const
Determine whether a point resides inside a rectangle.
Definition SDL3pp_rect.h:2031
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:2315
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:2460
bool Equal(const FRectRaw &other) const
Determine whether two floating point rectangles are equal, within a default epsilon.
Definition SDL3pp_rect.h:2351
bool RectsEqual(const RectRaw &a, const RectRaw &b)
Determine whether two rectangles are equal.
Definition SDL3pp_rect.h:2077
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:2496
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:2179
SDL_FRect FRectRaw
Alias to raw representation for FRect.
Definition SDL3pp_rect.h:40
constexpr Point operator+(const Point &lhs, const Point &rhs)
Get point's memberwise addition with another point.
Definition SDL3pp_rect.h:352
Rect GetIntersection(const RectRaw &other) const
Calculate the intersection of two rectangles.
Definition SDL3pp_rect.h:2134
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:2487
bool HasRectIntersectionFloat(const FRectRaw &A, const FRectRaw &B)
Determine whether two rectangles intersect with float precision.
Definition SDL3pp_rect.h:2371
FRect GetRectIntersectionFloat(const FRectRaw &A, const FRectRaw &B)
Calculate the intersection of two rectangles with float precision.
Definition SDL3pp_rect.h:2397
bool PointInRect(const PointRaw &p, const RectRaw &r)
Determine whether a point resides inside a rectangle.
Definition SDL3pp_rect.h:2026
bool RectEmptyFloat(const FRectRaw &r)
Determine whether a floating point rectangle takes no space.
Definition SDL3pp_rect.h:2279
bool InRect(const FRectRaw &r) const
Determine whether a point resides inside a floating point rectangle.
Definition SDL3pp_rect.h:2256
constexpr Point operator*(const Point &lhs, const Point &rhs)
Get point's memberwise multiplication with another point.
Definition SDL3pp_rect.h:406
bool RectEmpty(const RectRaw &r)
Determine whether a rectangle has no area.
Definition SDL3pp_rect.h:2054
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:2158
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:2190
bool HasIntersection(const FRectRaw &other) const
Determine whether two rectangles intersect with float precision.
Definition SDL3pp_rect.h:2376
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:2308
bool Empty() const
Determine whether a rectangle has no area.
Definition SDL3pp_rect.h:2281
constexpr Rect GetRectUnion(const RectRaw &A, const RectRaw &B)
Calculate the union of two rectangles.
Definition SDL3pp_rect.h:2151
bool RectsEqualFloat(const FRectRaw &a, const FRectRaw &b)
Determine whether two floating point rectangles are equal, within a default epsilon.
Definition SDL3pp_rect.h:2346
constexpr Point operator/(const Point &lhs, const Point &rhs)
Get point's memberwise division by another point.
Definition SDL3pp_rect.h:379
FRect GetIntersection(const FRectRaw &other) const
Calculate the intersection of two rectangles with float precision.
Definition SDL3pp_rect.h:2403
constexpr Point operator%(const Point &lhs, const Point &rhs)
Get point's memberwise remainder from division by another point.
Definition SDL3pp_rect.h:392
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:2216
constexpr FRect GetUnion(const FRectRaw &other) const
Calculate the union of two rectangles with float precision.
Definition SDL3pp_rect.h:2428
bool PointInRectFloat(const FPointRaw &p, const FRectRaw &r)
Determine whether a point resides inside a floating point rectangle.
Definition SDL3pp_rect.h:2251
bool Empty() const
Determine whether a rectangle has no area.
Definition SDL3pp_rect.h:2056
constexpr Point operator-(const Point &lhs, const Point &rhs)
Get point's memberwise subtraction with another point.
Definition SDL3pp_rect.h:366
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:2449
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:5207
Main include header for the SDL3pp library.
Sint32 narrowS32(T value)
Narrows to Sint32.
Definition SDL3pp_stdinc.h:6263
The structure that defines a point (using floating point values).
Definition SDL3pp_rect.h:422
constexpr float GetY() const noexcept
Get the y coordinate.
Definition SDL3pp_rect.h:488
constexpr FPoint & Wrap(const FRect &rect)
Wrap point coordinates within a specified rect.
Definition SDL3pp_rect.h:2569
constexpr FPoint operator-() const
Get point's memberwise negation.
Definition SDL3pp_rect.h:530
constexpr FPoint & operator/=(const FPoint &other)
Memberwise divide by another point.
Definition SDL3pp_rect.h:570
constexpr float GetX() const noexcept
Get the x coordinate.
Definition SDL3pp_rect.h:469
constexpr FPoint(float x, float y) noexcept
Constructs from its fields.
Definition SDL3pp_rect.h:439
constexpr FPoint & SetX(float newX) noexcept
Set the x coordinate.
Definition SDL3pp_rect.h:477
constexpr FPoint GetClamped(const FRect &rect) const
Get a point with coordinates modified so it fits into a given rect.
Definition SDL3pp_rect.h:2546
constexpr FPoint & operator*=(const FPoint &other)
Memberwise multiply by another point.
Definition SDL3pp_rect.h:585
constexpr FPoint & SetY(float newY) noexcept
Set the y coordinate.
Definition SDL3pp_rect.h:496
constexpr FPoint GetWrapped(const FRect &rect) const
Get a point wrapped within a specified rect.
Definition SDL3pp_rect.h:2562
constexpr FPoint & Clamp(const FRect &rect)
Clamp point coordinates to make it fit into a given rect.
Definition SDL3pp_rect.h:2553
constexpr FPoint(const FPointRaw &p={}) noexcept
Wraps FPoint.
Definition SDL3pp_rect.h:428
constexpr FPoint & operator-=(const FPoint &other)
Memberwise subtract another point.
Definition SDL3pp_rect.h:555
constexpr FPoint(float v) noexcept
Constructs from its fields.
Definition SDL3pp_rect.h:449
constexpr FPoint & operator+=(const FPoint &other)
Memberwise add another point.
Definition SDL3pp_rect.h:540
A rectangle stored using floating point values.
Definition SDL3pp_rect.h:1351
constexpr FRect(const FPoint &corner, const FPoint &size)
Constructs from top-left corner plus size.
Definition SDL3pp_rect.h:1378
constexpr FRect & Extend(float hAmount, float vAmount)
Extend a rect by specified amount of pixels.
Definition SDL3pp_rect.h:1920
constexpr FRect operator+(const FPoint &offset) const
Get rectangle moved by a given offset.
Definition SDL3pp_rect.h:1937
const FPoint & size() const
Definition SDL3pp_rect.h:1393
constexpr FRect & SetX(float newX) noexcept
Set the left x coordinate.
Definition SDL3pp_rect.h:1411
static constexpr FRect FromCorners(FPoint p1, FPoint p2)
Construct the rect from given centers coordinates.
Definition SDL3pp_rect.h:1544
constexpr FRect(float x, float y, float w, float h) noexcept
Constructs from its fields.
Definition SDL3pp_rect.h:1370
constexpr float GetH() const noexcept
Get height of the rect.
Definition SDL3pp_rect.h:1460
const FPoint & position() const
Definition SDL3pp_rect.h:1387
constexpr float GetY() const noexcept
Get top y coordinate.
Definition SDL3pp_rect.h:1422
constexpr FRect & SetSize(const FPoint &size)
Set the size of the rect.
Definition SDL3pp_rect.h:1664
constexpr FPoint GetPosition() const
Get the Position of the rect, which is the same as its top left corner.
Definition SDL3pp_rect.h:1634
constexpr FPoint GetTopRight() const
Get top right corner of the rect.
Definition SDL3pp_rect.h:1611
constexpr FRect operator-(const FPoint &offset) const
Get rectangle moved by an opposite of given offset.
Definition SDL3pp_rect.h:1950
bool Contains(const FPointRaw &p) const
Check whether the rect contains given point.
Definition SDL3pp_rect.h:1804
constexpr FRect & operator+=(const FPoint &offset)
Move by then given offset.
Definition SDL3pp_rect.h:1963
constexpr float GetX() const noexcept
Get left x coordinate.
Definition SDL3pp_rect.h:1403
static constexpr FRect FromCenter(FPoint center, FPoint size)
Construct the rect from given center coordinates and size.
Definition SDL3pp_rect.h:1518
bool Contains(const FRectRaw &other) const
Check whether the rect contains given point.
Definition SDL3pp_rect.h:1817
FPoint & size()
Definition SDL3pp_rect.h:1396
constexpr FRect & operator-=(const FPoint &offset)
Move by an opposite of the given offset.
Definition SDL3pp_rect.h:1978
constexpr FPoint GetBottomRight() const
Get bottom right corner of the rect.
Definition SDL3pp_rect.h:1627
constexpr FPoint GetBottomLeft() const
Get bottom left corner of the rect.
Definition SDL3pp_rect.h:1619
constexpr float GetX2() const
Get X coordinate of the rect second corner.
Definition SDL3pp_rect.h:1555
constexpr FRect GetExtension(unsigned int amount) const
Get a rect extended by specified amount of pixels.
Definition SDL3pp_rect.h:1874
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:1506
FPoint & position()
Definition SDL3pp_rect.h:1390
constexpr float GetY2() const
Get Y coordinate of the rect second corner.
Definition SDL3pp_rect.h:1579
constexpr FRect & SetH(float newH) noexcept
Set the height of the rect.
Definition SDL3pp_rect.h:1468
constexpr FRect & SetY2(float y2)
Set Y coordinate of the rect second corner.
Definition SDL3pp_rect.h:1591
constexpr float GetW() const noexcept
Get width of the rect.
Definition SDL3pp_rect.h:1441
constexpr FRect & SetX2(float x2)
Set X coordinate of the rect second corner.
Definition SDL3pp_rect.h:1567
static constexpr FRect FromCorners(float x1, float y1, float x2, float y2)
Construct the rect from given corners coordinates.
Definition SDL3pp_rect.h:1532
constexpr FRect & SetPosition(const FPoint &position)
Set the Position object.
Definition SDL3pp_rect.h:1643
constexpr FRect & Extend(float amount)
Extend a rect by specified amount of pixels.
Definition SDL3pp_rect.h:1907
constexpr FRect & SetY(float newY) noexcept
Set the top y coordinate.
Definition SDL3pp_rect.h:1430
constexpr FRect & SetW(float newW) noexcept
Set the width of the rect.
Definition SDL3pp_rect.h:1449
constexpr FRect GetExtension(float hAmount, float vAmount) const
Get a rect extended by specified amount of pixels.
Definition SDL3pp_rect.h:1892
constexpr FPoint GetCentroid() const
Get centroid of the rect.
Definition SDL3pp_rect.h:1677
bool GetLineIntersection(FPoint *p1, FPoint *p2) const
Determine whether a floating point rectangle takes no space.
Definition SDL3pp_rect.h:1717
constexpr FPoint GetTopLeft() const
Get top left corner of the rect.
Definition SDL3pp_rect.h:1603
constexpr FRect(const FRectRaw &r={}) noexcept
Wraps FRect.
Definition SDL3pp_rect.h:1357
constexpr FPoint GetSize() const
Get size of the rect.
Definition SDL3pp_rect.h:1656
The structure that defines a point (using integers).
Definition SDL3pp_rect.h:97
constexpr Point(int v) noexcept
Constructs from its fields.
Definition SDL3pp_rect.h:124
constexpr Point & operator%=(const Point &other)
Memberwise remainder from division by another point.
Definition SDL3pp_rect.h:271
constexpr Point(const PointRaw &p={}) noexcept
Wraps Point.
Definition SDL3pp_rect.h:103
constexpr Point GetClamped(const Rect &rect) const
Get a point with coordinates modified so it fits into a given rect.
Definition SDL3pp_rect.h:2508
constexpr Point(int x, int y) noexcept
Constructs from its fields.
Definition SDL3pp_rect.h:114
constexpr Point & Clamp(const Rect &rect)
Clamp point coordinates to make it fit into a given rect.
Definition SDL3pp_rect.h:2515
constexpr Point & SetX(int newX) noexcept
Set the x coordinate.
Definition SDL3pp_rect.h:162
constexpr Point & SetY(int newY) noexcept
Set the y coordinate.
Definition SDL3pp_rect.h:181
constexpr Point & operator*=(const Point &other)
Memberwise multiply by another point.
Definition SDL3pp_rect.h:286
constexpr Point & operator-=(const Point &other)
Memberwise subtract another point.
Definition SDL3pp_rect.h:240
constexpr int GetY() const noexcept
Get y coordinate.
Definition SDL3pp_rect.h:173
constexpr Point & operator/=(const Point &other)
Memberwise divide by another point.
Definition SDL3pp_rect.h:255
constexpr int GetX() const noexcept
Get x coordinate.
Definition SDL3pp_rect.h:154
constexpr Point GetWrapped(const Rect &rect) const
Get a point wrapped within a specified rect.
Definition SDL3pp_rect.h:2524
constexpr Point & Wrap(const Rect &rect)
Wrap point coordinates within a specified rect.
Definition SDL3pp_rect.h:2531
constexpr Point & operator+=(const Point &other)
Memberwise add another point.
Definition SDL3pp_rect.h:225
constexpr Point operator-() const
Get point's memberwise negation.
Definition SDL3pp_rect.h:215
constexpr Point(const FPointRaw &p)
Wraps Point.
Definition SDL3pp_rect.h:134
A rectangle, with the origin at the upper left (using integers).
Definition SDL3pp_rect.h:706
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:873
bool Contains(const RectRaw &other) const
Check whether the rect contains given point.
Definition SDL3pp_rect.h:1163
constexpr Rect & operator-=(const Point &offset)
Move by an opposite of the given offset.
Definition SDL3pp_rect.h:1321
bool GetLineIntersection(PointRaw *p1, PointRaw *p2) const
Calculate the intersection of a rectangle and line segment.
Definition SDL3pp_rect.h:1062
constexpr Rect & SetPosition(const Point &position)
Set the Position object.
Definition SDL3pp_rect.h:1010
constexpr Point GetPosition() const
Get the Position of the rect, which is the same as its top left corner.
Definition SDL3pp_rect.h:1001
constexpr Rect GetExtension(unsigned int hAmount, unsigned int vAmount) const
Get a rect extended by specified amount of pixels.
Definition SDL3pp_rect.h:1235
constexpr Point GetTopLeft() const
Get top left corner of the rect.
Definition SDL3pp_rect.h:970
constexpr Rect & Extend(unsigned int hAmount, unsigned int vAmount)
Extend a rect by specified amount of pixels.
Definition SDL3pp_rect.h:1263
constexpr int GetY() const noexcept
Get top y coordinate.
Definition SDL3pp_rect.h:790
constexpr int GetH() const noexcept
Get height of the rect.
Definition SDL3pp_rect.h:828
constexpr Rect operator+(const Point &offset) const
Get rectangle moved by a given offset.
Definition SDL3pp_rect.h:1280
constexpr Rect & operator+=(const Point &offset)
Move by then given offset.
Definition SDL3pp_rect.h:1306
Point & size()
Definition SDL3pp_rect.h:764
constexpr Rect(const RectRaw &r={}) noexcept
Wraps Rect.
Definition SDL3pp_rect.h:712
constexpr Rect GetExtension(unsigned int amount) const
Get a rect extended by specified amount of pixels.
Definition SDL3pp_rect.h:1217
constexpr Rect & SetY(int newY) noexcept
Set the top y coordinate.
Definition SDL3pp_rect.h:798
constexpr Rect(const FRectRaw &r)
Wraps FRect.
Definition SDL3pp_rect.h:735
constexpr Rect & SetW(int newW) noexcept
Set the width of the rect.
Definition SDL3pp_rect.h:817
constexpr Rect & Extend(unsigned int amount)
Extend a rect by specified amount of pixels.
Definition SDL3pp_rect.h:1250
constexpr Point GetCentroid() const
Get centroid of the rect.
Definition SDL3pp_rect.h:1044
constexpr Point GetBottomLeft() const
Get bottom left corner of the rect.
Definition SDL3pp_rect.h:986
constexpr Rect & SetX2(int x2)
Set X coordinate of the rect second corner.
Definition SDL3pp_rect.h:934
const Point & position() const
Definition SDL3pp_rect.h:755
static constexpr Rect FromCorners(Point p1, Point p2)
Construct the rect from given centers coordinates.
Definition SDL3pp_rect.h:911
bool Contains(const PointRaw &p) const
Check whether the rect contains given point.
Definition SDL3pp_rect.h:1153
constexpr Rect & SetSize(const Point &size)
Set the size of the rect.
Definition SDL3pp_rect.h:1031
static constexpr Rect FromCorners(int x1, int y1, int x2, int y2)
Construct the rect from given corners coordinates.
Definition SDL3pp_rect.h:899
constexpr Rect(int x, int y, int w, int h) noexcept
Constructs from its fields.
Definition SDL3pp_rect.h:725
constexpr Point GetSize() const
Get size of the rect.
Definition SDL3pp_rect.h:1023
constexpr Rect operator-(const Point &offset) const
Get rectangle moved by an opposite of given offset.
Definition SDL3pp_rect.h:1293
constexpr Point GetBottomRight() const
Get bottom right corner of the rect.
Definition SDL3pp_rect.h:994
constexpr int GetY2() const
Get Y coordinate of the rect second corner.
Definition SDL3pp_rect.h:946
static constexpr Rect FromCenter(Point center, Point size)
Construct the rect from given center coordinates and size.
Definition SDL3pp_rect.h:885
constexpr Rect & SetH(int newH) noexcept
Set the height of the rect.
Definition SDL3pp_rect.h:836
Point & position()
Definition SDL3pp_rect.h:758
constexpr int GetW() const noexcept
Get width of the rect.
Definition SDL3pp_rect.h:809
constexpr Rect & SetX(int newX) noexcept
Set the left x coordinate.
Definition SDL3pp_rect.h:779
constexpr Rect(const Point &corner, const Point &size)
Construct from offset and size.
Definition SDL3pp_rect.h:746
constexpr Rect & SetY2(int y2)
Set Y coordinate of the rect second corner.
Definition SDL3pp_rect.h:958
constexpr int GetX() const noexcept
Get left x coordinate.
Definition SDL3pp_rect.h:771
const Point & size() const
Definition SDL3pp_rect.h:761
constexpr Point GetTopRight() const
Get top right corner of the rect.
Definition SDL3pp_rect.h:978
constexpr int GetX2() const
Get X coordinate of the rect second corner.
Definition SDL3pp_rect.h:922