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
58constexpr bool operator==(const RectRaw& lhs, const RectRaw& rhs) noexcept
59{
60 return SDL_RectsEqual(&lhs, &rhs);
61}
62
64constexpr 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 constexpr 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 constexpr 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 constexpr bool operator==(const RectRaw& other) const { return Equal(other); }
882
884 constexpr bool operator==(const Rect& other) const
885 {
886 return *this == (const RectRaw&)(other);
887 }
888
890 constexpr 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
986 OptionalRef<const RectRaw> clip = std::nullopt);
987
997 static constexpr Rect FromCenter(int cx, int cy, int w, int h)
998 {
999 return Rect(cx - w / 2, cy - h / 2, w, h);
1000 }
1001
1009 static constexpr Rect FromCenter(Point center, Point size)
1010 {
1011 return Rect(center - size / 2, size);
1012 }
1013
1023 static constexpr Rect FromCorners(int x1, int y1, int x2, int y2)
1024 {
1025 return Rect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
1026 }
1027
1035 static constexpr Rect FromCorners(Point p1, Point p2)
1036 {
1037 return Rect(p1, p2 - p1 + Point(1, 1));
1038 }
1039
1046 constexpr int GetX2() const { return x + w - 1; }
1047
1058 constexpr Rect& SetX2(int x2)
1059 {
1060 w = x2 - x + 1;
1061 return *this;
1062 }
1063
1070 constexpr int GetY2() const { return y + h - 1; }
1071
1082 constexpr Rect& SetY2(int y2)
1083 {
1084 h = y2 - y + 1;
1085 return *this;
1086 }
1087
1094 constexpr Point GetTopLeft() const { return Point(x, y); }
1095
1102 constexpr Point GetTopRight() const { return Point(GetX2(), y); }
1103
1110 constexpr Point GetBottomLeft() const { return Point(x, GetY2()); }
1111
1118 constexpr Point GetBottomRight() const { return Point(GetX2(), GetY2()); }
1119
1126 constexpr Point GetSize() const { return Point(w, h); }
1127
1134 constexpr Point GetCentroid() const { return Point(x + w / 2, y + h / 2); }
1135
1153 {
1154 return GetLineIntersection(p1 ? &p1->x : nullptr,
1155 p1 ? &p1->y : nullptr,
1156 p2 ? &p2->x : nullptr,
1157 p2 ? &p2->y : nullptr);
1158 }
1159
1177 bool GetLineIntersection(int* X1, int* Y1, int* X2, int* Y2) const;
1178
1189 constexpr operator SDL_FRect() const;
1190
1192 constexpr operator FRect() const;
1193
1211 constexpr bool Empty() const;
1212
1231 constexpr bool Equal(const RectRaw& other) const;
1232
1241 constexpr bool Contains(const PointRaw& p) const
1242 {
1243 return SDL_PointInRect(&p, this);
1244 }
1245
1254 constexpr bool Contains(const RectRaw& other) const
1255 {
1256 return GetUnion(other) == *this;
1257 }
1258
1271 constexpr bool HasIntersection(const RectRaw& other) const;
1272
1286 constexpr Rect GetIntersection(const RectRaw& other) const;
1287
1297 constexpr Rect GetUnion(const RectRaw& other) const;
1298
1307 constexpr Rect GetExtension(unsigned int amount) const
1308 {
1309 Rect r = *this;
1310 r.Extend(amount);
1311 return r;
1312 }
1313
1325 constexpr Rect GetExtension(unsigned int hAmount, unsigned int vAmount) const
1326 {
1327 Rect r = *this;
1328 r.Extend(hAmount, vAmount);
1329 return r;
1330 }
1331
1340 constexpr Rect& Extend(unsigned int amount) { return Extend(amount, amount); }
1341
1353 constexpr Rect& Extend(unsigned int hAmount, unsigned int vAmount)
1354 {
1355 x -= hAmount;
1356 y -= vAmount;
1357 w += hAmount * 2;
1358 h += vAmount * 2;
1359 return *this;
1360 }
1361
1370 constexpr Rect operator+(const Point& offset) const
1371 {
1372 return Rect(x + offset.x, y + offset.y, w, h);
1373 }
1374
1383 constexpr Rect operator-(const Point& offset) const
1384 {
1385 return Rect(x - offset.x, y - offset.y, w, h);
1386 }
1387
1396 constexpr Rect& operator+=(const Point& offset)
1397 {
1398 x += offset.x;
1399 y += offset.y;
1400 return *this;
1401 }
1402
1411 constexpr Rect& operator-=(const Point& offset)
1412 {
1413 x -= offset.x;
1414 y -= offset.y;
1415 return *this;
1416 }
1417};
1418
1441{
1447 constexpr FRect(const FRectRaw& r = {}) noexcept
1448 : FRectRaw(r)
1449 {
1450 }
1451
1460 constexpr FRect(float x, float y, float w, float h) noexcept
1461 : FRectRaw{x, y, w, h}
1462 {
1463 }
1464
1468 constexpr FRect(const FPointRaw& corner, const FPointRaw& size)
1469 : FRect{corner.x, corner.y, size.x, size.y}
1470 {
1471 }
1472
1474 constexpr operator bool() const { return !Empty(); }
1475
1481 constexpr float GetX() const noexcept { return x; }
1482
1489 constexpr FRect& SetX(float newX) noexcept
1490 {
1491 x = newX;
1492 return *this;
1493 }
1494
1500 constexpr float GetY() const noexcept { return y; }
1501
1508 constexpr FRect& SetY(float newY) noexcept
1509 {
1510 y = newY;
1511 return *this;
1512 }
1513
1519 constexpr float GetW() const noexcept { return w; }
1520
1527 constexpr FRect& SetW(float newW) noexcept
1528 {
1529 w = newW;
1530 return *this;
1531 }
1532
1538 constexpr float GetH() const noexcept { return h; }
1539
1546 constexpr FRect& SetH(float newH) noexcept
1547 {
1548 h = newH;
1549 return *this;
1550 }
1551
1569 static constexpr FRect GetEnclosingPoints(
1571 OptionalRef<const FRectRaw> clip = std::nullopt);
1572
1582 static constexpr FRect FromCenter(float cx, float cy, float w, float h)
1583 {
1584 return FRect(cx - w / 2, cy - h / 2, w, h);
1585 }
1586
1594 static constexpr FRect FromCenter(FPoint center, FPoint size)
1595 {
1596 return FRect(center - size / 2, size);
1597 }
1598
1608 static constexpr FRect FromCorners(float x1, float y1, float x2, float y2)
1609 {
1610 return FRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
1611 }
1612
1620 static constexpr FRect FromCorners(FPoint p1, FPoint p2)
1621 {
1622 return FRect(p1, p2 - p1 + FPoint(1, 1));
1623 }
1624
1631 constexpr float GetX2() const { return x + w - 1; }
1632
1643 constexpr FRect& SetX2(float x2)
1644 {
1645 w = x2 - x + 1;
1646 return *this;
1647 }
1648
1655 constexpr float GetY2() const { return y + h - 1; }
1656
1667 constexpr FRect& SetY2(float y2)
1668 {
1669 h = y2 - y + 1;
1670 return *this;
1671 }
1672
1679 constexpr FPoint GetTopLeft() const { return FPoint(x, y); }
1680
1687 constexpr FPoint GetTopRight() const { return FPoint(GetX2(), y); }
1688
1695 constexpr FPoint GetBottomLeft() const { return FPoint(x, GetY2()); }
1696
1703 constexpr FPoint GetBottomRight() const { return FPoint(GetX2(), GetY2()); }
1704
1711 constexpr FPoint GetSize() const { return FPoint(w, h); }
1712
1719 constexpr FPoint GetCentroid() const { return FPoint(x + w / 2, y + h / 2); }
1720
1739 bool GetLineIntersection(float* X1, float* Y1, float* X2, float* Y2) const;
1740
1757 bool GetLineIntersection(FPoint* p1, FPoint* p2) const
1758 {
1759 return GetLineIntersection(p1 ? &p1->x : nullptr,
1760 p1 ? &p1->y : nullptr,
1761 p2 ? &p2->x : nullptr,
1762 p2 ? &p2->y : nullptr);
1763 }
1764
1782 constexpr bool Empty() const;
1783
1808 constexpr bool EqualEpsilon(const FRectRaw& other, const float epsilon) const;
1809
1834 constexpr bool Equal(const FRectRaw& other) const;
1835
1844 constexpr bool Contains(const FPointRaw& p) const
1845 {
1846 return SDL_PointInRectFloat(&p, this);
1847 }
1848
1857 constexpr bool Contains(const FRectRaw& other) const
1858 {
1859 return GetUnion(other) == *this;
1860 }
1861
1874 constexpr bool HasIntersection(const FRectRaw& other) const;
1875
1889 constexpr FRect GetIntersection(const FRectRaw& other) const;
1890
1900 constexpr FRect GetUnion(const FRectRaw& other) const;
1901
1910 constexpr FRect GetExtension(unsigned int amount) const
1911 {
1912 FRect r = *this;
1913 r.Extend(amount);
1914 return r;
1915 }
1916
1928 constexpr FRect GetExtension(float hAmount, float vAmount) const
1929 {
1930 FRect r = *this;
1931 r.Extend(hAmount, vAmount);
1932 return r;
1933 }
1934
1943 constexpr FRect& Extend(float amount) { return Extend(amount, amount); }
1944
1956 constexpr FRect& Extend(float hAmount, float vAmount)
1957 {
1958 x -= hAmount;
1959 y -= vAmount;
1960 w += hAmount * 2;
1961 h += vAmount * 2;
1962 return *this;
1963 }
1964
1973 constexpr FRect operator+(const FPoint& offset) const
1974 {
1975 return FRect(x + offset.x, y + offset.y, w, h);
1976 }
1977
1986 constexpr FRect operator-(const FPoint& offset) const
1987 {
1988 return FRect(x - offset.x, y - offset.y, w, h);
1989 }
1990
1999 constexpr FRect& operator+=(const FPoint& offset)
2000 {
2001 x += offset.x;
2002 y += offset.y;
2003 return *this;
2004 }
2005
2014 constexpr FRect& operator-=(const FPoint& offset)
2015 {
2016 x -= offset.x;
2017 y -= offset.y;
2018 return *this;
2019 }
2020};
2021
2032constexpr FRect RectToFRect(const RectRaw& rect)
2033{
2034 FRect frect;
2035 SDL_RectToFRect(&rect, &frect);
2036 return frect;
2037}
2038
2039constexpr Rect::operator SDL_FRect() const { return SDL::RectToFRect(*this); }
2040
2062constexpr bool PointInRect(const PointRaw& p, const RectRaw& r)
2063{
2064 return SDL_PointInRect(&p, &r);
2065}
2066
2067constexpr bool Point::InRect(const RectRaw& r) const
2068{
2069 return SDL::PointInRect(*this, r);
2070}
2071
2090constexpr bool RectEmpty(const RectRaw& r) { return SDL_RectEmpty(&r); }
2091
2092constexpr bool Rect::Empty() const { return SDL::RectEmpty(*this); }
2093
2113constexpr bool RectsEqual(const RectRaw& a, const RectRaw& b)
2114{
2115 return SDL_RectsEqual(&a, &b);
2116}
2117
2118constexpr bool Rect::Equal(const RectRaw& other) const
2119{
2120 return SDL::RectsEqual(*this, other);
2121}
2122
2138constexpr bool HasRectIntersection(const RectRaw& A, const RectRaw& B)
2139{
2140 return SDL_HasRectIntersection(&A, &B);
2141}
2142
2143constexpr bool Rect::HasIntersection(const RectRaw& other) const
2144{
2145 return SDL::HasRectIntersection(*this, other);
2146}
2147
2162constexpr Rect GetRectIntersection(const RectRaw& A, const RectRaw& B)
2163{
2164 if (Rect result; SDL_GetRectIntersection(&A, &B, &result)) return result;
2165 return {};
2166}
2167
2168constexpr Rect Rect::GetIntersection(const RectRaw& other) const
2169{
2170 return SDL::GetRectIntersection(*this, other);
2171}
2172
2183constexpr Rect GetRectUnion(const RectRaw& A, const RectRaw& B)
2184{
2185 Rect r;
2186 CheckError(SDL_GetRectUnion(&A, &B, &r));
2187 return r;
2188}
2189
2190constexpr Rect Rect::GetUnion(const RectRaw& other) const
2191{
2192 return SDL::GetRectUnion(*this, other);
2193}
2194
2211 OptionalRef<const RectRaw> clip = std::nullopt)
2212{
2213 if (Rect result;
2214 SDL_GetRectEnclosingPoints(points.data(), points.size(), clip, &result)) {
2215 return result;
2216 }
2217 return {};
2218}
2219
2222{
2223 return SDL::GetRectEnclosingPoints(points, clip);
2224}
2225
2244inline bool GetRectAndLineIntersection(const RectRaw& rect,
2245 int* X1,
2246 int* Y1,
2247 int* X2,
2248 int* Y2)
2249{
2250 return SDL_GetRectAndLineIntersection(&rect, X1, Y1, X2, Y2);
2251}
2252
2253inline bool Rect::GetLineIntersection(int* X1, int* Y1, int* X2, int* Y2) const
2254{
2255 return SDL::GetRectAndLineIntersection(*this, X1, Y1, X2, Y2);
2256}
2257
2279constexpr bool PointInRectFloat(const FPointRaw& p, const FRectRaw& r)
2280{
2281 return SDL_PointInRectFloat(&p, &r);
2282}
2283
2284constexpr bool FPoint::InRect(const FRectRaw& r) const
2285{
2286 return SDL::PointInRectFloat(*this, r);
2287}
2288
2307constexpr bool RectEmptyFloat(const FRectRaw& r)
2308{
2309 return SDL_RectEmptyFloat(&r);
2310}
2311
2312constexpr bool FRect::Empty() const { return SDL::RectEmptyFloat(*this); }
2313
2339constexpr bool RectsEqualEpsilon(const FRectRaw& a,
2340 const FRectRaw& b,
2341 const float epsilon)
2342{
2343 return SDL_RectsEqualEpsilon(&a, &b, epsilon);
2344}
2345
2346constexpr bool FRect::EqualEpsilon(const FRectRaw& other,
2347 const float epsilon) const
2348{
2349 return SDL::RectsEqualEpsilon(*this, other, epsilon);
2350}
2351
2377constexpr bool RectsEqualFloat(const FRectRaw& a, const FRectRaw& b)
2378{
2379 return SDL_RectsEqualFloat(&a, &b);
2380}
2381
2382constexpr bool FRect::Equal(const FRectRaw& other) const
2383{
2384 return SDL::RectsEqualFloat(*this, other);
2385}
2386
2400constexpr bool HasRectIntersectionFloat(const FRectRaw& A, const FRectRaw& B)
2401{
2402 return SDL_HasRectIntersectionFloat(&A, &B);
2403}
2404
2405constexpr bool FRect::HasIntersection(const FRectRaw& other) const
2406{
2407 return SDL::HasRectIntersectionFloat(*this, other);
2408}
2409
2425{
2426 if (FRect r; SDL_GetRectIntersectionFloat(&A, &B, &r)) return r;
2427 return {};
2428}
2429
2430constexpr FRect FRect::GetIntersection(const FRectRaw& other) const
2431{
2432 return SDL::GetRectIntersectionFloat(*this, other);
2433}
2434
2446constexpr FRect GetRectUnionFloat(const FRectRaw& A, const FRectRaw& B)
2447{
2448 FRect r;
2449 CheckError(SDL_GetRectUnionFloat(&A, &B, &r));
2450 return r;
2451}
2452
2453constexpr FRect FRect::GetUnion(const FRectRaw& other) const
2454{
2455 return SDL::GetRectUnionFloat(*this, other);
2456}
2457
2474 OptionalRef<const FRectRaw> clip = std::nullopt)
2475{
2476 if (FRect result; SDL_GetRectEnclosingPointsFloat(
2477 points.data(), points.size(), clip, &result)) {
2478 return result;
2479 }
2480 return {};
2481}
2482
2485{
2486 return SDL::GetRectEnclosingPointsFloat(points, clip);
2487}
2488
2509 float* X1,
2510 float* Y1,
2511 float* X2,
2512 float* Y2)
2513{
2514 return SDL_GetRectAndLineIntersectionFloat(&rect, X1, Y1, X2, Y2);
2515}
2516
2517inline bool FRect::GetLineIntersection(float* X1,
2518 float* Y1,
2519 float* X2,
2520 float* Y2) const
2521{
2522 return SDL::GetRectAndLineIntersectionFloat(*this, X1, Y1, X2, Y2);
2523}
2524
2526
2527constexpr Point::operator FPoint() const { return {float(x), float(y)}; }
2528
2529constexpr FPoint Point::operator/(float value) const
2530{
2531 return FPoint(*this) / value;
2532}
2533constexpr FPoint Point::operator*(float value) const
2534{
2535 return FPoint(*this) * value;
2536}
2537
2538constexpr Point Point::GetClamped(const Rect& rect) const
2539{
2540 Point p = *this;
2541 p.Clamp(rect);
2542 return p;
2543}
2544
2545constexpr Point& Point::Clamp(const Rect& rect)
2546{
2547 if (x < rect.x) x = rect.x;
2548 if (x > rect.GetX2()) x = rect.GetX2();
2549 if (y < rect.y) y = rect.y;
2550 if (y > rect.GetY2()) y = rect.GetY2();
2551 return *this;
2552}
2553
2554constexpr Point Point::GetWrapped(const Rect& rect) const
2555{
2556 Point p = *this;
2557 p.Wrap(rect);
2558 return p;
2559}
2560
2561constexpr Point& Point::Wrap(const Rect& rect)
2562{
2563 if (x < rect.x)
2564 x = rect.x + rect.w - 1 - (rect.x - x + rect.w - 1) % rect.w;
2565 else if (x >= rect.x + rect.w)
2566 x = rect.x + (x - rect.x - rect.w) % rect.w;
2567
2568 if (y < rect.y)
2569 y = rect.y + rect.h - 1 - (rect.y - y + rect.h - 1) % rect.h;
2570 else if (y >= rect.y + rect.h)
2571 y = rect.y + (y - rect.y - rect.h) % rect.h;
2572
2573 return *this;
2574}
2575
2576constexpr FPoint FPoint::GetClamped(const FRect& rect) const
2577{
2578 FPoint p = *this;
2579 p.Clamp(rect);
2580 return p;
2581}
2582
2583constexpr FPoint& FPoint::Clamp(const FRect& rect)
2584{
2585 if (x < rect.x) x = rect.x;
2586 if (x > rect.GetX2()) x = rect.GetX2();
2587 if (y < rect.y) y = rect.y;
2588 if (y > rect.GetY2()) y = rect.GetY2();
2589 return *this;
2590}
2591
2592constexpr FPoint FPoint::GetWrapped(const FRect& rect) const
2593{
2594 FPoint p = *this;
2595 p.Wrap(rect);
2596 return p;
2597}
2598
2599constexpr FPoint& FPoint::Wrap(const FRect& rect)
2600{
2601 if (x < rect.x)
2602 x = rect.x + rect.w - 1 - SDL_fmod(rect.x - x + rect.w - 1, rect.w);
2603 else if (x >= rect.x + rect.w)
2604 x = rect.x + SDL_fmod(x - rect.x - rect.w, rect.w);
2605
2606 if (y < rect.y)
2607 y = rect.y + rect.h - 1 - SDL_fmod(rect.y - y + rect.h - 1, rect.h);
2608 else if (y >= rect.y + rect.h)
2609 y = rect.y + SDL_fmod(y - rect.y - rect.h, rect.h);
2610
2611 return *this;
2612}
2613
2614constexpr Rect::operator FRect() const
2615{
2616 return {float(x), float(y), float(w), float(h)};
2617}
2618
2619} // namespace SDL
2620
2621#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:197
constexpr bool operator==(ColorRaw lhs, ColorRaw rhs) noexcept
Comparison operator for Color.
Definition: SDL3pp_pixels.h:2150
constexpr bool RectEmptyFloat(const FRectRaw &r)
Determine whether a floating point rectangle takes no space.
Definition: SDL3pp_rect.h:2307
constexpr FRect GetRectUnionFloat(const FRectRaw &A, const FRectRaw &B)
Calculate the union of two rectangles with float precision.
Definition: SDL3pp_rect.h:2446
constexpr bool InRect(const RectRaw &r) const
Determine whether a point resides inside a rectangle.
Definition: SDL3pp_rect.h:2067
constexpr bool HasRectIntersectionFloat(const FRectRaw &A, const FRectRaw &B)
Determine whether two rectangles intersect with float precision.
Definition: SDL3pp_rect.h:2400
constexpr FRect GetRectIntersectionFloat(const FRectRaw &A, const FRectRaw &B)
Calculate the intersection of two rectangles with float precision.
Definition: SDL3pp_rect.h:2424
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:2517
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:2209
constexpr FRect GetIntersection(const FRectRaw &other) const
Calculate the intersection of two rectangles with float precision.
Definition: SDL3pp_rect.h:2430
constexpr 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:2346
constexpr bool InRect(const FRectRaw &r) const
Determine whether a point resides inside a floating point rectangle.
Definition: SDL3pp_rect.h:2284
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:2508
constexpr bool PointInRectFloat(const FPointRaw &p, const FRectRaw &r)
Determine whether a point resides inside a floating point rectangle.
Definition: SDL3pp_rect.h:2279
constexpr bool Equal(const FRectRaw &other) const
Determine whether two floating point rectangles are equal, within a default epsilon.
Definition: SDL3pp_rect.h:2382
SDL_FPoint FPointRaw
Alias to raw representation for FPoint.
Definition: SDL3pp_rect.h:28
constexpr bool Empty() const
Determine whether a rectangle has no area.
Definition: SDL3pp_rect.h:2092
constexpr bool Equal(const RectRaw &other) const
Determine whether two rectangles are equal.
Definition: SDL3pp_rect.h:2118
constexpr bool RectsEqual(const RectRaw &a, const RectRaw &b)
Determine whether two rectangles are equal.
Definition: SDL3pp_rect.h:2113
constexpr bool Empty() const
Determine whether a rectangle has no area.
Definition: SDL3pp_rect.h:2312
constexpr bool RectEmpty(const RectRaw &r)
Determine whether a rectangle has no area.
Definition: SDL3pp_rect.h:2090
constexpr Rect GetUnion(const RectRaw &other) const
Calculate the union of two rectangles.
Definition: SDL3pp_rect.h:2190
constexpr bool PointInRect(const PointRaw &p, const RectRaw &r)
Determine whether a point resides inside a rectangle.
Definition: SDL3pp_rect.h:2062
static constexpr 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:2483
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:2220
constexpr Rect GetRectUnion(const RectRaw &A, const RectRaw &B)
Calculate the union of two rectangles.
Definition: SDL3pp_rect.h:2183
constexpr FRect RectToFRect(const RectRaw &rect)
Convert an Rect to FRect.
Definition: SDL3pp_rect.h:2032
constexpr Rect GetRectIntersection(const RectRaw &A, const RectRaw &B)
Calculate the intersection of two rectangles.
Definition: SDL3pp_rect.h:2162
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:2244
constexpr FRect GetUnion(const FRectRaw &other) const
Calculate the union of two rectangles with float precision.
Definition: SDL3pp_rect.h:2453
constexpr bool RectsEqualFloat(const FRectRaw &a, const FRectRaw &b)
Determine whether two floating point rectangles are equal, within a default epsilon.
Definition: SDL3pp_rect.h:2377
constexpr 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:2339
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
constexpr bool HasIntersection(const RectRaw &other) const
Determine whether two rectangles intersect.
Definition: SDL3pp_rect.h:2143
constexpr bool HasIntersection(const FRectRaw &other) const
Determine whether two rectangles intersect with float precision.
Definition: SDL3pp_rect.h:2405
constexpr Rect GetIntersection(const RectRaw &other) const
Calculate the intersection of two rectangles.
Definition: SDL3pp_rect.h:2168
constexpr 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:2472
SDL_Point PointRaw
Alias to raw representation for Point.
Definition: SDL3pp_rect.h:22
constexpr bool HasRectIntersection(const RectRaw &A, const RectRaw &B)
Determine whether two rectangles intersect.
Definition: SDL3pp_rect.h:2138
Main include header for the SDL3pp library.
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:2599
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:2576
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:2592
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:2583
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:1441
constexpr FRect & Extend(float hAmount, float vAmount)
Extend a rect by specified amount of pixels.
Definition: SDL3pp_rect.h:1956
constexpr FRect operator+(const FPoint &offset) const
Get rectangle moved by a given offset.
Definition: SDL3pp_rect.h:1973
constexpr FRect & SetX(float newX) noexcept
Set the left x coordinate.
Definition: SDL3pp_rect.h:1489
static constexpr FRect FromCorners(FPoint p1, FPoint p2)
Construct the rect from given centers coordinates.
Definition: SDL3pp_rect.h:1620
constexpr FRect(float x, float y, float w, float h) noexcept
Constructs from its fields.
Definition: SDL3pp_rect.h:1460
constexpr float GetH() const noexcept
Get height of the rect.
Definition: SDL3pp_rect.h:1538
constexpr float GetY() const noexcept
Get top y coordinate.
Definition: SDL3pp_rect.h:1500
constexpr FPoint GetTopRight() const
Get top right corner of the rect.
Definition: SDL3pp_rect.h:1687
constexpr FRect operator-(const FPoint &offset) const
Get rectangle moved by an opposite of given offset.
Definition: SDL3pp_rect.h:1986
constexpr bool Contains(const FRectRaw &other) const
Check whether the rect contains given point.
Definition: SDL3pp_rect.h:1857
constexpr FRect & operator+=(const FPoint &offset)
Move by then given offset.
Definition: SDL3pp_rect.h:1999
constexpr float GetX() const noexcept
Get left x coordinate.
Definition: SDL3pp_rect.h:1481
static constexpr FRect FromCenter(FPoint center, FPoint size)
Construct the rect from given center coordinates and size.
Definition: SDL3pp_rect.h:1594
constexpr FRect & operator-=(const FPoint &offset)
Move by an opposite of the given offset.
Definition: SDL3pp_rect.h:2014
constexpr FPoint GetBottomRight() const
Get bottom right corner of the rect.
Definition: SDL3pp_rect.h:1703
constexpr FPoint GetBottomLeft() const
Get bottom left corner of the rect.
Definition: SDL3pp_rect.h:1695
constexpr FRect(const FPointRaw &corner, const FPointRaw &size)
Constructs from top-left corner plus size.
Definition: SDL3pp_rect.h:1468
constexpr float GetX2() const
Get X coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1631
constexpr FRect GetExtension(unsigned int amount) const
Get a rect extended by specified amount of pixels.
Definition: SDL3pp_rect.h:1910
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:1582
constexpr float GetY2() const
Get Y coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1655
constexpr FRect & SetH(float newH) noexcept
Set the height of the rect.
Definition: SDL3pp_rect.h:1546
constexpr FRect & SetY2(float y2)
Set Y coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1667
constexpr float GetW() const noexcept
Get width of the rect.
Definition: SDL3pp_rect.h:1519
constexpr FRect & SetX2(float x2)
Set X coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1643
static constexpr FRect FromCorners(float x1, float y1, float x2, float y2)
Construct the rect from given corners coordinates.
Definition: SDL3pp_rect.h:1608
constexpr bool Contains(const FPointRaw &p) const
Check whether the rect contains given point.
Definition: SDL3pp_rect.h:1844
constexpr FRect & Extend(float amount)
Extend a rect by specified amount of pixels.
Definition: SDL3pp_rect.h:1943
constexpr FRect & SetY(float newY) noexcept
Set the top y coordinate.
Definition: SDL3pp_rect.h:1508
constexpr FRect & SetW(float newW) noexcept
Set the width of the rect.
Definition: SDL3pp_rect.h:1527
constexpr FRect GetExtension(float hAmount, float vAmount) const
Get a rect extended by specified amount of pixels.
Definition: SDL3pp_rect.h:1928
constexpr FPoint GetCentroid() const
Get centroid of the rect.
Definition: SDL3pp_rect.h:1719
bool GetLineIntersection(FPoint *p1, FPoint *p2) const
Determine whether a floating point rectangle takes no space.
Definition: SDL3pp_rect.h:1757
constexpr FPoint GetTopLeft() const
Get top left corner of the rect.
Definition: SDL3pp_rect.h:1679
constexpr FRect(const FRectRaw &r={}) noexcept
Wraps FRect.
Definition: SDL3pp_rect.h:1447
constexpr FPoint GetSize() const
Get size of the rect.
Definition: SDL3pp_rect.h:1711
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:2538
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:2545
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:2554
constexpr Point & Wrap(const Rect &rect)
Wrap point coordinates within a specified rect.
Definition: SDL3pp_rect.h:2561
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:997
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:1411
constexpr bool Contains(const PointRaw &p) const
Check whether the rect contains given point.
Definition: SDL3pp_rect.h:1241
bool GetLineIntersection(PointRaw *p1, PointRaw *p2) const
Calculate the intersection of a rectangle and line segment.
Definition: SDL3pp_rect.h:1152
constexpr Rect GetExtension(unsigned int hAmount, unsigned int vAmount) const
Get a rect extended by specified amount of pixels.
Definition: SDL3pp_rect.h:1325
constexpr Point GetTopLeft() const
Get top left corner of the rect.
Definition: SDL3pp_rect.h:1094
constexpr Rect & Extend(unsigned int hAmount, unsigned int vAmount)
Extend a rect by specified amount of pixels.
Definition: SDL3pp_rect.h:1353
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:1370
constexpr Rect & operator+=(const Point &offset)
Move by then given offset.
Definition: SDL3pp_rect.h:1396
constexpr bool operator==(const Rect &other) const
Compares with the underlying type.
Definition: SDL3pp_rect.h:884
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:1307
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:1340
constexpr Point GetCentroid() const
Get centroid of the rect.
Definition: SDL3pp_rect.h:1134
constexpr Point GetBottomLeft() const
Get bottom left corner of the rect.
Definition: SDL3pp_rect.h:1110
constexpr Rect & SetX2(int x2)
Set X coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1058
static constexpr Rect FromCorners(Point p1, Point p2)
Construct the rect from given centers coordinates.
Definition: SDL3pp_rect.h:1035
static constexpr Rect FromCorners(int x1, int y1, int x2, int y2)
Construct the rect from given corners coordinates.
Definition: SDL3pp_rect.h:1023
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:1126
constexpr Rect operator-(const Point &offset) const
Get rectangle moved by an opposite of given offset.
Definition: SDL3pp_rect.h:1383
constexpr Point GetBottomRight() const
Get bottom right corner of the rect.
Definition: SDL3pp_rect.h:1118
constexpr int GetY2() const
Get Y coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1070
static constexpr Rect FromCenter(Point center, Point size)
Construct the rect from given center coordinates and size.
Definition: SDL3pp_rect.h:1009
constexpr bool operator==(const RectRaw &other) const
Compares with the underlying type.
Definition: SDL3pp_rect.h:881
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:1082
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:1102
constexpr bool Contains(const RectRaw &other) const
Check whether the rect contains given point.
Definition: SDL3pp_rect.h:1254
constexpr int GetX2() const
Get X coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1046