UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
IntRect.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "Math/MathFwd.h" // IWYU pragma: export
9#include "Math/IntPoint.h"
10#include "Math/Vector2D.h"
11
12namespace UE::Math
13{
14
22template <typename InIntType>
24{
27 static_assert(std::is_integral_v<IntType>, "Only an integer types are supported.");
28
29 union
30 {
31 struct
32 {
35
38 };
39
40 UE_DEPRECATED(all, "For internal use only")
42 };
43
46 : Min(ForceInit)
47 , Max(ForceInit)
48 {}
49
61 : Min(X0, Y0)
62 , Max(X1, Y1)
63 {
64 }
65
77
79 {
80 *this = Other;
81 }
82
84 {
85 Min = Other.Min;
86 Max = Other.Max;
87 return *this;
88 }
89
93 template <typename OtherIntType>
99
112
125
132 [[nodiscard]] bool operator==(const TIntRect& Other) const
133 {
134 return Min == Other.Min && Max == Other.Max;
135 }
136
143 [[nodiscard]] bool operator!=(const TIntRect& Other) const
144 {
145 return Min != Other.Min || Max != Other.Max;
146 }
147
155 {
156 Min *= Scale;
157 Max *= Scale;
158
159 return *this;
160 }
161
169 {
170 Min += Point;
171 Max += Point;
172
173 return *this;
174 }
175
183 {
184 Min -= Point;
185 Max -= Point;
186
187 return *this;
188 }
189
197 {
198 return TIntRect(Min * Scale, Max * Scale);
199 }
200
208 {
209 return TIntRect(Min / Div, Max / Div);
210 }
211
219 {
220 return TIntRect(Min + Point, Max + Point);
221 }
222
230 {
231 return TIntRect(Min / Point, Max / Point);
232 }
233
241 {
242 return TIntRect(Min - Point, Max - Point);
243 }
244
252 {
253 return TIntRect(Min + Other.Min, Max + Other.Max);
254 }
255
263 {
264 return TIntRect(Min - Other.Min, Max - Other.Max);
265 }
266
273 {
274 return (Max.X - Min.X) * (Max.Y - Min.Y);
275 }
276
285 {
286 return TIntRect(Min.X, FMath::Max(Min.Y, Max.Y - InHeight), Max.X, Max.Y);
287 }
288
294 void Clip(const TIntRect& R)
295 {
296 Min.X = FMath::Max<IntType>(Min.X, R.Min.X);
297 Min.Y = FMath::Max<IntType>(Min.Y, R.Min.Y);
298 Max.X = FMath::Min<IntType>(Max.X, R.Max.X);
299 Max.Y = FMath::Min<IntType>(Max.Y, R.Max.Y);
300
301 // return zero area if not overlapping
302 Max.X = FMath::Max<IntType>(Min.X, Max.X);
303 Max.Y = FMath::Max<IntType>(Min.Y, Max.Y);
304 }
305
307 void Union(const TIntRect& R)
308 {
309 Min.X = FMath::Min<IntType>(Min.X, R.Min.X);
310 Min.Y = FMath::Min<IntType>(Min.Y, R.Min.Y);
311 Max.X = FMath::Max<IntType>(Max.X, R.Max.X);
312 Max.Y = FMath::Max<IntType>(Max.Y, R.Max.Y);
313 }
314
324 [[nodiscard]] bool Intersect(const TIntRect& Other) const
325 {
326 return Other.Min.X < Max.X && Other.Max.X > Min.X && Other.Min.Y < Max.Y && Other.Max.Y > Min.Y;
327 }
328
339 {
340 return P.X >= Min.X && P.X < Max.X&& P.Y >= Min.Y && P.Y < Max.Y;
341 }
342
346 [[nodiscard]] bool Contains(const FIntRect& Other) const
347 {
348 return Other.Min.X >= Min.X && Other.Max.X <= Max.X &&
349 Other.Min.Y >= Min.Y && Other.Max.Y <= Max.Y;
350 }
351
359 {
360 OutExtent.X = (Max.X - Min.X) / 2;
361 OutExtent.Y = (Max.Y - Min.Y) / 2;
362
363 OutCenter.X = Min.X + OutExtent.X;
364 OutCenter.Y = Min.Y + OutExtent.Y;
365 }
366
373 {
374 return (Max.Y - Min.Y);
375 }
376
377
383 void InflateRect(IntType Amount)
384 {
385 Min.X -= Amount;
386 Min.Y -= Amount;
387 Max.X += Amount;
388 Max.Y += Amount;
389 }
396 {
397 Min.X = FMath::Min(Min.X, Point.X);
398 Min.Y = FMath::Min(Min.Y, Point.Y);
399 Max.X = FMath::Max(Max.X, Point.X);
400 Max.Y = FMath::Max(Max.Y, Point.Y);
401 }
402
410 {
411 return TIntRect(Min + Shrink, Max - Shrink);
412 }
420 {
421 return TIntRect(FMath::Max(Min.X, Max.X - InWidth), Min.Y, Max.X, Max.Y);
422 }
423
430 [[nodiscard]] TIntRect Scale(double Fraction) const
431 {
433 const Vec2D Min2D = Vec2D((double)Min.X, (double)Min.Y) * Fraction;
434 const Vec2D Max2D = Vec2D((double)Max.X, (double)Max.Y) * Fraction;
435
436 return TIntRect(
437 IntCastChecked<IntType>(FMath::FloorToInt64(Min2D.X)),
438 IntCastChecked<IntType>(FMath::FloorToInt64(Min2D.Y)),
439 IntCastChecked<IntType>(FMath::CeilToInt64(Max2D.X)),
440 IntCastChecked<IntType>(FMath::CeilToInt64(Max2D.Y))
441 );
442 }
443
450 {
451 return IntPointType(Max.X - Min.X, Max.Y - Min.Y);
452 }
453
459 [[nodiscard]] FString ToString() const
460 {
461 return FString::Printf(TEXT("Min=(%s) Max=(%s)"), *Min.ToString(), *Max.ToString());
462 }
463
470 {
471 return Max.X - Min.X;
472 }
473
479 [[nodiscard]] bool IsEmpty() const
480 {
481 return Width() == 0 && Height() == 0;
482 }
483
492 {
493 return DivideAndRoundUp(lhs, IntPointType(Div, Div));
494 }
495
497 {
498 return TIntRect(lhs.Min / Div, IntPointType::DivideAndRoundUp(lhs.Max, Div));
499 }
500
506 [[nodiscard]] static constexpr int32 Num()
507 {
508 return 2;
509 }
510
511public:
512
521 {
522 return Ar << Rect.Min.X << Rect.Min.Y << Rect.Max.X << Rect.Max.Y;
523 }
524};
525
526template <typename IntType>
531
532}
533
534template <> struct TIsPODType<FInt32Rect> { enum { Value = true }; };
535template <> struct TIsPODType<FUint32Rect> { enum { Value = true }; };
536
537template <> struct TIsUECoreVariant<FInt32Rect> { enum { Value = true }; };
538template <> struct TIsUECoreVariant<FUint32Rect> { enum { Value = true }; };
539
540template <> struct TIsPODType<FInt64Rect> { enum { Value = true }; };
541template <> struct TIsPODType<FUint64Rect> { enum { Value = true }; };
542
543template <> struct TIsUECoreVariant<FInt64Rect> { enum { Value = true }; };
544template <> struct TIsUECoreVariant<FUint64Rect> { enum { Value = true }; };
@ ForceInit
Definition CoreMiscDefines.h:155
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define PRAGMA_ENABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:12
#define PRAGMA_DISABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:8
constexpr uint32 HashCombine(uint32 A, uint32 C)
Definition TypeHash.h:36
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
Definition Sphere.cpp:10
uint32 GetTypeHash(const TBox< T > &Box)
Definition Box.h:1008
Definition LinuxPlatformSplash.cpp:43
Definition IsPODType.h:12
Definition IsUECoreType.h:19
IntType Y
Definition IntPoint.h:37
static TIntPoint DivideAndRoundUp(TIntPoint lhs, IntType Divisor)
Definition IntPoint.h:429
FString ToString() const
Definition IntPoint.h:399
IntType X
Definition IntPoint.h:34
Definition IntRect.h:24
TIntPoint< IntType > IntPointType
Definition IntRect.h:26
const TIntRect & operator()(int32 PointIndex) const
Definition IntRect.h:106
TIntRect operator-(const IntPointType &Point) const
Definition IntRect.h:240
TIntRect Right(IntType InWidth) const
Definition IntRect.h:419
void GetCenterAndExtents(IntPointType &OutCenter, IntPointType &OutExtent) const
Definition IntRect.h:358
static constexpr int32 Num()
Definition IntRect.h:506
TIntRect & operator()(int32 PointIndex)
Definition IntRect.h:119
void Include(IntPointType Point)
Definition IntRect.h:395
IntType Width() const
Definition IntRect.h:469
static TIntRect DivideAndRoundUp(TIntRect lhs, IntType Div)
Definition IntRect.h:491
TIntRect(IntPointType InMin, IntPointType InMax)
Definition IntRect.h:72
TIntRect Inner(IntPointType Shrink) const
Definition IntRect.h:409
void InflateRect(IntType Amount)
Definition IntRect.h:383
bool Contains(const FIntRect &Other) const
Definition IntRect.h:346
TIntRect & operator*=(IntType Scale)
Definition IntRect.h:154
TIntRect operator+(const TIntRect &Other) const
Definition IntRect.h:251
static TIntRect DivideAndRoundUp(TIntRect lhs, IntPointType Div)
Definition IntRect.h:496
bool IsEmpty() const
Definition IntRect.h:479
friend FArchive & operator<<(FArchive &Ar, TIntRect &Rect)
Definition IntRect.h:520
IntType Height() const
Definition IntRect.h:372
TIntRect & operator=(const TIntRect &Other)
Definition IntRect.h:83
TIntRect & operator-=(const IntPointType &Point)
Definition IntRect.h:182
void Union(const TIntRect &R)
Definition IntRect.h:307
bool Intersect(const TIntRect &Other) const
Definition IntRect.h:324
InIntType IntType
Definition IntRect.h:25
TIntRect operator/(const IntPointType &Point) const
Definition IntRect.h:229
bool Contains(IntPointType P) const
Definition IntRect.h:338
IntPointType Max
Definition IntRect.h:37
IntPointType Min
Definition IntRect.h:34
TIntRect operator+(const IntPointType &Point) const
Definition IntRect.h:218
TIntRect(TIntRect< OtherIntType > Other)
Definition IntRect.h:94
TIntRect(const TIntRect &Other)
Definition IntRect.h:78
TIntRect operator-(const TIntRect &Other) const
Definition IntRect.h:262
TIntRect & operator+=(const IntPointType &Point)
Definition IntRect.h:168
TIntRect operator*(IntType Scale) const
Definition IntRect.h:196
TIntRect Bottom(IntType InHeight) const
Definition IntRect.h:284
TIntRect Scale(double Fraction) const
Definition IntRect.h:430
void Clip(const TIntRect &R)
Definition IntRect.h:294
bool operator==(const TIntRect &Other) const
Definition IntRect.h:132
IntType Area() const
Definition IntRect.h:272
IntPointType Size() const
Definition IntRect.h:449
TIntRect operator/(IntType Div) const
Definition IntRect.h:207
TIntRect()
Definition IntRect.h:45
FString ToString() const
Definition IntRect.h:459
bool operator!=(const TIntRect &Other) const
Definition IntRect.h:143
TIntRect(IntType X0, IntType Y0, IntType X1, IntType Y1)
Definition IntRect.h:60
IntPointType MinMax[2]
Definition IntRect.h:41
Definition Vector2D.h:38