SDL3pp
A slim C++ wrapper for SDL3
Loading...
Searching...
No Matches
SDL3pp_rect.h
1#ifndef SDL3PP_RECT_H_
2#define SDL3PP_RECT_H_
3
4#include <optional>
5#include <span>
6#include <SDL3/SDL_rect.h>
7#include "SDL3pp_error.h"
8#include "SDL3pp_optionalRef.h"
9#include "SDL3pp_spanRef.h"
10#include "SDL3pp_stdinc.h"
11
12namespace SDL {
13
22// Forward decl
23struct FPoint;
24
25// Forward decl
26struct Rect;
27
28// Forward decl
29struct FRect;
30
40struct Point : SDL_Point
41{
47 constexpr Point(const SDL_Point& p = {})
48 : SDL_Point(p)
49 {
50 }
51
58 constexpr Point(int x, int y)
59 : SDL_Point{x, y}
60 {
61 }
62
66 constexpr explicit Point(const SDL_FPoint& p)
67 : SDL_Point{int(p.x), int(p.y)}
68 {
69 }
70
74 constexpr bool operator==(const Point& other) const
75 {
76 return x == other.x && y == other.y;
77 }
78
82 constexpr bool operator==(const SDL_Point& p) const
83 {
84 return operator==(Point(p));
85 }
91 constexpr explicit operator bool() const { return x != 0 && y != 0; }
92
99 constexpr int GetX() const { return x; }
100
107 constexpr Point& SetX(int newX)
108 {
109 x = newX;
110 return *this;
111 }
112
119 constexpr int GetY() const { return y; }
120
127 constexpr Point& SetY(int newY)
128 {
129 y = newY;
130 return *this;
131 }
132
153 constexpr bool IsInRect(const Rect& r) const;
154
161 constexpr Point operator-() const { return Point(-x, -y); }
162
171 constexpr Point operator+(const Point& other) const
172 {
173 return Point(x + other.x, y + other.y);
174 }
175
184 constexpr Point operator-(const Point& other) const
185 {
186 return Point(x - other.x, y - other.y);
187 }
188
198 constexpr Point operator/(int value) const
199 {
200 return Point(x / value, y / value);
201 }
202
212 constexpr FPoint operator/(float value) const;
213
223 constexpr Point operator/(const Point& other) const
224 {
225 return Point(x / other.x, y / other.y);
226 }
227
238 constexpr Point operator%(int value) const
239 {
240 return Point(x % value, y % value);
241 }
242
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 FPoint operator*(float value) const;
284
295 constexpr Point operator*(const Point& other) const
296 {
297 return Point(x * other.x, y * other.y);
298 }
299
308 constexpr Point& operator+=(const Point& other)
309 {
310 x += other.x;
311 y += other.y;
312 return *this;
313 }
314
323 constexpr Point& operator-=(const Point& other)
324 {
325 x -= other.x;
326 y -= other.y;
327 return *this;
328 }
329
338 constexpr Point& operator/=(int value)
339 {
340 x /= value;
341 y /= value;
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
384 constexpr Point& operator%=(const Point& other)
385 {
386 x %= other.x;
387 y %= other.y;
388 return *this;
389 }
390
399 constexpr Point& operator*=(int value)
400 {
401 x *= value;
402 y *= value;
403 return *this;
404 }
405
414 constexpr Point& operator*=(const Point& other)
415 {
416 x *= other.x;
417 y *= other.y;
418 return *this;
419 }
420
430 constexpr Point GetClamped(const Rect& rect) const;
431
441 constexpr Point& Clamp(const Rect& rect);
442
451 constexpr Point GetWrapped(const Rect& rect) const;
452
461 constexpr Point& Wrap(const Rect& rect);
462
468 constexpr operator FPoint() const;
469};
470
478struct FPoint : SDL_FPoint
479{
485 constexpr FPoint(const SDL_FPoint& p = {})
486 : SDL_FPoint(p)
487 {
488 }
489
496 constexpr FPoint(float x, float y)
497 : SDL_FPoint{x, y}
498 {
499 }
500
504 constexpr bool operator==(const FPoint& other) const
505 {
506 return x == other.x && y == other.y;
507 }
508
512 constexpr bool operator==(const SDL_FPoint& p) const
513 {
514 return operator==(FPoint(p));
515 }
516
522 constexpr explicit operator bool() const { return x != 0 && y != 0; }
523
529 constexpr float GetX() const { return x; }
530
537 constexpr FPoint& SetX(float newX)
538 {
539 x = newX;
540 return *this;
541 }
542
548 constexpr float GetY() const { return y; }
549
556 constexpr FPoint& SetY(float newY)
557 {
558 y = newY;
559 return *this;
560 }
561
582 constexpr bool IsInRect(const FRect& r) const;
583
590 constexpr FPoint operator-() const { return FPoint(-x, -y); }
591
600 constexpr FPoint operator+(const FPoint& other) const
601 {
602 return FPoint(x + other.x, y + other.y);
603 }
604
613 constexpr FPoint operator-(const FPoint& other) const
614 {
615 return FPoint(x - other.x, y - other.y);
616 }
617
627 constexpr FPoint operator/(float value) const
628 {
629 return FPoint(x / value, y / value);
630 }
631
641 constexpr FPoint operator/(const FPoint& other) const
642 {
643 return FPoint(x / other.x, y / other.y);
644 }
645
656 constexpr FPoint operator*(float value) const
657 {
658 return FPoint(x * value, y * value);
659 }
660
671 constexpr FPoint operator*(const FPoint& other) const
672 {
673 return FPoint(x * other.x, y * other.y);
674 }
675
684 constexpr FPoint& operator+=(const FPoint& other)
685 {
686 x += other.x;
687 y += other.y;
688 return *this;
689 }
690
699 constexpr FPoint& operator-=(const FPoint& other)
700 {
701 x -= other.x;
702 y -= other.y;
703 return *this;
704 }
705
714 constexpr FPoint& operator/=(float value)
715 {
716 x /= value;
717 y /= value;
718 return *this;
719 }
720
729 constexpr FPoint& operator/=(const FPoint& other)
730 {
731 x /= other.x;
732 y /= other.y;
733 return *this;
734 }
735
744 constexpr FPoint& operator*=(float value)
745 {
746 x *= value;
747 y *= value;
748 return *this;
749 }
750
759 constexpr FPoint& operator*=(const FPoint& other)
760 {
761 x *= other.x;
762 y *= other.y;
763 return *this;
764 }
765
775 constexpr FPoint GetClamped(const FRect& rect) const;
776
786 constexpr FPoint& Clamp(const FRect& rect);
787
796 constexpr FPoint GetWrapped(const FRect& rect) const;
797
806 constexpr FPoint& Wrap(const FRect& rect);
807};
808
816struct Rect : SDL_Rect
817{
823 constexpr Rect(const SDL_Rect& r = {})
824 : SDL_Rect(r)
825 {
826 }
827
836 constexpr Rect(int x, int y, int w, int h)
837 : SDL_Rect({x, y, w, h})
838 {
839 }
840
847 constexpr Rect(const SDL_Point& corner, const SDL_Point& size)
848 : Rect{corner.x, corner.y, size.x, size.y}
849 {
850 }
851
855 constexpr bool operator==(const Rect& other) const { return Equal(other); }
856
860 constexpr bool operator==(const SDL_Rect& r) const
861 {
862 return operator==(Rect(r));
863 }
864
868 constexpr operator bool() const { return !Empty(); }
869
876 constexpr int GetX() const { return x; }
877
884 constexpr Rect& SetX(int newX)
885 {
886 x = newX;
887 return *this;
888 }
889
896 constexpr int GetY() const { return y; }
897
904 constexpr Rect& SetY(int newY)
905 {
906 y = newY;
907 return *this;
908 }
909
916 constexpr int GetW() const { return w; }
917
924 constexpr Rect& SetW(int newW)
925 {
926 w = newW;
927 return *this;
928 }
929
936 constexpr int GetH() const { return h; }
937
944 constexpr Rect& SetH(int newH)
945 {
946 h = newH;
947 return *this;
948 }
949
968 OptionalRef<const SDL_Rect> clip = std::nullopt)
969 {
970 Rect result;
971 if (SDL_GetRectEnclosingPoints(
972 points.data(), points.size(), clip, &result)) {
973 return result;
974 }
975 return {};
976 }
977
987 static constexpr Rect FromCenter(int cx, int cy, int w, int h)
988 {
989 return Rect(cx - w / 2, cy - h / 2, w, h);
990 }
991
999 static constexpr Rect FromCenter(const Point& center, const Point& size)
1000 {
1001 return Rect(center - size / 2, size);
1002 }
1003
1013 static constexpr Rect FromCorners(int x1, int y1, int x2, int y2)
1014 {
1015 return Rect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
1016 }
1017
1025 static constexpr Rect FromCorners(const Point& p1, const Point& p2)
1026 {
1027 return Rect(p1, p2 - p1 + Point(1, 1));
1028 }
1029
1036 constexpr int GetX2() const { return x + w - 1; }
1037
1048 constexpr Rect& SetX2(int x2)
1049 {
1050 w = x2 - x + 1;
1051 return *this;
1052 }
1053
1060 constexpr int GetY2() const { return y + h - 1; }
1061
1072 constexpr Rect& SetY2(int y2)
1073 {
1074 h = y2 - y + 1;
1075 return *this;
1076 }
1077
1084 constexpr Point GetTopLeft() const { return Point(x, y); }
1085
1092 constexpr Point GetTopRight() const { return Point(GetX2(), y); }
1093
1100 constexpr Point GetBottomLeft() const { return Point(x, GetY2()); }
1101
1108 constexpr Point GetBottomRight() const { return Point(GetX2(), GetY2()); }
1109
1116 constexpr Point GetSize() const { return Point(w, h); }
1117
1124 constexpr Point GetCentroid() const { return Point(x + w / 2, y + h / 2); }
1125
1143 bool IntersectLine(int* X1, int* Y1, int* X2, int* Y2) const
1144 {
1145 return SDL_GetRectAndLineIntersection(this, X1, Y1, X2, Y2);
1146 }
1147
1164 bool IntersectLine(Point* p1, Point* p2) const
1165 {
1166 return IntersectLine(p1 ? &p1->x : nullptr,
1167 p1 ? &p1->y : nullptr,
1168 p2 ? &p2->x : nullptr,
1169 p2 ? &p2->y : nullptr);
1170 }
1171
1182 constexpr operator FRect() const;
1183
1187 constexpr operator SDL_FRect() const { return operator SDL_FRect(); }
1188
1206 constexpr bool Empty() const { return SDL_RectEmpty(this); }
1207
1226 constexpr bool Equal(const Rect& other) const
1227 {
1228 return SDL_RectsEqual(this, &other);
1229 }
1230
1239 constexpr bool Contains(const Point& p) const
1240 {
1241 return SDL_PointInRect(&p, this);
1242 }
1243
1252 constexpr bool Contains(const Rect& other) const
1253 {
1254 return GetUnion(other) == *this;
1255 }
1256
1269 bool HasIntersection(const Rect& other) const
1270 {
1271 return SDL_HasRectIntersection(this, &other);
1272 }
1273
1287 constexpr std::optional<Rect> GetIntersection(const Rect& other) const
1288 {
1289 if (Rect result; SDL_GetRectIntersection(this, &other, &result)) {
1290 return result;
1291 }
1292 return std::nullopt;
1293 }
1294
1304 constexpr Rect GetUnion(const Rect& other) const
1305 {
1306 Rect result;
1307 CheckError(SDL_GetRectUnion(this, &other, &result));
1308 return result;
1309 }
1310
1319 constexpr Rect GetExtension(unsigned int amount) const
1320 {
1321 Rect r = *this;
1322 r.Extend(amount);
1323 return r;
1324 }
1325
1337 constexpr Rect GetExtension(unsigned int hAmount, unsigned int vAmount) const
1338 {
1339 Rect r = *this;
1340 r.Extend(hAmount, vAmount);
1341 return r;
1342 }
1343
1352 constexpr Rect& Extend(unsigned int amount) { return Extend(amount, amount); }
1353
1365 constexpr Rect& Extend(unsigned int hAmount, unsigned int vAmount)
1366 {
1367 x -= hAmount;
1368 y -= vAmount;
1369 w += hAmount * 2;
1370 h += vAmount * 2;
1371 return *this;
1372 }
1373
1382 constexpr Rect operator+(const Point& offset) const
1383 {
1384 return Rect(x + offset.x, y + offset.y, w, h);
1385 }
1386
1395 constexpr Rect operator-(const Point& offset) const
1396 {
1397 return Rect(x - offset.x, y - offset.y, w, h);
1398 }
1399
1408 constexpr Rect& operator+=(const Point& offset)
1409 {
1410 x += offset.x;
1411 y += offset.y;
1412 return *this;
1413 }
1414
1423 constexpr Rect& operator-=(const Point& offset)
1424 {
1425 x -= offset.x;
1426 y -= offset.y;
1427 return *this;
1428 }
1429};
1430
1438struct FRect : SDL_FRect
1439{
1445 constexpr FRect(const SDL_FRect& r = {})
1446 : SDL_FRect{r}
1447 {
1448 }
1449
1458 constexpr FRect(float x, float y, float w, float h)
1459 : SDL_FRect{x, y, w, h}
1460 {
1461 }
1462
1464 constexpr FRect(const SDL_FPoint& corner, const SDL_FPoint& size)
1465 : FRect{corner.x, corner.y, size.x, size.y}
1466 {
1467 }
1468
1472 constexpr bool operator==(const FRect& other) const { return Equal(other); }
1473
1477 constexpr bool operator==(const SDL_FRect& r) const
1478 {
1479 return operator==(FRect(r));
1480 }
1481
1485 constexpr operator bool() const { return !Empty(); }
1486
1493 constexpr float GetX() const { return x; }
1494
1501 constexpr FRect& SetX(float newX)
1502 {
1503 x = newX;
1504 return *this;
1505 }
1506
1513 constexpr float GetY() const { return y; }
1514
1521 constexpr FRect& SetY(float newY)
1522 {
1523 y = newY;
1524 return *this;
1525 }
1526
1533 constexpr float GetW() const { return w; }
1534
1541 constexpr FRect& SetW(float newW)
1542 {
1543 w = newW;
1544 return *this;
1545 }
1546
1553 constexpr float GetH() const { return h; }
1554
1561 constexpr FRect& SetH(float newH)
1562 {
1563 h = newH;
1564 return *this;
1565 }
1566
1586 OptionalRef<const SDL_FRect> clip = std::nullopt)
1587 {
1588 if (FRect result; SDL_GetRectEnclosingPointsFloat(
1589 points.data(), points.size(), clip, &result)) {
1590 return result;
1591 }
1592 return {};
1593 }
1594
1604 static constexpr FRect FromCenter(float cx, float cy, float w, float h)
1605 {
1606 return FRect(cx - w / 2, cy - h / 2, w, h);
1607 }
1608
1616 static constexpr FRect FromCenter(const FPoint& center, const FPoint& size)
1617 {
1618 return FRect(center - size / 2, size);
1619 }
1620
1630 static constexpr FRect FromCorners(float x1, float y1, float x2, float y2)
1631 {
1632 return FRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
1633 }
1634
1642 static constexpr FRect FromCorners(const FPoint& p1, const FPoint& p2)
1643 {
1644 return FRect(p1, p2 - p1 + FPoint(1, 1));
1645 }
1646
1653 constexpr float GetX2() const { return x + w - 1; }
1654
1665 constexpr FRect& SetX2(float x2)
1666 {
1667 w = x2 - x + 1;
1668 return *this;
1669 }
1670
1677 constexpr float GetY2() const { return y + h - 1; }
1678
1689 constexpr FRect& SetY2(float y2)
1690 {
1691 h = y2 - y + 1;
1692 return *this;
1693 }
1694
1701 constexpr FPoint GetTopLeft() const { return FPoint(x, y); }
1702
1709 constexpr FPoint GetTopRight() const { return FPoint(GetX2(), y); }
1710
1717 constexpr FPoint GetBottomLeft() const { return FPoint(x, GetY2()); }
1718
1725 constexpr FPoint GetBottomRight() const { return FPoint(GetX2(), GetY2()); }
1726
1733 constexpr FPoint GetSize() const { return FPoint(w, h); }
1734
1741 constexpr FPoint GetCentroid() const { return FPoint(x + w / 2, y + h / 2); }
1742
1761 bool IntersectLine(float* X1, float* Y1, float* X2, float* Y2) const
1762 {
1763 return SDL_GetRectAndLineIntersectionFloat(this, X1, Y1, X2, Y2);
1764 }
1765
1782 bool IntersectLine(FPoint* p1, FPoint* p2) const
1783 {
1784 return IntersectLine(p1 ? &p1->x : nullptr,
1785 p1 ? &p1->y : nullptr,
1786 p2 ? &p2->x : nullptr,
1787 p2 ? &p2->y : nullptr);
1788 }
1789
1807 constexpr bool Empty() const { return SDL_RectEmptyFloat(this); }
1808
1833 constexpr bool EqualEpsilon(const FRect& other, const float epsilon) const
1834 {
1835 return SDL_RectsEqualEpsilon(this, &other, epsilon);
1836 }
1837
1856 constexpr bool Equal(const FRect& other) const
1857 {
1858 return SDL_RectsEqualFloat(this, &other);
1859 }
1860
1869 constexpr bool Contains(const FPoint& p) const
1870 {
1871 return SDL_PointInRectFloat(&p, this);
1872 }
1873
1882 constexpr bool Contains(const FRect& other) const
1883 {
1884 return GetUnion(other) == *this;
1885 }
1886
1899 bool HasIntersection(const FRect& other) const
1900 {
1901 return SDL_HasRectIntersectionFloat(this, &other);
1902 }
1903
1917 FRect GetIntersection(const FRect& other) const
1918 {
1919 if (FRect result; SDL_GetRectIntersectionFloat(this, &other, &result)) {
1920 return result;
1921 }
1922 return {};
1923 }
1924
1934 FRect GetUnion(const FRect& other) const
1935 {
1936 FRect result;
1937 CheckError(SDL_GetRectUnionFloat(this, &other, &result));
1938 return result;
1939 }
1940
1949 constexpr FRect GetExtension(unsigned int amount) const
1950 {
1951 FRect r = *this;
1952 r.Extend(amount);
1953 return r;
1954 }
1955
1967 constexpr FRect GetExtension(float hAmount, float vAmount) const
1968 {
1969 FRect r = *this;
1970 r.Extend(hAmount, vAmount);
1971 return r;
1972 }
1973
1982 constexpr FRect& Extend(float amount) { return Extend(amount, amount); }
1983
1995 constexpr FRect& Extend(float hAmount, float vAmount)
1996 {
1997 x -= hAmount;
1998 y -= vAmount;
1999 w += hAmount * 2;
2000 h += vAmount * 2;
2001 return *this;
2002 }
2003
2012 constexpr FRect operator+(const FPoint& offset) const
2013 {
2014 return FRect(x + offset.x, y + offset.y, w, h);
2015 }
2016
2025 constexpr FRect operator-(const FPoint& offset) const
2026 {
2027 return FRect(x - offset.x, y - offset.y, w, h);
2028 }
2029
2038 constexpr FRect& operator+=(const FPoint& offset)
2039 {
2040 x += offset.x;
2041 y += offset.y;
2042 return *this;
2043 }
2044
2053 constexpr FRect& operator-=(const FPoint& offset)
2054 {
2055 x -= offset.x;
2056 y -= offset.y;
2057 return *this;
2058 }
2059};
2060
2061constexpr bool Point::IsInRect(const Rect& r) const
2062{
2063 return r.Contains(*this);
2064}
2065
2066constexpr bool FPoint::IsInRect(const FRect& r) const
2067{
2068 return r.Contains(*this);
2069}
2070
2071#pragma region impl
2073
2074constexpr Point::operator FPoint() const { return {float(x), float(y)}; }
2075
2076constexpr FPoint Point::operator/(float value) const
2077{
2078 return FPoint(*this) / value;
2079}
2080constexpr FPoint Point::operator*(float value) const
2081{
2082 return FPoint(*this) * value;
2083}
2084
2085constexpr Point Point::GetClamped(const Rect& rect) const
2086{
2087 Point p = *this;
2088 p.Clamp(rect);
2089 return p;
2090}
2091
2092constexpr Point& Point::Clamp(const Rect& rect)
2093{
2094 if (x < rect.x) x = rect.x;
2095 if (x > rect.GetX2()) x = rect.GetX2();
2096 if (y < rect.y) y = rect.y;
2097 if (y > rect.GetY2()) y = rect.GetY2();
2098 return *this;
2099}
2100
2101constexpr Point Point::GetWrapped(const Rect& rect) const
2102{
2103 Point p = *this;
2104 p.Wrap(rect);
2105 return p;
2106}
2107
2108constexpr Point& Point::Wrap(const Rect& rect)
2109{
2110 if (x < rect.x)
2111 x = rect.x + rect.w - 1 - (rect.x - x + rect.w - 1) % rect.w;
2112 else if (x >= rect.x + rect.w)
2113 x = rect.x + (x - rect.x - rect.w) % rect.w;
2114
2115 if (y < rect.y)
2116 y = rect.y + rect.h - 1 - (rect.y - y + rect.h - 1) % rect.h;
2117 else if (y >= rect.y + rect.h)
2118 y = rect.y + (y - rect.y - rect.h) % rect.h;
2119
2120 return *this;
2121}
2122
2123constexpr FPoint FPoint::GetClamped(const FRect& rect) const
2124{
2125 FPoint p = *this;
2126 p.Clamp(rect);
2127 return p;
2128}
2129
2130constexpr FPoint& FPoint::Clamp(const FRect& rect)
2131{
2132 if (x < rect.x) x = rect.x;
2133 if (x > rect.GetX2()) x = rect.GetX2();
2134 if (y < rect.y) y = rect.y;
2135 if (y > rect.GetY2()) y = rect.GetY2();
2136 return *this;
2137}
2138
2139constexpr FPoint FPoint::GetWrapped(const FRect& rect) const
2140{
2141 FPoint p = *this;
2142 p.Wrap(rect);
2143 return p;
2144}
2145
2146constexpr FPoint& FPoint::Wrap(const FRect& rect)
2147{
2148 if (x < rect.x)
2149 x = rect.x + rect.w - 1 - fmod(rect.x - x + rect.w - 1, rect.w);
2150 else if (x >= rect.x + rect.w)
2151 x = rect.x + fmod(x - rect.x - rect.w, rect.w);
2152
2153 if (y < rect.y)
2154 y = rect.y + rect.h - 1 - fmod(rect.y - y + rect.h - 1, rect.h);
2155 else if (y >= rect.y + rect.h)
2156 y = rect.y + fmod(y - rect.y - rect.h, rect.h);
2157
2158 return *this;
2159}
2160
2161constexpr Rect::operator FRect() const
2162{
2163 return {float(x), float(y), float(w), float(h)};
2164}
2165
2166#pragma endregion impl
2167
2168} // namespace SDL
2169
2170#endif /* SDL3PP_RECT_H_ */
Optional-like shim for references.
Definition SDL3pp_optionalRef.h:20
span-like for empty-derived structs
Definition SDL3pp_spanRef.h:24
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:206
constexpr bool IsInRect(const Rect &r) const
Determine whether a point resides inside a rectangle.
Definition SDL3pp_rect.h:2061
constexpr bool IsInRect(const FRect &r) const
Determine whether a point resides inside a floating point rectangle.
Definition SDL3pp_rect.h:2066
double fmod(double x, double y)
Return the floating-point remainder of x / y
Definition SDL3pp_stdinc.h:4579
the main namespace where all SDL3pp public functions and types live
Definition SDL3pp_assert.h:7
The structure that defines a point (using floating point values).
Definition SDL3pp_rect.h:479
constexpr FPoint operator/(const FPoint &other) const
Get point's memberwise division by another point.
Definition SDL3pp_rect.h:641
constexpr FPoint(float x, float y)
Constructs from its fields.
Definition SDL3pp_rect.h:496
constexpr FPoint & Wrap(const FRect &rect)
Wrap point coordinates within a specified rect.
Definition SDL3pp_rect.h:2146
constexpr float GetX() const
Get the x coordinate.
Definition SDL3pp_rect.h:529
constexpr float GetY() const
Get the y coordinate.
Definition SDL3pp_rect.h:548
constexpr FPoint operator-() const
Get point's memberwise negation.
Definition SDL3pp_rect.h:590
constexpr FPoint & operator/=(const FPoint &other)
Memberwise divide by another point.
Definition SDL3pp_rect.h:729
constexpr FPoint(const SDL_FPoint &p={})
Wraps FPoint.
Definition SDL3pp_rect.h:485
constexpr FPoint operator/(float value) const
Get point's memberwise division by an float.
Definition SDL3pp_rect.h:627
constexpr FPoint operator-(const FPoint &other) const
Get point's memberwise subtraction with another point.
Definition SDL3pp_rect.h:613
constexpr FPoint operator*(float value) const
Get point's memberwise multiplication by an float.
Definition SDL3pp_rect.h:656
constexpr FPoint & operator/=(float value)
Memberwise divide by an float.
Definition SDL3pp_rect.h:714
constexpr FPoint & SetX(float newX)
Set the x coordinate.
Definition SDL3pp_rect.h:537
constexpr FPoint GetClamped(const FRect &rect) const
Get a point with coordinates modified so it fits into a given rect.
Definition SDL3pp_rect.h:2123
constexpr bool operator==(const SDL_FPoint &p) const
Compares with the underlying type.
Definition SDL3pp_rect.h:512
constexpr FPoint & operator*=(const FPoint &other)
Memberwise multiply by another point.
Definition SDL3pp_rect.h:759
constexpr FPoint GetWrapped(const FRect &rect) const
Get a point wrapped within a specified rect.
Definition SDL3pp_rect.h:2139
constexpr FPoint operator+(const FPoint &other) const
Get point's memberwise addition with another point.
Definition SDL3pp_rect.h:600
constexpr FPoint & SetY(float newY)
Set the y coordinate.
Definition SDL3pp_rect.h:556
constexpr FPoint & Clamp(const FRect &rect)
Clamp point coordinates to make it fit into a given rect.
Definition SDL3pp_rect.h:2130
constexpr FPoint & operator*=(float value)
Memberwise multiply by an float.
Definition SDL3pp_rect.h:744
constexpr FPoint & operator-=(const FPoint &other)
Memberwise subtract another point.
Definition SDL3pp_rect.h:699
constexpr bool operator==(const FPoint &other) const
Default comparison operator.
Definition SDL3pp_rect.h:504
constexpr FPoint operator*(const FPoint &other) const
Get point's memberwise multiplication by another point.
Definition SDL3pp_rect.h:671
constexpr FPoint & operator+=(const FPoint &other)
Memberwise add another point.
Definition SDL3pp_rect.h:684
A rectangle, with the origin at the upper left (using floats).
Definition SDL3pp_rect.h:1439
constexpr float GetH() const
Get height of the rect.
Definition SDL3pp_rect.h:1553
constexpr bool EqualEpsilon(const FRect &other, const float epsilon) const
Determine whether two floating point rectangles are equal, within some given epsilon.
Definition SDL3pp_rect.h:1833
FRect GetIntersection(const FRect &other) const
Calculate the intersection of two rectangles with float precision.
Definition SDL3pp_rect.h:1917
bool HasIntersection(const FRect &other) const
Determine whether two rectangles intersect.
Definition SDL3pp_rect.h:1899
constexpr bool Equal(const FRect &other) const
Determine whether two rectangles are equal.
Definition SDL3pp_rect.h:1856
constexpr FRect & Extend(float hAmount, float vAmount)
Extend a rect by specified amount of pixels.
Definition SDL3pp_rect.h:1995
static constexpr FRect FromCenter(const FPoint &center, const FPoint &size)
Construct the rect from given center coordinates and size.
Definition SDL3pp_rect.h:1616
constexpr FRect & SetH(float newH)
Set the height of the rect.
Definition SDL3pp_rect.h:1561
constexpr FRect & SetW(float newW)
Set the width of the rect.
Definition SDL3pp_rect.h:1541
constexpr bool Contains(const FPoint &p) const
Check whether the rect contains given point.
Definition SDL3pp_rect.h:1869
constexpr float GetY() const
Get top y coordinate.
Definition SDL3pp_rect.h:1513
constexpr FRect operator+(const FPoint &offset) const
Get rectangle moved by a given offset.
Definition SDL3pp_rect.h:2012
constexpr bool operator==(const FRect &other) const
Definition SDL3pp_rect.h:1472
constexpr FPoint GetTopRight() const
Get top right corner of the rect.
Definition SDL3pp_rect.h:1709
constexpr FRect operator-(const FPoint &offset) const
Get rectangle moved by an opposite of given offset.
Definition SDL3pp_rect.h:2025
constexpr float GetW() const
Get width of the rect.
Definition SDL3pp_rect.h:1533
constexpr FRect & operator+=(const FPoint &offset)
Move by then given offset.
Definition SDL3pp_rect.h:2038
bool IntersectLine(FPoint *p1, FPoint *p2) const
Calculate the intersection of a rectangle and line segment.
Definition SDL3pp_rect.h:1782
constexpr bool operator==(const SDL_FRect &r) const
Compares with the underlying type.
Definition SDL3pp_rect.h:1477
constexpr FRect & operator-=(const FPoint &offset)
Move by an opposite of the given offset.
Definition SDL3pp_rect.h:2053
constexpr FPoint GetBottomRight() const
Get bottom right corner of the rect.
Definition SDL3pp_rect.h:1725
constexpr FPoint GetBottomLeft() const
Get bottom left corner of the rect.
Definition SDL3pp_rect.h:1717
constexpr bool Empty() const
Determine whether a rectangle has no area.
Definition SDL3pp_rect.h:1807
constexpr float GetX2() const
Get X coordinate of the rect second corner.
Definition SDL3pp_rect.h:1653
constexpr FRect GetExtension(unsigned int amount) const
Get a rect extended by specified amount of pixels.
Definition SDL3pp_rect.h:1949
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:1604
constexpr float GetY2() const
Get Y coordinate of the rect second corner.
Definition SDL3pp_rect.h:1677
constexpr FRect & SetY2(float y2)
Set Y coordinate of the rect second corner.
Definition SDL3pp_rect.h:1689
constexpr FRect & SetY(float newY)
Set the top y coordinate.
Definition SDL3pp_rect.h:1521
constexpr FRect(const SDL_FRect &r={})
Wraps FRect.
Definition SDL3pp_rect.h:1445
constexpr FRect & SetX2(float x2)
Set X coordinate of the rect second corner.
Definition SDL3pp_rect.h:1665
static constexpr FRect FromCorners(float x1, float y1, float x2, float y2)
Construct the rect from given corners coordinates.
Definition SDL3pp_rect.h:1630
constexpr FRect(const SDL_FPoint &corner, const SDL_FPoint &size)
Constructs from top-left corner plus size.
Definition SDL3pp_rect.h:1464
bool IntersectLine(float *X1, float *Y1, float *X2, float *Y2) const
Calculate the intersection of a rectangle and line segment with float precision.
Definition SDL3pp_rect.h:1761
constexpr FRect & SetX(float newX)
Set the left x coordinate.
Definition SDL3pp_rect.h:1501
constexpr FRect & Extend(float amount)
Extend a rect by specified amount of pixels.
Definition SDL3pp_rect.h:1982
static constexpr FRect FromCorners(const FPoint &p1, const FPoint &p2)
Construct the rect from given centers coordinates.
Definition SDL3pp_rect.h:1642
static FRect GetEnclosingPoints(SpanRef< const SDL_FPoint > points, OptionalRef< const SDL_FRect > clip=std::nullopt)
Calculate a minimal rectangle enclosing a set of points with float precision.
Definition SDL3pp_rect.h:1584
FRect GetUnion(const FRect &other) const
Calculate the union of two rectangles with float precision.
Definition SDL3pp_rect.h:1934
constexpr FRect GetExtension(float hAmount, float vAmount) const
Get a rect extended by specified amount of pixels.
Definition SDL3pp_rect.h:1967
constexpr FPoint GetCentroid() const
Get centroid of the rect.
Definition SDL3pp_rect.h:1741
constexpr FRect(float x, float y, float w, float h)
Constructs from its fields.
Definition SDL3pp_rect.h:1458
constexpr FPoint GetTopLeft() const
Get top left corner of the rect.
Definition SDL3pp_rect.h:1701
constexpr FPoint GetSize() const
Get size of the rect.
Definition SDL3pp_rect.h:1733
constexpr bool Contains(const FRect &other) const
Check whether the rect contains given point.
Definition SDL3pp_rect.h:1882
constexpr float GetX() const
Get left x coordinate.
Definition SDL3pp_rect.h:1493
The structure that defines a point (using integers)
Definition SDL3pp_rect.h:41
constexpr Point & operator/=(int value)
Memberwise divide by an integer.
Definition SDL3pp_rect.h:338
constexpr Point & operator%=(const Point &other)
Memberwise remainder from division by another point.
Definition SDL3pp_rect.h:384
constexpr Point operator/(int value) const
Get point's memberwise division by an integer.
Definition SDL3pp_rect.h:198
constexpr Point GetClamped(const Rect &rect) const
Get a point with coordinates modified so it fits into a given rect.
Definition SDL3pp_rect.h:2085
constexpr Point operator-(const Point &other) const
Get point's memberwise subtraction with another point.
Definition SDL3pp_rect.h:184
constexpr int GetX() const
Get x coordinate.
Definition SDL3pp_rect.h:99
constexpr Point operator+(const Point &other) const
Get point's memberwise addition with another point.
Definition SDL3pp_rect.h:171
constexpr Point & Clamp(const Rect &rect)
Clamp point coordinates to make it fit into a given rect.
Definition SDL3pp_rect.h:2092
constexpr Point operator*(const Point &other) const
Get point's memberwise multiplication by another point.
Definition SDL3pp_rect.h:295
constexpr Point operator%(int value) const
Get point's memberwise remainder from division by an integer.
Definition SDL3pp_rect.h:238
constexpr Point & operator*=(const Point &other)
Memberwise multiply by another point.
Definition SDL3pp_rect.h:414
constexpr Point & SetX(int newX)
Set the x coordinate.
Definition SDL3pp_rect.h:107
constexpr bool operator==(const SDL_Point &p) const
Compares with the underlying type.
Definition SDL3pp_rect.h:82
constexpr Point & operator-=(const Point &other)
Memberwise subtract another point.
Definition SDL3pp_rect.h:323
constexpr Point(const SDL_Point &p={})
Wraps Point.
Definition SDL3pp_rect.h:47
constexpr Point(const SDL_FPoint &p)
Explicit conversion from FPoint.
Definition SDL3pp_rect.h:66
constexpr Point operator*(int value) const
Get point's memberwise multiplication by an integer.
Definition SDL3pp_rect.h:268
constexpr Point & operator/=(const Point &other)
Memberwise divide by another point.
Definition SDL3pp_rect.h:353
constexpr bool operator==(const Point &other) const
Default comparison operator.
Definition SDL3pp_rect.h:74
constexpr Point operator%(const Point &other) const
Get point's memberwise remainder from division by another point.
Definition SDL3pp_rect.h:253
constexpr Point GetWrapped(const Rect &rect) const
Get a point wrapped within a specified rect.
Definition SDL3pp_rect.h:2101
constexpr Point(int x, int y)
Constructs from its fields.
Definition SDL3pp_rect.h:58
constexpr Point & Wrap(const Rect &rect)
Wrap point coordinates within a specified rect.
Definition SDL3pp_rect.h:2108
constexpr int GetY() const
Get y coordinate.
Definition SDL3pp_rect.h:119
constexpr Point & SetY(int newY)
Set the y.
Definition SDL3pp_rect.h:127
constexpr Point & operator%=(int value)
Memberwise remainder from division by an integer.
Definition SDL3pp_rect.h:368
constexpr Point operator/(const Point &other) const
Get point's memberwise division by another point.
Definition SDL3pp_rect.h:223
constexpr Point & operator+=(const Point &other)
Memberwise add another point.
Definition SDL3pp_rect.h:308
constexpr Point operator-() const
Get point's memberwise negation.
Definition SDL3pp_rect.h:161
constexpr Point & operator*=(int value)
Memberwise multiply by an integer.
Definition SDL3pp_rect.h:399
A rectangle, with the origin at the upper left (using integers).
Definition SDL3pp_rect.h:817
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:987
constexpr bool Equal(const Rect &other) const
Determine whether two rectangles are equal.
Definition SDL3pp_rect.h:1226
constexpr int GetX() const
Get left x coordinate.
Definition SDL3pp_rect.h:876
constexpr Rect & operator-=(const Point &offset)
Move by an opposite of the given offset.
Definition SDL3pp_rect.h:1423
constexpr int GetW() const
Get width of the rect.
Definition SDL3pp_rect.h:916
static constexpr Rect FromCenter(const Point &center, const Point &size)
Construct the rect from given center coordinates and size.
Definition SDL3pp_rect.h:999
constexpr Rect GetExtension(unsigned int hAmount, unsigned int vAmount) const
Get a rect extended by specified amount of pixels.
Definition SDL3pp_rect.h:1337
constexpr Rect(int x, int y, int w, int h)
Constructs from its fields.
Definition SDL3pp_rect.h:836
constexpr Rect(const SDL_Rect &r={})
Wraps Rect.
Definition SDL3pp_rect.h:823
constexpr Rect & SetY(int newY)
Set the top y coordinate.
Definition SDL3pp_rect.h:904
constexpr Point GetTopLeft() const
Get top left corner of the rect.
Definition SDL3pp_rect.h:1084
constexpr bool Contains(const Point &p) const
Check whether the rect contains given point.
Definition SDL3pp_rect.h:1239
constexpr std::optional< Rect > GetIntersection(const Rect &other) const
Calculate the intersection of two rectangles.
Definition SDL3pp_rect.h:1287
constexpr Rect & Extend(unsigned int hAmount, unsigned int vAmount)
Extend a rect by specified amount of pixels.
Definition SDL3pp_rect.h:1365
constexpr bool operator==(const SDL_Rect &r) const
Compares with the underlying type.
Definition SDL3pp_rect.h:860
constexpr Rect operator+(const Point &offset) const
Get rectangle moved by a given offset.
Definition SDL3pp_rect.h:1382
bool IntersectLine(Point *p1, Point *p2) const
Calculate the intersection of a rectangle and line segment.
Definition SDL3pp_rect.h:1164
constexpr bool Empty() const
Determine whether a rectangle has no area.
Definition SDL3pp_rect.h:1206
constexpr Rect & operator+=(const Point &offset)
Move by then given offset.
Definition SDL3pp_rect.h:1408
constexpr bool operator==(const Rect &other) const
Definition SDL3pp_rect.h:855
constexpr Rect(const SDL_Point &corner, const SDL_Point &size)
Construct from offset and size.
Definition SDL3pp_rect.h:847
constexpr Rect GetExtension(unsigned int amount) const
Get a rect extended by specified amount of pixels.
Definition SDL3pp_rect.h:1319
constexpr Rect & Extend(unsigned int amount)
Extend a rect by specified amount of pixels.
Definition SDL3pp_rect.h:1352
constexpr Rect GetUnion(const Rect &other) const
Calculate the union of two rectangles.
Definition SDL3pp_rect.h:1304
constexpr Rect & SetW(int newW)
Set the width of the rect.
Definition SDL3pp_rect.h:924
static Rect GetEnclosingPoints(SpanRef< const SDL_Point > points, OptionalRef< const SDL_Rect > clip=std::nullopt)
Calculate a minimal rectangle enclosing a set of points.
Definition SDL3pp_rect.h:966
constexpr Point GetCentroid() const
Get centroid of the rect.
Definition SDL3pp_rect.h:1124
constexpr Point GetBottomLeft() const
Get bottom left corner of the rect.
Definition SDL3pp_rect.h:1100
constexpr int GetH() const
Get height of the rect.
Definition SDL3pp_rect.h:936
constexpr Rect & SetX2(int x2)
Set X coordinate of the rect second corner.
Definition SDL3pp_rect.h:1048
constexpr Rect & SetH(int newH)
Set the height of the rect.
Definition SDL3pp_rect.h:944
static constexpr Rect FromCorners(int x1, int y1, int x2, int y2)
Construct the rect from given corners coordinates.
Definition SDL3pp_rect.h:1013
constexpr Point GetSize() const
Get size of the rect.
Definition SDL3pp_rect.h:1116
constexpr Rect operator-(const Point &offset) const
Get rectangle moved by an opposite of given offset.
Definition SDL3pp_rect.h:1395
constexpr Point GetBottomRight() const
Get bottom right corner of the rect.
Definition SDL3pp_rect.h:1108
constexpr int GetY2() const
Get Y coordinate of the rect second corner.
Definition SDL3pp_rect.h:1060
static constexpr Rect FromCorners(const Point &p1, const Point &p2)
Construct the rect from given centers coordinates.
Definition SDL3pp_rect.h:1025
bool HasIntersection(const Rect &other) const
Determine whether two rectangles intersect.
Definition SDL3pp_rect.h:1269
constexpr int GetY() const
Get top y coordinate.
Definition SDL3pp_rect.h:896
constexpr Rect & SetX(int newX)
Set the left x coordinate.
Definition SDL3pp_rect.h:884
constexpr bool Contains(const Rect &other) const
Check whether the rect contains given point.
Definition SDL3pp_rect.h:1252
constexpr Rect & SetY2(int y2)
Set Y coordinate of the rect second corner.
Definition SDL3pp_rect.h:1072
bool IntersectLine(int *X1, int *Y1, int *X2, int *Y2) const
Calculate the intersection of a rectangle and line segment.
Definition SDL3pp_rect.h:1143
constexpr Point GetTopRight() const
Get top right corner of the rect.
Definition SDL3pp_rect.h:1092
constexpr int GetX2() const
Get X coordinate of the rect second corner.
Definition SDL3pp_rect.h:1036