5#include "Containers/Array.h"
6#include "Containers/UnrealString.h"
8#include "Math/UnrealMathUtility.h"
9#include "Math/Vector2D.h"
10#include "Misc/AssertionMacros.h"
11#include "Misc/LargeWorldCoordinates.h"
12#include "Misc/LargeWorldCoordinatesSerializer.h"
13#include "Serialization/Archive.h"
14#include "Templates/IsUECoreType.h"
15#include "Templates/UnrealTypeTraits.h"
16#include "UObject/NameTypes.h"
17#include "UObject/UnrealNames.h"
19template <
typename T>
struct TIsPODType;
22
23
48
49
50
51
52
53
60
61
62
63
64
65 TBox2<T>(
const TVector2<T>& InMin,
const TVector2<T>& InMax )
72
73
74
75
76
77 TBox2<T>(
const TVector2<T>* Points,
const int32 Count );
80
81
82
83
84 TBox2<T>(
const TArray<TVector2<T>>& Points );
89
90
91
92
93
96 return (Min == Other.Min) && (Max == Other.Max);
100
101
102
103
104
107 return !(*
this == Other);
111
112
113
114
115
116
119 return Min.Equals(Other.Min, Tolerance) && Max.Equals(Other.Max, Tolerance);
123
124
125
126
127
131
132
133
134
135
136 TBox2<T>
operator+(
const TVector2<T>& Other )
const
138 return TBox2<T>(*
this) += Other;
142
143
144
145
146
150
151
152
153
154
157 return TBox2<T>(*
this) += Other;
161
162
163
164
165
168 check((Index >= 0) && (Index < 2));
181
182
183
184
185
193 DistSquared += FMath::Square(Point.X - Min.X);
195 else if (Point.X > Max.X)
197 DistSquared += FMath::Square(Point.X - Max.X);
202 DistSquared += FMath::Square(Point.Y - Min.Y);
204 else if (Point.Y > Max.Y)
206 DistSquared += FMath::Square(Point.Y - Max.Y);
209 return (T)DistSquared;
213
214
215
216
217
220 return TBox2<T>(Min - TVector2<T>(W, W), Max + TVector2<T>(W, W));
224
225
226
227
228
231 return TBox2<T>(Min - V, Max + V);
235
236
237
238
239
242 return (Max.X - Min.X) * (Max.Y - Min.Y);
246
247
248
249
250
253 return TVector2<T>((Min + Max) * 0.5f);
257
258
259
260
261
262
265 Extents = GetExtent();
266 center = Min + Extents;
270
271
272
273
274
275
279
280
281
282
283
286 return 0.5f * TVector2<T>(Max - Min);
291
292
293
294
295
298 return TVector2<T>(Max - Min);
302
303
306 Min = Max = TVector2<T>::ZeroVector;
311
312
313
314
315
316 TBox2<T>
Overlap(
const TBox2<T>& Other )
const;
319
320
321
322
323
327
328
329
330
331
332 bool IsInside(
const TVector2<T> & TestPoint )
const
334 return ((TestPoint.X > Min.X) && (TestPoint.X < Max.X) && (TestPoint.Y > Min.Y) && (TestPoint.Y < Max.Y));
338
339
340
341
342
343
346 return ((TestPoint.X >= Min.X) && (TestPoint.X <= Max.X) && (TestPoint.Y >= Min.Y) && (TestPoint.Y <= Max.Y));
350
351
352
353
354
357 return (IsInside(Other.Min) && IsInside(Other.Max));
361
362
363
364
365
366 TBox2<T>
ShiftBy(
const TVector2<T>& Offset )
const
368 return TBox2<T>(Min + Offset, Max + Offset);
372
373
374
375
376
377 TBox2<T>
MoveTo(
const TVector2<T>& Destination)
const
379 const TVector2<T> Offset = Destination - GetCenter();
380 return TBox2<T>(Min + Offset, Max + Offset);
384
385
386
387
393
394
395
396
397
398
399
402 return Ar << Box.Min << Box.Max << Box.bIsValid;
410 uint8 bValid = bIsValid;
411 Ar.Serialize(&bValid,
sizeof(uint8));
420 explicit TBox2(
const TBox2<FArg>& From) : Min((TVector2<T>)From.Min), Max((TVector2<T>)From.Max), bIsValid(From.bIsValid) {}
425
428TBox2<T>::TBox2(
const TVector2<T>* Points,
const int32 Count)
440TBox2<T>::TBox2(
const TArray<TVector2<T>>& Points)
522TBox2<T> TBox2<T>::
Overlap(
const TBox2<T>& Other)
const
571template<>
struct TIsPODType<FBox2f> {
enum {
Value =
true }; };
572template<>
struct TIsUECoreVariant<FBox2f> {
enum { Value =
true }; };
575template<>
struct TIsPODType<FBox2d> {
enum {
Value =
true }; };
576template<>
struct TIsUECoreVariant<FBox2d> {
enum { Value =
true }; };
580inline bool FBox2f::SerializeFromMismatchedTag(FName StructTag, FArchive& Ar)
586inline bool FBox2d::SerializeFromMismatchedTag(FName StructTag, FArchive& Ar)
#define UE_DECLARE_LWC_TYPE(...)
#define UE_SERIALIZE_VARIANT_FROM_MISMATCHED_TAG(AR_OR_SLOT, ALIAS, TYPE, ALT_TYPE)
#define UE_KINDA_SMALL_NUMBER
#define TEMPLATE_REQUIRES(...)
TBox2< T > ExpandBy(const TVector2< T > &V) const
TBox2< T > MoveTo(const TVector2< T > &Destination) const
TBox2< T > operator+(const TBox2< T > &Other) const
bool operator==(const TBox2< T > &Other) const
TBox2< T > ShiftBy(const TVector2< T > &Offset) const
bool IsInside(const TBox2< T > &Other) const
TBox2(const TBox2< FArg > &From)
FORCEINLINE bool Intersect(const TBox2< T > &other) const
TVector2< T > & operator[](int32 Index)
TBox2< T > operator+(const TVector2< T > &Other) const
TBox2< T > Overlap(const TBox2< T > &Other) const
bool IsInsideOrOn(const TVector2< T > &TestPoint) const
bool operator!=(const TBox2< T > &Other) const
bool Equals(const TBox2< T > &Other, T Tolerance=UE_KINDA_SMALL_NUMBER) const
TBox2< T > ExpandBy(const T W) const
FORCEINLINE TBox2< T > & operator+=(const TVector2< T > &Other)
bool Serialize(FArchive &Ar)
FORCEINLINE TBox2< T > & operator+=(const TBox2< T > &Other)
FORCEINLINE TVector2< T > GetClosestPointTo(const TVector2< T > &Point) const
bool SerializeFromMismatchedTag(FName StructTag, FArchive &Ar)
TVector2< T > GetSize() const
TVector2< T > GetExtent() const
FORCEINLINE T ComputeSquaredDistanceToPoint(const TVector2< T > &Point) const
bool IsInside(const TVector2< T > &TestPoint) const
TVector2< T > GetCenter() const
void GetCenterAndExtents(TVector2< T > ¢er, TVector2< T > &Extents) const