UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
IntPoint.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"
7#include "Misc/Parse.h"
8#include "Math/MathFwd.h" // IWYU pragma: export
12#include "Templates/TypeHash.h"
14
15namespace UE::Math
16{
17
23template <typename InIntType>
25{
27 static_assert(std::is_integral_v<IntType>, "An integer type is required.");
28
29 union
30 {
31 struct
32 {
35
38 };
39
40 UE_DEPRECATED(all, "For internal use only")
42 };
43
46
49
51 [[nodiscard]] TIntPoint() = default;
52
60 : X(InX)
61 , Y(InY)
62 {
63 }
64
72 : X(InXY)
73 , Y(InXY)
74 {
75 }
76
83 : X(0)
84 , Y(0)
85 {
86 }
87
91 template <typename OtherIntType>
97
98 // Workaround for clang deprecation warnings for deprecated XY member in implicitly-defined special member functions
100 TIntPoint(TIntPoint&&) = default;
101 TIntPoint(const TIntPoint&) = default;
103 TIntPoint& operator=(const TIntPoint&) = default;
105
118
131
138 [[nodiscard]] bool operator==(const TIntPoint& Other) const
139 {
140 return X == Other.X && Y == Other.Y;
141 }
142
149 [[nodiscard]] bool operator!=(const TIntPoint& Other) const
150 {
151 return (X != Other.X) || (Y != Other.Y);
152 }
153
161 {
162 X *= Scale;
163 Y *= Scale;
164
165 return *this;
166 }
167
175 {
176 X /= Divisor;
177 Y /= Divisor;
178
179 return *this;
180 }
181
189 {
190 X += Other.X;
191 Y += Other.Y;
192
193 return *this;
194 }
195
203 {
204 X *= Other.X;
205 Y *= Other.Y;
206
207 return *this;
208 }
209
217 {
218 X -= Other.X;
219 Y -= Other.Y;
220
221 return *this;
222 }
223
231 {
232 X /= Other.X;
233 Y /= Other.Y;
234
235 return *this;
236 }
237
245 {
246 return TIntPoint(*this) *= Scale;
247 }
248
256 {
257 return TIntPoint(*this) /= Divisor;
258 }
259
267 {
268 return TIntPoint(*this) += Other;
269 }
270
278 {
279 return TIntPoint(*this) -= Other;
280 }
281
289 {
290 return TIntPoint(*this) *= Other;
291 }
292
300 {
301 return TIntPoint(*this) /= Other;
302 }
303
311 {
312 check(Index >= 0 && Index < 2);
313 return ((Index == 0) ? X : Y);
314 }
315
323 {
324 check(Index >= 0 && Index < 2);
325 return ((Index == 0) ? X : Y);
326 }
327
334 {
335 return TIntPoint(FMath::Min(X, Other.X), FMath::Min(Y, Other.Y));
336 }
337
344 {
345 return TIntPoint(FMath::Max(X, Other.X), FMath::Max(Y, Other.Y));
346 }
347
355 {
356 return FMath::Max(X, Y);
357 }
358
366 {
367 return FMath::Min(X, Y);
368 }
369
377 {
380 return IntType(FMath::Sqrt(double(LocalX64 * LocalX64 + LocalY64 * LocalY64)));
381 }
382
390 {
391 return X * X + Y * Y;
392 }
393
399 [[nodiscard]] FString ToString() const
400 {
401 return FString::Printf(TEXT("X=%s Y=%s"), *LexToString(X), *LexToString(Y));
402 }
403
411 bool InitFromString(const FString& InSourceString)
412 {
413 X = Y = 0;
414
415 // The initialization is only successful if the X and Y values can all be parsed from the string
416 const bool bSuccessful = FParse::Value(*InSourceString, TEXT("X="), X) && FParse::Value(*InSourceString, TEXT("Y="), Y);
417
418 return bSuccessful;
419 }
420
430 {
431 return TIntPoint(FMath::DivideAndRoundUp(lhs.X, Divisor), FMath::DivideAndRoundUp(lhs.Y, Divisor));
432 }
433
435 {
436 return TIntPoint(FMath::DivideAndRoundUp(lhs.X, Divisor.X), FMath::DivideAndRoundUp(lhs.Y, Divisor.Y));
437 }
438
448 {
450 }
451
456
462 [[nodiscard]] static int32 Num()
463 {
464 return 2;
465 }
466
475 {
476 return Ar << Point.X << Point.Y;
477 }
478
490
498 {
499 Ar << *this;
500 return true;
501 }
502
504 {
505 if constexpr (std::is_same_v<IntType, int32>)
506 {
508 }
509 else if constexpr (std::is_same_v<IntType, int64>)
510 {
512 }
513 else if constexpr (std::is_same_v<IntType, uint32>)
514 {
516 }
517 else if constexpr (std::is_same_v<IntType, uint64>)
518 {
520 }
521 else
522 {
523 static_assert(sizeof(IntType) == 0, "Unimplemented");
524 return false;
525 }
526 }
527};
528
529template <typename IntType>
530const TIntPoint<IntType> TIntPoint<IntType>::ZeroValue(0, 0);
531
532template <typename IntType>
533const TIntPoint<IntType> TIntPoint<IntType>::NoneValue(static_cast<IntType>(INDEX_NONE), static_cast<IntType>(INDEX_NONE));
534
535template <typename IntType>
540
541template <>
542inline FString TIntPoint<int64>::ToString() const
543{
544 return FString::Printf(TEXT("X=%lld Y=%lld"), X, Y);
545}
546
547template <>
548inline FString TIntPoint<int32>::ToString() const
549{
550 return FString::Printf(TEXT("X=%d Y=%d"), X, Y);
551}
552
553template <>
554inline FString TIntPoint<int16>::ToString() const
555{
556 return FString::Printf(TEXT("X=%d Y=%d"), X, Y);
557}
558
559template <>
560inline FString TIntPoint<int8>::ToString() const
561{
562 return FString::Printf(TEXT("X=%d Y=%d"), X, Y);
563}
564
565template <>
566inline FString TIntPoint<uint64>::ToString() const
567{
568 return FString::Printf(TEXT("X=%llu Y=%llu"), X, Y);
569}
570
571template <>
572inline FString TIntPoint<uint32>::ToString() const
573{
574 return FString::Printf(TEXT("X=%u Y=%u"), X, Y);
575}
576
577template <>
578inline FString TIntPoint<uint16>::ToString() const
579{
580 return FString::Printf(TEXT("X=%u Y=%u"), X, Y);
581}
582
583template <>
584inline FString TIntPoint<uint8>::ToString() const
585{
586 return FString::Printf(TEXT("X=%u Y=%u"), X, Y);
587}
588
589}
590
591template <> struct TIsPODType<FInt32Point> { enum { Value = true }; };
592template <> struct TIsPODType<FUint32Point> { enum { Value = true }; };
593
594template<> struct TIsUECoreVariant<FInt32Point> { enum { Value = true }; };
595template<> struct TIsUECoreVariant<FUint32Point> { enum { Value = true }; };
596
597template <> struct TIsPODType<FInt64Point> { enum { Value = true }; };
598template <> struct TIsPODType<FUint64Point> { enum { Value = true }; };
599
600template<> struct TIsUECoreVariant<FInt64Point> { enum { Value = true }; };
601template<> struct TIsUECoreVariant<FUint64Point> { enum { Value = true }; };
#define check(expr)
Definition AssertionMacros.h:314
@ INDEX_NONE
Definition CoreMiscDefines.h:150
EForceInit
Definition CoreMiscDefines.h:154
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
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
const TCHAR * LexToString(EAnalyticsRecordEventMode Mode)
Definition IAnalyticsProvider.cpp:5
#define UE_SERIALIZE_VARIANT_FROM_MISMATCHED_TAG(AR_OR_SLOT, ALIAS, TYPE, ALT_TYPE)
Definition LargeWorldCoordinatesSerializer.h:9
#define SA_VALUE(Name, Value)
Definition StructuredArchiveNameHelpers.h:77
constexpr uint32 HashCombine(uint32 A, uint32 C)
Definition TypeHash.h:36
OutType IntCastChecked(InType In)
Definition UnrealTemplate.h:166
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
Definition NameTypes.h:617
Definition StructuredArchiveSlots.h:144
Definition StructuredArchiveSlots.h:52
UE_API FStructuredArchiveRecord EnterRecord()
Definition StructuredArchiveSlots.h:252
Definition Sphere.cpp:10
uint32 GetTypeHash(const TBox< T > &Box)
Definition Box.h:1008
U16 Index
Definition radfft.cpp:71
static constexpr UE_FORCEINLINE_HINT T DivideAndRoundUp(T Dividend, T Divisor)
Definition UnrealMathUtility.h:694
static constexpr UE_FORCEINLINE_HINT T DivideAndRoundDown(T Dividend, T Divisor)
Definition UnrealMathUtility.h:701
static CORE_API bool Value(const TCHAR *Stream, const TCHAR *Match, FName &Name)
Definition Parse.cpp:584
Definition IsPODType.h:12
Definition IsUECoreType.h:19
Definition IntPoint.h:25
TIntPoint operator/(const TIntPoint &Other) const
Definition IntPoint.h:299
friend void operator<<(FStructuredArchive::FSlot Slot, TIntPoint &Point)
Definition IntPoint.h:485
InIntType IntType
Definition IntPoint.h:26
TIntPoint(IntType InXY)
Definition IntPoint.h:71
IntType GetMin() const
Definition IntPoint.h:365
TIntPoint(const TIntPoint &)=default
friend FArchive & operator<<(FArchive &Ar, TIntPoint &Point)
Definition IntPoint.h:474
static TIntPoint DivideAndRoundUp(TIntPoint lhs, TIntPoint Divisor)
Definition IntPoint.h:434
TIntPoint operator+(const TIntPoint &Other) const
Definition IntPoint.h:266
TIntPoint operator*(const TIntPoint &Other) const
Definition IntPoint.h:288
bool operator==(const TIntPoint &Other) const
Definition IntPoint.h:138
bool SerializeFromMismatchedTag(FName StructTag, FArchive &Ar)
Definition IntPoint.h:503
IntType operator[](IntType Index) const
Definition IntPoint.h:322
TIntPoint(TIntPoint< OtherIntType > Other)
Definition IntPoint.h:92
TIntPoint operator*(IntType Scale) const
Definition IntPoint.h:244
TIntPoint operator-(const TIntPoint &Other) const
Definition IntPoint.h:277
TIntPoint ComponentMax(const TIntPoint &Other) const
Definition IntPoint.h:343
TIntPoint & operator=(TIntPoint &&)=default
IntType Y
Definition IntPoint.h:37
static int32 Num()
Definition IntPoint.h:462
static TIntPoint DivideAndRoundUp(TIntPoint lhs, IntType Divisor)
Definition IntPoint.h:429
IntType GetMax() const
Definition IntPoint.h:354
static TIntPoint DivideAndRoundDown(TIntPoint lhs, TIntPoint Divisor)
Definition IntPoint.h:452
static TIntPoint DivideAndRoundDown(TIntPoint lhs, IntType Divisor)
Definition IntPoint.h:447
TIntPoint & operator/=(IntType Divisor)
Definition IntPoint.h:174
TIntPoint ComponentMin(const TIntPoint &Other) const
Definition IntPoint.h:333
bool Serialize(FArchive &Ar)
Definition IntPoint.h:497
IntType XY[2]
Definition IntPoint.h:41
PRAGMA_ENABLE_DEPRECATION_WARNINGS const IntType & operator()(int32 PointIndex) const
Definition IntPoint.h:112
TIntPoint operator/(IntType Divisor) const
Definition IntPoint.h:255
FString ToString() const
Definition IntPoint.h:399
IntType & operator[](IntType Index)
Definition IntPoint.h:310
static const TIntPoint ZeroValue
Definition IntPoint.h:45
TIntPoint & operator/=(const TIntPoint &Other)
Definition IntPoint.h:230
TIntPoint(EForceInit)
Definition IntPoint.h:82
IntType & operator()(int32 PointIndex)
Definition IntPoint.h:125
bool operator!=(const TIntPoint &Other) const
Definition IntPoint.h:149
TIntPoint & operator*=(const TIntPoint &Other)
Definition IntPoint.h:202
static const TIntPoint NoneValue
Definition IntPoint.h:48
IntType X
Definition IntPoint.h:34
TIntPoint & operator=(const TIntPoint &)=default
TIntPoint & operator*=(IntType Scale)
Definition IntPoint.h:160
TIntPoint & operator-=(const TIntPoint &Other)
Definition IntPoint.h:216
bool InitFromString(const FString &InSourceString)
Definition IntPoint.h:411
IntType Size() const
Definition IntPoint.h:376
IntType SizeSquared() const
Definition IntPoint.h:389
TIntPoint & operator+=(const TIntPoint &Other)
Definition IntPoint.h:188
PRAGMA_DISABLE_DEPRECATION_WARNINGS TIntPoint(TIntPoint &&)=default