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)
47{
48 return lhs.x == rhs.x && lhs.y == rhs.y;
49}
50
52constexpr bool operator==(const FPointRaw& lhs, const FPointRaw& rhs)
53{
54 return lhs.x == rhs.x && lhs.y == rhs.y;
55}
56
58constexpr bool operator==(const RectRaw& lhs, const RectRaw& rhs)
59{
60 return SDL_RectsEqual(&lhs, &rhs);
61}
62
64constexpr bool operator==(const FRectRaw& lhs, const FRectRaw& rhs)
65{
66 return SDL_RectsEqualFloat(&lhs, &rhs);
67}
68
83{
89 constexpr Point(const PointRaw& p = {})
90 : PointRaw(p)
91 {
92 }
93
100 constexpr Point(int x, int y)
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 { return *this != PointRaw{}; }
121
127 constexpr int GetX() const { return x; }
128
135 constexpr Point& SetX(int newX)
136 {
137 x = newX;
138 return *this;
139 }
140
146 constexpr int GetY() const { return y; }
147
154 constexpr Point& SetY(int newY)
155 {
156 y = newY;
157 return *this;
158 }
159
180 constexpr bool InRect(const RectRaw& r) const;
181
188 constexpr Point operator-() const { return Point(-x, -y); }
189
198 constexpr Point operator+(const Point& other) const
199 {
200 return Point(x + other.x, y + other.y);
201 }
202
211 constexpr Point operator-(const Point& other) const
212 {
213 return Point(x - other.x, y - other.y);
214 }
215
225 constexpr Point operator/(int value) const
226 {
227 return Point(x / value, y / value);
228 }
229
239 constexpr FPoint operator/(float value) const;
240
250 constexpr Point operator/(const Point& other) const
251 {
252 return Point(x / other.x, y / other.y);
253 }
254
265 constexpr Point operator%(int value) const
266 {
267 return Point(x % value, y % value);
268 }
269
280 constexpr Point operator%(const Point& other) const
281 {
282 return Point(x % other.x, y % other.y);
283 }
284
295 constexpr Point operator*(int value) const
296 {
297 return Point(x * value, y * value);
298 }
299
310 constexpr FPoint operator*(float value) const;
311
322 constexpr Point operator*(const Point& other) const
323 {
324 return Point(x * other.x, y * other.y);
325 }
326
335 constexpr Point& operator+=(const Point& other)
336 {
337 x += other.x;
338 y += other.y;
339 return *this;
340 }
341
350 constexpr Point& operator-=(const Point& other)
351 {
352 x -= other.x;
353 y -= other.y;
354 return *this;
355 }
356
365 constexpr Point& operator/=(int value)
366 {
367 x /= value;
368 y /= value;
369 return *this;
370 }
371
380 constexpr Point& operator/=(const Point& other)
381 {
382 x /= other.x;
383 y /= other.y;
384 return *this;
385 }
386
395 constexpr Point& operator%=(int value)
396 {
397 x %= value;
398 y %= value;
399 return *this;
400 }
401
411 constexpr Point& operator%=(const Point& other)
412 {
413 x %= other.x;
414 y %= other.y;
415 return *this;
416 }
417
426 constexpr Point& operator*=(int value)
427 {
428 x *= value;
429 y *= value;
430 return *this;
431 }
432
441 constexpr Point& operator*=(const Point& other)
442 {
443 x *= other.x;
444 y *= other.y;
445 return *this;
446 }
447
457 constexpr Point GetClamped(const Rect& rect) const;
458
468 constexpr Point& Clamp(const Rect& rect);
469
478 constexpr Point GetWrapped(const Rect& rect) const;
479
488 constexpr Point& Wrap(const Rect& rect);
489
495 constexpr operator FPoint() const;
496};
497
509{
515 constexpr FPoint(const FPointRaw& p = {})
516 : FPointRaw(p)
517 {
518 }
519
526 constexpr FPoint(float x, float y)
527 : FPointRaw{x, y}
528 {
529 }
530
536 constexpr explicit operator bool() const { return *this != FPointRaw{}; }
537
543 constexpr float GetX() const { return x; }
544
551 constexpr FPoint& SetX(float newX)
552 {
553 x = newX;
554 return *this;
555 }
556
562 constexpr float GetY() const { return y; }
563
570 constexpr FPoint& SetY(float newY)
571 {
572 y = newY;
573 return *this;
574 }
575
596 constexpr bool InRect(const FRectRaw& r) const;
597
604 constexpr FPoint operator-() const { return FPoint(-x, -y); }
605
614 constexpr FPoint operator+(const FPoint& other) const
615 {
616 return FPoint(x + other.x, y + other.y);
617 }
618
627 constexpr FPoint operator-(const FPoint& other) const
628 {
629 return FPoint(x - other.x, y - other.y);
630 }
631
641 constexpr FPoint operator/(float value) const
642 {
643 return FPoint(x / value, y / value);
644 }
645
655 constexpr FPoint operator/(const FPoint& other) const
656 {
657 return FPoint(x / other.x, y / other.y);
658 }
659
670 constexpr FPoint operator*(float value) const
671 {
672 return FPoint(x * value, y * value);
673 }
674
685 constexpr FPoint operator*(const FPoint& other) const
686 {
687 return FPoint(x * other.x, y * other.y);
688 }
689
698 constexpr FPoint& operator+=(const FPoint& other)
699 {
700 x += other.x;
701 y += other.y;
702 return *this;
703 }
704
713 constexpr FPoint& operator-=(const FPoint& other)
714 {
715 x -= other.x;
716 y -= other.y;
717 return *this;
718 }
719
728 constexpr FPoint& operator/=(float value)
729 {
730 x /= value;
731 y /= value;
732 return *this;
733 }
734
743 constexpr FPoint& operator/=(const FPoint& other)
744 {
745 x /= other.x;
746 y /= other.y;
747 return *this;
748 }
749
758 constexpr FPoint& operator*=(float value)
759 {
760 x *= value;
761 y *= value;
762 return *this;
763 }
764
773 constexpr FPoint& operator*=(const FPoint& other)
774 {
775 x *= other.x;
776 y *= other.y;
777 return *this;
778 }
779
789 constexpr FPoint GetClamped(const FRect& rect) const;
790
800 constexpr FPoint& Clamp(const FRect& rect);
801
810 constexpr FPoint GetWrapped(const FRect& rect) const;
811
820 constexpr FPoint& Wrap(const FRect& rect);
821};
822
838struct Rect : RectRaw
839{
845 constexpr Rect(const RectRaw& r = {})
846 : RectRaw(r)
847 {
848 }
849
858 constexpr Rect(int x, int y, int w, int h)
859 : RectRaw{x, y, w, h}
860 {
861 }
862
869 constexpr Rect(const PointRaw& corner, const PointRaw& size)
870 : Rect{corner.x, corner.y, size.x, size.y}
871 {
872 }
873
875 constexpr bool operator==(const RectRaw& other) const { return Equal(other); }
876
878 constexpr bool operator==(const Rect& other) const
879 {
880 return *this == (const RectRaw&)(other);
881 }
882
884 constexpr explicit operator bool() const { return !Empty(); }
885
891 constexpr int GetX() const { return x; }
892
899 constexpr Rect& SetX(int newX)
900 {
901 x = newX;
902 return *this;
903 }
904
910 constexpr int GetY() const { return y; }
911
918 constexpr Rect& SetY(int newY)
919 {
920 y = newY;
921 return *this;
922 }
923
929 constexpr int GetW() const { return w; }
930
937 constexpr Rect& SetW(int newW)
938 {
939 w = newW;
940 return *this;
941 }
942
948 constexpr int GetH() const { return h; }
949
956 constexpr Rect& SetH(int newH)
957 {
958 h = newH;
959 return *this;
960 }
961
980 OptionalRef<const RectRaw> clip = std::nullopt);
981
991 static constexpr Rect FromCenter(int cx, int cy, int w, int h)
992 {
993 return Rect(cx - w / 2, cy - h / 2, w, h);
994 }
995
1003 static constexpr Rect FromCenter(Point center, Point size)
1004 {
1005 return Rect(center - size / 2, size);
1006 }
1007
1017 static constexpr Rect FromCorners(int x1, int y1, int x2, int y2)
1018 {
1019 return Rect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
1020 }
1021
1029 static constexpr Rect FromCorners(Point p1, Point p2)
1030 {
1031 return Rect(p1, p2 - p1 + Point(1, 1));
1032 }
1033
1040 constexpr int GetX2() const { return x + w - 1; }
1041
1052 constexpr Rect& SetX2(int x2)
1053 {
1054 w = x2 - x + 1;
1055 return *this;
1056 }
1057
1064 constexpr int GetY2() const { return y + h - 1; }
1065
1076 constexpr Rect& SetY2(int y2)
1077 {
1078 h = y2 - y + 1;
1079 return *this;
1080 }
1081
1088 constexpr Point GetTopLeft() const { return Point(x, y); }
1089
1096 constexpr Point GetTopRight() const { return Point(GetX2(), y); }
1097
1104 constexpr Point GetBottomLeft() const { return Point(x, GetY2()); }
1105
1112 constexpr Point GetBottomRight() const { return Point(GetX2(), GetY2()); }
1113
1120 constexpr Point GetSize() const { return Point(w, h); }
1121
1128 constexpr Point GetCentroid() const { return Point(x + w / 2, y + h / 2); }
1129
1147 {
1148 return GetLineIntersection(p1 ? &p1->x : nullptr,
1149 p1 ? &p1->y : nullptr,
1150 p2 ? &p2->x : nullptr,
1151 p2 ? &p2->y : nullptr);
1152 }
1153
1171 bool GetLineIntersection(int* X1, int* Y1, int* X2, int* Y2) const;
1172
1183 constexpr operator SDL_FRect() const;
1184
1186 constexpr operator FRect() const;
1187
1205 constexpr bool Empty() const;
1206
1225 constexpr bool Equal(const RectRaw& other) const;
1226
1235 constexpr bool Contains(const PointRaw& p) const
1236 {
1237 return SDL_PointInRect(&p, this);
1238 }
1239
1248 constexpr bool Contains(const RectRaw& other) const
1249 {
1250 return GetUnion(other) == *this;
1251 }
1252
1265 constexpr bool HasIntersection(const RectRaw& other) const;
1266
1280 constexpr Rect GetIntersection(const RectRaw& other) const;
1281
1291 constexpr Rect GetUnion(const RectRaw& other) const;
1292
1301 constexpr Rect GetExtension(unsigned int amount) const
1302 {
1303 Rect r = *this;
1304 r.Extend(amount);
1305 return r;
1306 }
1307
1319 constexpr Rect GetExtension(unsigned int hAmount, unsigned int vAmount) const
1320 {
1321 Rect r = *this;
1322 r.Extend(hAmount, vAmount);
1323 return r;
1324 }
1325
1334 constexpr Rect& Extend(unsigned int amount) { return Extend(amount, amount); }
1335
1347 constexpr Rect& Extend(unsigned int hAmount, unsigned int vAmount)
1348 {
1349 x -= hAmount;
1350 y -= vAmount;
1351 w += hAmount * 2;
1352 h += vAmount * 2;
1353 return *this;
1354 }
1355
1364 constexpr Rect operator+(const Point& offset) const
1365 {
1366 return Rect(x + offset.x, y + offset.y, w, h);
1367 }
1368
1377 constexpr Rect operator-(const Point& offset) const
1378 {
1379 return Rect(x - offset.x, y - offset.y, w, h);
1380 }
1381
1390 constexpr Rect& operator+=(const Point& offset)
1391 {
1392 x += offset.x;
1393 y += offset.y;
1394 return *this;
1395 }
1396
1405 constexpr Rect& operator-=(const Point& offset)
1406 {
1407 x -= offset.x;
1408 y -= offset.y;
1409 return *this;
1410 }
1411};
1412
1432{
1438 constexpr FRect(const FRectRaw& r = {})
1439 : FRectRaw(r)
1440 {
1441 }
1442
1451 constexpr FRect(float x, float y, float w, float h)
1452 : FRectRaw{x, y, w, h}
1453 {
1454 }
1455
1459 constexpr FRect(FPoint corner, FPoint size)
1460 : FRect{corner.x, corner.y, size.x, size.y}
1461 {
1462 }
1463
1465 constexpr bool operator==(const FRectRaw& other) const
1466 {
1467 return Equal(other);
1468 }
1469
1471 constexpr bool operator==(const FRect& other) const
1472 {
1473 return *this == (const FRectRaw&)(other);
1474 }
1475
1477 constexpr operator bool() const { return !Empty(); }
1478
1484 constexpr float GetX() const { return x; }
1485
1492 constexpr FRect& SetX(float newX)
1493 {
1494 x = newX;
1495 return *this;
1496 }
1497
1503 constexpr float GetY() const { return y; }
1504
1511 constexpr FRect& SetY(float newY)
1512 {
1513 y = newY;
1514 return *this;
1515 }
1516
1522 constexpr float GetW() const { return w; }
1523
1530 constexpr FRect& SetW(float newW)
1531 {
1532 w = newW;
1533 return *this;
1534 }
1535
1541 constexpr float GetH() const { return h; }
1542
1549 constexpr FRect& SetH(float newH)
1550 {
1551 h = newH;
1552 return *this;
1553 }
1554
1572 static constexpr FRect GetEnclosingPoints(
1574 OptionalRef<const FRectRaw> clip = std::nullopt);
1575
1585 static constexpr FRect FromCenter(float cx, float cy, float w, float h)
1586 {
1587 return FRect(cx - w / 2, cy - h / 2, w, h);
1588 }
1589
1597 static constexpr FRect FromCenter(FPoint center, FPoint size)
1598 {
1599 return FRect(center - size / 2, size);
1600 }
1601
1611 static constexpr FRect FromCorners(float x1, float y1, float x2, float y2)
1612 {
1613 return FRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
1614 }
1615
1623 static constexpr FRect FromCorners(FPoint p1, FPoint p2)
1624 {
1625 return FRect(p1, p2 - p1 + FPoint(1, 1));
1626 }
1627
1634 constexpr float GetX2() const { return x + w - 1; }
1635
1646 constexpr FRect& SetX2(float x2)
1647 {
1648 w = x2 - x + 1;
1649 return *this;
1650 }
1651
1658 constexpr float GetY2() const { return y + h - 1; }
1659
1670 constexpr FRect& SetY2(float y2)
1671 {
1672 h = y2 - y + 1;
1673 return *this;
1674 }
1675
1682 constexpr FPoint GetTopLeft() const { return FPoint(x, y); }
1683
1690 constexpr FPoint GetTopRight() const { return FPoint(GetX2(), y); }
1691
1698 constexpr FPoint GetBottomLeft() const { return FPoint(x, GetY2()); }
1699
1706 constexpr FPoint GetBottomRight() const { return FPoint(GetX2(), GetY2()); }
1707
1714 constexpr FPoint GetSize() const { return FPoint(w, h); }
1715
1722 constexpr FPoint GetCentroid() const { return FPoint(x + w / 2, y + h / 2); }
1723
1742 bool GetLineIntersection(float* X1, float* Y1, float* X2, float* Y2) const;
1743
1760 bool GetLineIntersection(FPoint* p1, FPoint* p2) const
1761 {
1762 return GetLineIntersection(p1 ? &p1->x : nullptr,
1763 p1 ? &p1->y : nullptr,
1764 p2 ? &p2->x : nullptr,
1765 p2 ? &p2->y : nullptr);
1766 }
1767
1785 constexpr bool Empty() const;
1786
1811 constexpr bool EqualEpsilon(const FRectRaw& other, const float epsilon) const;
1812
1836 constexpr bool Equal(const FRectRaw& other) const;
1837
1846 constexpr bool Contains(const FPointRaw& p) const
1847 {
1848 return SDL_PointInRectFloat(&p, this);
1849 }
1850
1859 constexpr bool Contains(const FRectRaw& other) const
1860 {
1861 return GetUnion(other) == *this;
1862 }
1863
1876 constexpr bool HasIntersection(const FRectRaw& other) const;
1877
1891 constexpr FRect GetIntersection(const FRectRaw& other) const;
1892
1902 constexpr FRect GetUnion(const FRectRaw& other) const;
1903
1912 constexpr FRect GetExtension(unsigned int amount) const
1913 {
1914 FRect r = *this;
1915 r.Extend(amount);
1916 return r;
1917 }
1918
1930 constexpr FRect GetExtension(float hAmount, float vAmount) const
1931 {
1932 FRect r = *this;
1933 r.Extend(hAmount, vAmount);
1934 return r;
1935 }
1936
1945 constexpr FRect& Extend(float amount) { return Extend(amount, amount); }
1946
1958 constexpr FRect& Extend(float hAmount, float vAmount)
1959 {
1960 x -= hAmount;
1961 y -= vAmount;
1962 w += hAmount * 2;
1963 h += vAmount * 2;
1964 return *this;
1965 }
1966
1975 constexpr FRect operator+(const FPoint& offset) const
1976 {
1977 return FRect(x + offset.x, y + offset.y, w, h);
1978 }
1979
1988 constexpr FRect operator-(const FPoint& offset) const
1989 {
1990 return FRect(x - offset.x, y - offset.y, w, h);
1991 }
1992
2001 constexpr FRect& operator+=(const FPoint& offset)
2002 {
2003 x += offset.x;
2004 y += offset.y;
2005 return *this;
2006 }
2007
2016 constexpr FRect& operator-=(const FPoint& offset)
2017 {
2018 x -= offset.x;
2019 y -= offset.y;
2020 return *this;
2021 }
2022};
2023
2034constexpr FRect RectToFRect(const RectRaw& rect)
2035{
2036 FRect frect;
2037 SDL_RectToFRect(&rect, &frect);
2038 return frect;
2039}
2040
2041constexpr Rect::operator SDL_FRect() const { return RectToFRect(*this); }
2042
2064constexpr bool PointInRect(const PointRaw& p, const RectRaw& r)
2065{
2066 return SDL_PointInRect(&p, &r);
2067}
2068
2069constexpr bool Point::InRect(const RectRaw& r) const
2070{
2071 return SDL::PointInRect(*this, r);
2072}
2073
2092constexpr bool RectEmpty(const RectRaw& r) { return SDL_RectEmpty(&r); }
2093
2094constexpr bool Rect::Empty() const { return SDL::RectEmpty(*this); }
2095
2115constexpr bool RectsEqual(const RectRaw& a, const RectRaw& b)
2116{
2117 return SDL_RectsEqual(&a, &b);
2118}
2119
2120constexpr bool Rect::Equal(const RectRaw& other) const
2121{
2122 return SDL::RectsEqual(*this, other);
2123}
2124
2140constexpr bool HasRectIntersection(const RectRaw& A, const RectRaw& B)
2141{
2142 return SDL_HasRectIntersection(&A, &B);
2143}
2144
2145constexpr bool Rect::HasIntersection(const RectRaw& other) const
2146{
2147 return SDL::HasRectIntersection(*this, other);
2148}
2149
2164constexpr Rect GetRectIntersection(const RectRaw& A, const RectRaw& B)
2165{
2166 if (Rect result; SDL_GetRectIntersection(&A, &B, &result)) return result;
2167 return {};
2168}
2169
2170constexpr Rect Rect::GetIntersection(const RectRaw& other) const
2171{
2172 return SDL::GetRectIntersection(*this, other);
2173}
2174
2185constexpr Rect GetRectUnion(const RectRaw& A, const RectRaw& B)
2186{
2187 Rect r;
2188 CheckError(SDL_GetRectUnion(&A, &B, &r));
2189 return r;
2190}
2191
2192constexpr Rect Rect::GetUnion(const RectRaw& other) const
2193{
2194 return SDL::GetRectUnion(*this, other);
2195}
2196
2213 OptionalRef<const RectRaw> clip = std::nullopt)
2214{
2215 if (Rect result;
2216 SDL_GetRectEnclosingPoints(points.data(), points.size(), clip, &result)) {
2217 return result;
2218 }
2219 return {};
2220}
2221
2224{
2225 return SDL::GetRectEnclosingPoints(points, clip);
2226}
2227
2246inline bool GetRectAndLineIntersection(const RectRaw& rect,
2247 int* X1,
2248 int* Y1,
2249 int* X2,
2250 int* Y2)
2251{
2252 return SDL_GetRectAndLineIntersection(&rect, X1, Y1, X2, Y2);
2253}
2254
2255inline bool Rect::GetLineIntersection(int* X1, int* Y1, int* X2, int* Y2) const
2256{
2257 return SDL::GetRectAndLineIntersection(*this, X1, Y1, X2, Y2);
2258}
2259
2281constexpr bool PointInRectFloat(const FPointRaw& p, const FRectRaw& r)
2282{
2283 return SDL_PointInRectFloat(&p, &r);
2284}
2285
2286constexpr bool FPoint::InRect(const FRectRaw& r) const
2287{
2288 return SDL::PointInRectFloat(*this, r);
2289}
2290
2309constexpr bool RectEmptyFloat(const FRectRaw& r)
2310{
2311 return SDL_RectEmptyFloat(&r);
2312}
2313
2314constexpr bool FRect::Empty() const { return SDL::RectEmptyFloat(*this); }
2315
2341constexpr bool RectsEqualEpsilon(const FRectRaw& a,
2342 const FRectRaw& b,
2343 const float epsilon)
2344{
2345 return SDL_RectsEqualEpsilon(&a, &b, epsilon);
2346}
2347
2348constexpr bool FRect::EqualEpsilon(const FRectRaw& other,
2349 const float epsilon) const
2350{
2351 return SDL::RectsEqualEpsilon(*this, other, epsilon);
2352}
2353
2379constexpr bool RectsEqualFloat(const FRectRaw& a, const FRectRaw& b)
2380{
2381 return SDL_RectsEqualFloat(&a, &b);
2382}
2383
2384constexpr bool FRect::Equal(const FRectRaw& other) const
2385{
2386 return SDL::RectsEqualFloat(*this, other);
2387}
2388
2402constexpr bool HasRectIntersectionFloat(const FRectRaw& A, const FRectRaw& B)
2403{
2404 return SDL_HasRectIntersectionFloat(&A, &B);
2405}
2406
2407constexpr bool FRect::HasIntersection(const FRectRaw& other) const
2408{
2409 return SDL::HasRectIntersectionFloat(*this, other);
2410}
2411
2427{
2428 if (FRect r; SDL_GetRectIntersectionFloat(&A, &B, &r)) return r;
2429 return {};
2430}
2431
2432constexpr FRect FRect::GetIntersection(const FRectRaw& other) const
2433{
2434 return SDL::GetRectIntersectionFloat(*this, other);
2435}
2436
2448constexpr FRect GetRectUnionFloat(const FRectRaw& A, const FRectRaw& B)
2449{
2450 FRect r;
2451 CheckError(SDL_GetRectUnionFloat(&A, &B, &r));
2452 return r;
2453}
2454
2455constexpr FRect FRect::GetUnion(const FRectRaw& other) const
2456{
2457 return SDL::GetRectUnionFloat(*this, other);
2458}
2459
2477 OptionalRef<const FRectRaw> clip = std::nullopt)
2478{
2479 if (FRect result; SDL_GetRectEnclosingPointsFloat(
2480 points.data(), points.size(), clip, &result)) {
2481 return result;
2482 }
2483 return {};
2484}
2485
2488{
2489 return SDL::GetRectEnclosingPointsFloat(points, clip);
2490}
2491
2512 float* X1,
2513 float* Y1,
2514 float* X2,
2515 float* Y2)
2516{
2517 return SDL_GetRectAndLineIntersectionFloat(&rect, X1, Y1, X2, Y2);
2518}
2519
2520inline bool FRect::GetLineIntersection(float* X1,
2521 float* Y1,
2522 float* X2,
2523 float* Y2) const
2524{
2525 return SDL::GetRectAndLineIntersectionFloat(*this, X1, Y1, X2, Y2);
2526}
2527
2529
2530constexpr Point::operator FPoint() const { return {float(x), float(y)}; }
2531
2532constexpr FPoint Point::operator/(float value) const
2533{
2534 return FPoint(*this) / value;
2535}
2536constexpr FPoint Point::operator*(float value) const
2537{
2538 return FPoint(*this) * value;
2539}
2540
2541constexpr Point Point::GetClamped(const Rect& rect) const
2542{
2543 Point p = *this;
2544 p.Clamp(rect);
2545 return p;
2546}
2547
2548constexpr Point& Point::Clamp(const Rect& rect)
2549{
2550 if (x < rect.x) x = rect.x;
2551 if (x > rect.GetX2()) x = rect.GetX2();
2552 if (y < rect.y) y = rect.y;
2553 if (y > rect.GetY2()) y = rect.GetY2();
2554 return *this;
2555}
2556
2557constexpr Point Point::GetWrapped(const Rect& rect) const
2558{
2559 Point p = *this;
2560 p.Wrap(rect);
2561 return p;
2562}
2563
2564constexpr Point& Point::Wrap(const Rect& rect)
2565{
2566 if (x < rect.x)
2567 x = rect.x + rect.w - 1 - (rect.x - x + rect.w - 1) % rect.w;
2568 else if (x >= rect.x + rect.w)
2569 x = rect.x + (x - rect.x - rect.w) % rect.w;
2570
2571 if (y < rect.y)
2572 y = rect.y + rect.h - 1 - (rect.y - y + rect.h - 1) % rect.h;
2573 else if (y >= rect.y + rect.h)
2574 y = rect.y + (y - rect.y - rect.h) % rect.h;
2575
2576 return *this;
2577}
2578
2579constexpr FPoint FPoint::GetClamped(const FRect& rect) const
2580{
2581 FPoint p = *this;
2582 p.Clamp(rect);
2583 return p;
2584}
2585
2586constexpr FPoint& FPoint::Clamp(const FRect& rect)
2587{
2588 if (x < rect.x) x = rect.x;
2589 if (x > rect.GetX2()) x = rect.GetX2();
2590 if (y < rect.y) y = rect.y;
2591 if (y > rect.GetY2()) y = rect.GetY2();
2592 return *this;
2593}
2594
2595constexpr FPoint FPoint::GetWrapped(const FRect& rect) const
2596{
2597 FPoint p = *this;
2598 p.Wrap(rect);
2599 return p;
2600}
2601
2602constexpr FPoint& FPoint::Wrap(const FRect& rect)
2603{
2604 if (x < rect.x)
2605 x = rect.x + rect.w - 1 - SDL_fmod(rect.x - x + rect.w - 1, rect.w);
2606 else if (x >= rect.x + rect.w)
2607 x = rect.x + SDL_fmod(x - rect.x - rect.w, rect.w);
2608
2609 if (y < rect.y)
2610 y = rect.y + rect.h - 1 - SDL_fmod(rect.y - y + rect.h - 1, rect.h);
2611 else if (y >= rect.y + rect.h)
2612 y = rect.y + SDL_fmod(y - rect.y - rect.h, rect.h);
2613
2614 return *this;
2615}
2616
2617constexpr Rect::operator FRect() const
2618{
2619 return {float(x), float(y), float(w), float(h)};
2620}
2621
2622} // namespace SDL
2623
2624#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:198
constexpr bool operator==(ColorRaw lhs, ColorRaw rhs)
Comparison operator for Color.
Definition: SDL3pp_pixels.h:2148
constexpr bool RectEmptyFloat(const FRectRaw &r)
Determine whether a floating point rectangle can contain any point.
Definition: SDL3pp_rect.h:2309
constexpr FRect GetRectUnionFloat(const FRectRaw &A, const FRectRaw &B)
Calculate the union of two rectangles with float precision.
Definition: SDL3pp_rect.h:2448
constexpr bool InRect(const RectRaw &r) const
Determine whether a point resides inside a rectangle.
Definition: SDL3pp_rect.h:2069
constexpr bool HasRectIntersectionFloat(const FRectRaw &A, const FRectRaw &B)
Determine whether two rectangles intersect with float precision.
Definition: SDL3pp_rect.h:2402
constexpr FRect GetRectIntersectionFloat(const FRectRaw &A, const FRectRaw &B)
Calculate the intersection of two rectangles with float precision.
Definition: SDL3pp_rect.h:2426
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:2520
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:2211
constexpr FRect GetIntersection(const FRectRaw &other) const
Calculate the intersection of two rectangles with float precision.
Definition: SDL3pp_rect.h:2432
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:2348
constexpr bool InRect(const FRectRaw &r) const
Determine whether a point resides inside a floating point rectangle.
Definition: SDL3pp_rect.h:2286
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:2511
constexpr bool PointInRectFloat(const FPointRaw &p, const FRectRaw &r)
Determine whether a point resides inside a floating point rectangle.
Definition: SDL3pp_rect.h:2281
constexpr bool Equal(const FRectRaw &other) const
Determine whether two rectangles are equal.
Definition: SDL3pp_rect.h:2384
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:2094
constexpr bool Equal(const RectRaw &other) const
Determine whether two rectangles are equal.
Definition: SDL3pp_rect.h:2120
constexpr bool RectsEqual(const RectRaw &a, const RectRaw &b)
Determine whether two rectangles are equal.
Definition: SDL3pp_rect.h:2115
constexpr bool Empty() const
Determine whether a rectangle has no area.
Definition: SDL3pp_rect.h:2314
constexpr bool RectEmpty(const RectRaw &r)
Determine whether a rectangle has no area.
Definition: SDL3pp_rect.h:2092
constexpr Rect GetUnion(const RectRaw &other) const
Calculate the union of two rectangles.
Definition: SDL3pp_rect.h:2192
constexpr bool PointInRect(const PointRaw &p, const RectRaw &r)
Determine whether a point resides inside a rectangle.
Definition: SDL3pp_rect.h:2064
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:2486
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:2222
constexpr Rect GetRectUnion(const RectRaw &A, const RectRaw &B)
Calculate the union of two rectangles.
Definition: SDL3pp_rect.h:2185
constexpr FRect RectToFRect(const RectRaw &rect)
Convert an Rect to FRect.
Definition: SDL3pp_rect.h:2034
constexpr Rect GetRectIntersection(const RectRaw &A, const RectRaw &B)
Calculate the intersection of two rectangles.
Definition: SDL3pp_rect.h:2164
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:2246
constexpr FRect GetUnion(const FRectRaw &other) const
Calculate the union of two rectangles with float precision.
Definition: SDL3pp_rect.h:2455
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:2379
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:2341
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:2145
constexpr bool HasIntersection(const FRectRaw &other) const
Determine whether two rectangles intersect.
Definition: SDL3pp_rect.h:2407
constexpr Rect GetIntersection(const RectRaw &other) const
Calculate the intersection of two rectangles.
Definition: SDL3pp_rect.h:2170
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:2475
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:2140
Main include header for the SDL3pp library.
The structure that defines a point (using floating point values).
Definition: SDL3pp_rect.h:509
constexpr FPoint operator/(const FPoint &other) const
Get point's memberwise division by another point.
Definition: SDL3pp_rect.h:655
constexpr FPoint(float x, float y)
Constructs from its fields.
Definition: SDL3pp_rect.h:526
constexpr FPoint & Wrap(const FRect &rect)
Wrap point coordinates within a specified rect.
Definition: SDL3pp_rect.h:2602
constexpr float GetX() const
Get the x coordinate.
Definition: SDL3pp_rect.h:543
constexpr float GetY() const
Get the y coordinate.
Definition: SDL3pp_rect.h:562
constexpr FPoint operator-() const
Get point's memberwise negation.
Definition: SDL3pp_rect.h:604
constexpr FPoint & operator/=(const FPoint &other)
Memberwise divide by another point.
Definition: SDL3pp_rect.h:743
constexpr FPoint operator/(float value) const
Get point's memberwise division by an float.
Definition: SDL3pp_rect.h:641
constexpr FPoint(const FPointRaw &p={})
Wraps FPoint.
Definition: SDL3pp_rect.h:515
constexpr FPoint operator-(const FPoint &other) const
Get point's memberwise subtraction with another point.
Definition: SDL3pp_rect.h:627
constexpr FPoint operator*(float value) const
Get point's memberwise multiplication by an float.
Definition: SDL3pp_rect.h:670
constexpr FPoint & operator/=(float value)
Memberwise divide by an float.
Definition: SDL3pp_rect.h:728
constexpr FPoint & SetX(float newX)
Set the x coordinate.
Definition: SDL3pp_rect.h:551
constexpr FPoint GetClamped(const FRect &rect) const
Get a point with coordinates modified so it fits into a given rect.
Definition: SDL3pp_rect.h:2579
constexpr FPoint & operator*=(const FPoint &other)
Memberwise multiply by another point.
Definition: SDL3pp_rect.h:773
constexpr FPoint GetWrapped(const FRect &rect) const
Get a point wrapped within a specified rect.
Definition: SDL3pp_rect.h:2595
constexpr FPoint operator+(const FPoint &other) const
Get point's memberwise addition with another point.
Definition: SDL3pp_rect.h:614
constexpr FPoint & SetY(float newY)
Set the y coordinate.
Definition: SDL3pp_rect.h:570
constexpr FPoint & Clamp(const FRect &rect)
Clamp point coordinates to make it fit into a given rect.
Definition: SDL3pp_rect.h:2586
constexpr FPoint & operator*=(float value)
Memberwise multiply by an float.
Definition: SDL3pp_rect.h:758
constexpr FPoint & operator-=(const FPoint &other)
Memberwise subtract another point.
Definition: SDL3pp_rect.h:713
constexpr FPoint operator*(const FPoint &other) const
Get point's memberwise multiplication by another point.
Definition: SDL3pp_rect.h:685
constexpr FPoint & operator+=(const FPoint &other)
Memberwise add another point.
Definition: SDL3pp_rect.h:698
A rectangle, with the origin at the upper left (using floating point values).
Definition: SDL3pp_rect.h:1432
constexpr bool operator==(const FRectRaw &other) const
Compares with the underlying type.
Definition: SDL3pp_rect.h:1465
constexpr float GetH() const
Get height of the rect.
Definition: SDL3pp_rect.h:1541
constexpr FRect(FPoint corner, FPoint size)
Constructs from top-left corner plus size.
Definition: SDL3pp_rect.h:1459
constexpr FRect & Extend(float hAmount, float vAmount)
Extend a rect by specified amount of pixels.
Definition: SDL3pp_rect.h:1958
constexpr FRect & SetH(float newH)
Set the height of the rect.
Definition: SDL3pp_rect.h:1549
constexpr FRect & SetW(float newW)
Set the width of the rect.
Definition: SDL3pp_rect.h:1530
constexpr float GetY() const
Get top y coordinate.
Definition: SDL3pp_rect.h:1503
constexpr FRect operator+(const FPoint &offset) const
Get rectangle moved by a given offset.
Definition: SDL3pp_rect.h:1975
static constexpr FRect FromCorners(FPoint p1, FPoint p2)
Construct the rect from given centers coordinates.
Definition: SDL3pp_rect.h:1623
constexpr bool operator==(const FRect &other) const
Compares with the underlying type.
Definition: SDL3pp_rect.h:1471
constexpr FPoint GetTopRight() const
Get top right corner of the rect.
Definition: SDL3pp_rect.h:1690
constexpr FRect operator-(const FPoint &offset) const
Get rectangle moved by an opposite of given offset.
Definition: SDL3pp_rect.h:1988
constexpr float GetW() const
Get width of the rect.
Definition: SDL3pp_rect.h:1522
constexpr bool Contains(const FRectRaw &other) const
Check whether the rect contains given point.
Definition: SDL3pp_rect.h:1859
constexpr FRect & operator+=(const FPoint &offset)
Move by then given offset.
Definition: SDL3pp_rect.h:2001
static constexpr FRect FromCenter(FPoint center, FPoint size)
Construct the rect from given center coordinates and size.
Definition: SDL3pp_rect.h:1597
constexpr FRect & operator-=(const FPoint &offset)
Move by an opposite of the given offset.
Definition: SDL3pp_rect.h:2016
constexpr FPoint GetBottomRight() const
Get bottom right corner of the rect.
Definition: SDL3pp_rect.h:1706
constexpr FPoint GetBottomLeft() const
Get bottom left corner of the rect.
Definition: SDL3pp_rect.h:1698
constexpr float GetX2() const
Get X coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1634
constexpr FRect GetExtension(unsigned int amount) const
Get a rect extended by specified amount of pixels.
Definition: SDL3pp_rect.h:1912
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:1585
constexpr float GetY2() const
Get Y coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1658
constexpr FRect & SetY2(float y2)
Set Y coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1670
constexpr FRect(const FRectRaw &r={})
Wraps FRect.
Definition: SDL3pp_rect.h:1438
constexpr FRect & SetY(float newY)
Set the top y coordinate.
Definition: SDL3pp_rect.h:1511
constexpr FRect & SetX2(float x2)
Set X coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1646
static constexpr FRect FromCorners(float x1, float y1, float x2, float y2)
Construct the rect from given corners coordinates.
Definition: SDL3pp_rect.h:1611
constexpr bool Contains(const FPointRaw &p) const
Check whether the rect contains given point.
Definition: SDL3pp_rect.h:1846
constexpr FRect & SetX(float newX)
Set the left x coordinate.
Definition: SDL3pp_rect.h:1492
constexpr FRect & Extend(float amount)
Extend a rect by specified amount of pixels.
Definition: SDL3pp_rect.h:1945
constexpr FRect GetExtension(float hAmount, float vAmount) const
Get a rect extended by specified amount of pixels.
Definition: SDL3pp_rect.h:1930
constexpr FPoint GetCentroid() const
Get centroid of the rect.
Definition: SDL3pp_rect.h:1722
constexpr FRect(float x, float y, float w, float h)
Constructs from its fields.
Definition: SDL3pp_rect.h:1451
bool GetLineIntersection(FPoint *p1, FPoint *p2) const
Calculate the intersection of a rectangle and line segment.
Definition: SDL3pp_rect.h:1760
constexpr FPoint GetTopLeft() const
Get top left corner of the rect.
Definition: SDL3pp_rect.h:1682
constexpr FPoint GetSize() const
Get size of the rect.
Definition: SDL3pp_rect.h:1714
constexpr float GetX() const
Get left x coordinate.
Definition: SDL3pp_rect.h:1484
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:365
constexpr Point & operator%=(const Point &other)
Memberwise remainder from division by another point.
Definition: SDL3pp_rect.h:411
constexpr Point operator/(int value) const
Get point's memberwise division by an integer.
Definition: SDL3pp_rect.h:225
constexpr Point GetClamped(const Rect &rect) const
Get a point with coordinates modified so it fits into a given rect.
Definition: SDL3pp_rect.h:2541
constexpr Point operator-(const Point &other) const
Get point's memberwise subtraction with another point.
Definition: SDL3pp_rect.h:211
constexpr int GetX() const
Get x coordinate.
Definition: SDL3pp_rect.h:127
constexpr Point operator+(const Point &other) const
Get point's memberwise addition with another point.
Definition: SDL3pp_rect.h:198
constexpr Point & Clamp(const Rect &rect)
Clamp point coordinates to make it fit into a given rect.
Definition: SDL3pp_rect.h:2548
constexpr Point operator*(const Point &other) const
Get point's memberwise multiplication by another point.
Definition: SDL3pp_rect.h:322
constexpr Point operator%(int value) const
Get point's memberwise remainder from division by an integer.
Definition: SDL3pp_rect.h:265
constexpr Point & operator*=(const Point &other)
Memberwise multiply by another point.
Definition: SDL3pp_rect.h:441
constexpr Point & SetX(int newX)
Set the x coordinate.
Definition: SDL3pp_rect.h:135
constexpr Point & operator-=(const Point &other)
Memberwise subtract another point.
Definition: SDL3pp_rect.h:350
constexpr Point(const PointRaw &p={})
Wraps Point.
Definition: SDL3pp_rect.h:89
constexpr Point operator*(int value) const
Get point's memberwise multiplication by an integer.
Definition: SDL3pp_rect.h:295
constexpr Point & operator/=(const Point &other)
Memberwise divide by another point.
Definition: SDL3pp_rect.h:380
constexpr Point operator%(const Point &other) const
Get point's memberwise remainder from division by another point.
Definition: SDL3pp_rect.h:280
constexpr Point GetWrapped(const Rect &rect) const
Get a point wrapped within a specified rect.
Definition: SDL3pp_rect.h:2557
constexpr Point(int x, int y)
Constructs from its fields.
Definition: SDL3pp_rect.h:100
constexpr Point & Wrap(const Rect &rect)
Wrap point coordinates within a specified rect.
Definition: SDL3pp_rect.h:2564
constexpr int GetY() const
Get y coordinate.
Definition: SDL3pp_rect.h:146
constexpr Point & SetY(int newY)
Set the y coordinate.
Definition: SDL3pp_rect.h:154
constexpr Point & operator%=(int value)
Memberwise remainder from division by an integer.
Definition: SDL3pp_rect.h:395
constexpr Point operator/(const Point &other) const
Get point's memberwise division by another point.
Definition: SDL3pp_rect.h:250
constexpr Point & operator+=(const Point &other)
Memberwise add another point.
Definition: SDL3pp_rect.h:335
constexpr Point operator-() const
Get point's memberwise negation.
Definition: SDL3pp_rect.h:188
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:426
A rectangle, with the origin at the upper left (using integers).
Definition: SDL3pp_rect.h:839
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:991
constexpr int GetX() const
Get left x coordinate.
Definition: SDL3pp_rect.h:891
constexpr Rect(const PointRaw &corner, const PointRaw &size)
Construct from offset and size.
Definition: SDL3pp_rect.h:869
constexpr Rect & operator-=(const Point &offset)
Move by an opposite of the given offset.
Definition: SDL3pp_rect.h:1405
constexpr bool Contains(const PointRaw &p) const
Check whether the rect contains given point.
Definition: SDL3pp_rect.h:1235
bool GetLineIntersection(PointRaw *p1, PointRaw *p2) const
Calculate the intersection of a rectangle and line segment.
Definition: SDL3pp_rect.h:1146
constexpr int GetW() const
Get width of the rect.
Definition: SDL3pp_rect.h:929
constexpr Rect GetExtension(unsigned int hAmount, unsigned int vAmount) const
Get a rect extended by specified amount of pixels.
Definition: SDL3pp_rect.h:1319
constexpr Rect(const RectRaw &r={})
Wraps Rect.
Definition: SDL3pp_rect.h:845
constexpr Rect(int x, int y, int w, int h)
Constructs from its fields.
Definition: SDL3pp_rect.h:858
constexpr Rect & SetY(int newY)
Set the top y coordinate.
Definition: SDL3pp_rect.h:918
constexpr Point GetTopLeft() const
Get top left corner of the rect.
Definition: SDL3pp_rect.h:1088
constexpr Rect & Extend(unsigned int hAmount, unsigned int vAmount)
Extend a rect by specified amount of pixels.
Definition: SDL3pp_rect.h:1347
constexpr Rect operator+(const Point &offset) const
Get rectangle moved by a given offset.
Definition: SDL3pp_rect.h:1364
constexpr Rect & operator+=(const Point &offset)
Move by then given offset.
Definition: SDL3pp_rect.h:1390
constexpr bool operator==(const Rect &other) const
Compares with the underlying type.
Definition: SDL3pp_rect.h:878
constexpr Rect GetExtension(unsigned int amount) const
Get a rect extended by specified amount of pixels.
Definition: SDL3pp_rect.h:1301
constexpr Rect & Extend(unsigned int amount)
Extend a rect by specified amount of pixels.
Definition: SDL3pp_rect.h:1334
constexpr Rect & SetW(int newW)
Set the width of the rect.
Definition: SDL3pp_rect.h:937
constexpr Point GetCentroid() const
Get centroid of the rect.
Definition: SDL3pp_rect.h:1128
constexpr Point GetBottomLeft() const
Get bottom left corner of the rect.
Definition: SDL3pp_rect.h:1104
constexpr int GetH() const
Get height of the rect.
Definition: SDL3pp_rect.h:948
constexpr Rect & SetX2(int x2)
Set X coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1052
constexpr Rect & SetH(int newH)
Set the height of the rect.
Definition: SDL3pp_rect.h:956
static constexpr Rect FromCorners(Point p1, Point p2)
Construct the rect from given centers coordinates.
Definition: SDL3pp_rect.h:1029
static constexpr Rect FromCorners(int x1, int y1, int x2, int y2)
Construct the rect from given corners coordinates.
Definition: SDL3pp_rect.h:1017
constexpr Point GetSize() const
Get size of the rect.
Definition: SDL3pp_rect.h:1120
constexpr Rect operator-(const Point &offset) const
Get rectangle moved by an opposite of given offset.
Definition: SDL3pp_rect.h:1377
constexpr Point GetBottomRight() const
Get bottom right corner of the rect.
Definition: SDL3pp_rect.h:1112
constexpr int GetY2() const
Get Y coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1064
static constexpr Rect FromCenter(Point center, Point size)
Construct the rect from given center coordinates and size.
Definition: SDL3pp_rect.h:1003
constexpr bool operator==(const RectRaw &other) const
Compares with the underlying type.
Definition: SDL3pp_rect.h:875
constexpr int GetY() const
Get top y coordinate.
Definition: SDL3pp_rect.h:910
constexpr Rect & SetX(int newX)
Set the left x coordinate.
Definition: SDL3pp_rect.h:899
constexpr Rect & SetY2(int y2)
Set Y coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1076
constexpr Point GetTopRight() const
Get top right corner of the rect.
Definition: SDL3pp_rect.h:1096
constexpr bool Contains(const RectRaw &other) const
Check whether the rect contains given point.
Definition: SDL3pp_rect.h:1248
constexpr int GetX2() const
Get X coordinate of the rect second corner.
Definition: SDL3pp_rect.h:1040