UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Box.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 "Math/MathFwd.h" // IWYU pragma: export
10#include "Math/Vector.h"
11#include "Math/Sphere.h"
13
14#ifndef ENABLE_UNINITIALIZED_BOX_DIAGNOSTIC
15#define ENABLE_UNINITIALIZED_BOX_DIAGNOSTIC 0
16#endif // ENABLE_UNINITIALIZED_BOX_DIAGNOSTIC
17
18#ifndef ENABLE_BOX_DIAGNOSTIC_CHECKS
19#define ENABLE_BOX_DIAGNOSTIC_CHECKS (ENABLE_UNINITIALIZED_BOX_DIAGNOSTIC || ENABLE_NAN_DIAGNOSTIC)
20#endif// ENABLE_BOX_DIAGNOSTIC_CHECKS
21
28namespace UE::Math
29{
30
31struct TBoxConstInit {};
32
33template<typename T>
34struct TBox
35{
36 using FReal = T;
37
40
43
46
47private:
48 uint8 Pad[sizeof(T) - sizeof(IsValid)];
49
50public:
51
61 [[nodiscard]] constexpr TBox()
62#if ENABLE_UNINITIALIZED_BOX_DIAGNOSTIC
63 : Min(std::numeric_limits<T>::quiet_NaN(), TVectorConstInit{})
64 , Max(std::numeric_limits<T>::quiet_NaN(), TVectorConstInit{})
65 , IsValid(0)
66#else
67 // To be consistent with other engine core types (i.e. Vector) the other members are not initialized
68 // since there is not meaningful default values.
69 : IsValid(0)
70#endif
71 {
72 }
73
75 [[nodiscard]] explicit constexpr TBox(ENoInit)
76 {
77 }
78
80 [[nodiscard]] explicit constexpr TBox(EForceInit)
81 : Min(0, TVectorConstInit{})
82 , Max(0, TVectorConstInit{})
83 , IsValid(0)
84 , Pad() // For deterministic cooking with UPS serialize-as-zero for immutable/atomic noexport types
85 {
86 }
87
90 {
91 }
92
93#if ENABLE_BOX_DIAGNOSTIC_CHECKS
94 inline void DiagnosticCheck() const
95 {
96 if (ContainsNaN())
97 {
98#if ENABLE_UNINITIALIZED_BOX_DIAGNOSTIC
99 // In case ENABLE_UNINITIALIZED_BOX_DIAGNOSTIC was explicitly enabled then report each encountered accesses to uninitialized members.
100 ensureAlwaysMsgf(false, TEXT("FBox contains NaN: %s. Initializing with zero extent and marking as invalid for safety."), *ToString());
101#else
102 // In case diagnostic check is enable from NaN diagnostic we report the error using the NaN error reporting behavior.
103 logOrEnsureNanError(TEXT("FBox contains NaN: %s. Initializing with zero extent and marking as invalid for safety."), *ToString());
104#endif
105 const_cast<TBox<T>*>(this)->Init();
106 }
107 }
108#else
110#endif
111
112 [[nodiscard]] bool ContainsNaN() const
113 {
114 return Min.ContainsNaN() || Max.ContainsNaN();
115 }
116
123 template<typename FArg>
125 : Min(InMin)
126 , Max(InMax)
127 , IsValid(1)
128 {
129 // Intended to catch TBox<float>(TVector<double>(), TVector<double>())
130 static_assert(sizeof(FArg) <= sizeof(T), "Losing precision when constructing a box of floats from vectors of doubles");
131
133 }
134
136 : Min(InMin)
137 , Max(InMax)
138 , IsValid(1)
139 {
141 }
142
149 TBox(const TVector<T>* Points, const int32 Count) : TBox(ForceInit)
150 {
151 for (int32 i = 0; i < Count; i++)
152 {
153 *this += Points[i];
154 }
155 }
156
162 explicit TBox(const TArray<TVector<T>>& Points) : TBox<T>(&Points[0], Points.Num()) {};
163
164 // Conversion from other type.
165 template<typename FArg UE_REQUIRES(!std::is_same_v<T, FArg>)>
166 explicit TBox(const TBox<FArg>& From)
167 : TBox<T>(TVector<T>(From.Min), TVector<T>(From.Max))
168 {
169 }
170
176 explicit TBox(const TSphere<T>& Sphere) : TBox<T>(Sphere.Center - TVector<T>(Sphere.W), Sphere.Center + TVector<T>(Sphere.W)) {};
177
178public:
179
188 {
189 return (!IsValid && !Other.IsValid) || ((IsValid && Other.IsValid) && (Min == Other.Min) && (Max == Other.Max));
190 }
191
198 {
199 return !(*this == Other);
200 }
201
211 [[nodiscard]] bool Equals(const TBox<T>& Other, T Tolerance=UE_KINDA_SMALL_NUMBER) const
212 {
213 return (!IsValid && !Other.IsValid) || ((IsValid && Other.IsValid) && Min.Equals(Other.Min, Tolerance) && Max.Equals(Other.Max, Tolerance));
214 }
215
223
231 {
232 return TBox<T>(*this) += Other;
233 }
234
241 inline TBox<T>& operator+=( const TBox<T>& Other );
242
250 {
251 return TBox<T>(*this) += Other;
252 }
253
261 {
262 check((Index >= 0) && (Index < 2));
263
264 if (Index == 0)
265 {
266 return Min;
267 }
268
269 return Max;
270 }
271
272 /* Gets reference to the min or max of this bounding volume.
273 *
274 * @param Index the index into points of the bounding volume.
275 * @return a const reference to a point of the bounding volume.
276 */
277 [[nodiscard]] inline const TVector<T>& operator[]( int32 Index ) const
278 {
279 check((Index >= 0) && (Index < 2));
280
281 if (Index == 0)
282 {
283 return Min;
284 }
285
286 return Max;
287 }
288
289public:
290
301
306 {
307 TVector<T> AxisDistances = (GetCenter() - Box.GetCenter()).GetAbs() - (GetExtent() + Box.GetExtent());
310 }
311
319 {
320 return TBox<T>(Min - TVector<T>(W, W, W), Max + TVector<T>(W, W, W));
321 }
322
330 {
331 return TBox<T>(Min - V, Max + V);
332 }
333
341 [[nodiscard]] TBox<T> ExpandBy(const TVector<T>& Neg, const TVector<T>& Pos) const
342 {
343 return TBox<T>(Min - Neg, Max + Pos);
344 }
345
353 {
354 return TBox<T>(Min + Offset, Max + Offset);
355 }
356
363 [[nodiscard]] inline TBox<T> MoveTo( const TVector<T>& Destination ) const
364 {
365 const TVector<T> Offset = Destination - GetCenter();
366 return TBox<T>(Min + Offset, Max + Offset);
367 }
368
375 inline TVector<T> GetCenter() const
376 {
378 return TVector<T>((Min + Max) * 0.5f);
379 }
380
388 inline void GetCenterAndExtents( TVector<T>& Center, TVector<T>& Extents ) const
389 {
390 Extents = GetExtent();
391 Center = Min + Extents;
392 }
393
401
408 inline TVector<T> GetExtent() const
409 {
411 return 0.5f * (Max - Min);
412 }
413
420 inline TVector<T> GetSize() const
421 {
423 return (Max - Min);
424 }
425
432 inline T GetVolume() const
433 {
435 return (Max.X - Min.X) * (Max.Y - Min.Y) * (Max.Z - Min.Z);
436 }
437
441 inline void Init()
442 {
444 IsValid = 0;
445 }
446
456 inline bool Intersect( const TBox<T>& Other ) const;
457
467 inline bool IntersectXY( const TBox<T>& Other ) const;
468
475 [[nodiscard]] TBox<T> Overlap( const TBox<T>& Other ) const;
476
484
495 inline bool IsInside( const TVector<T>& In ) const
496 {
498 return ((In.X > Min.X) && (In.X < Max.X) && (In.Y > Min.Y) && (In.Y < Max.Y) && (In.Z > Min.Z) && (In.Z < Max.Z));
499 }
500
511 inline bool IsInsideOrOn( const TVector<T>& In ) const
512 {
514 return ((In.X >= Min.X) && (In.X <= Max.X) && (In.Y >= Min.Y) && (In.Y <= Max.Y) && (In.Z >= Min.Z) && (In.Z <= Max.Z));
515 }
516
528 {
529 return (IsInside(Other.Min) && IsInside(Other.Max));
530 }
531
543 {
544 return (IsInsideOrOn(Other.Min) && IsInsideOrOn(Other.Max));
545 }
546
557 inline bool IsInsideXY( const TVector<T>& In ) const
558 {
560 return ((In.X > Min.X) && (In.X < Max.X) && (In.Y > Min.Y) && (In.Y < Max.Y));
561 }
562
573 inline bool IsInsideOrOnXY(const TVector<T>& In) const
574 {
576 return ((In.X >= Min.X) && (In.X <= Max.X) && (In.Y >= Min.Y) && (In.Y <= Max.Y));
577 }
578
590 {
591 return (IsInsideXY(Other.Min) && IsInsideXY(Other.Max));
592 }
593
602
611
620
626 FString ToString() const;
627
633 FString ToCompactString() const;
634
640 void GetVertices( TVector<T> (&Vertices)[8] ) const;
641
642public:
643
651 static TBox<T> BuildAABB( const TVector<T>& Origin, const TVector<T>& Extent )
652 {
653 TBox<T> NewBox(Origin - Extent, Origin + Extent);
654
655 return NewBox;
656 }
657
658public:
659
668 {
669 return Ar << Box.Min << Box.Max << Box.IsValid;
670 }
671
679 {
681 Record << SA_VALUE(TEXT("Min"), Box.Min) << SA_VALUE(TEXT("Max"), Box.Max) << SA_VALUE(TEXT("IsValid"), Box.IsValid);
682 }
683
684 bool Serialize( FArchive& Ar )
685 {
686 Ar << *this;
687 return true;
688 }
689
691 {
692 Slot << *this;
693 return true;
694 }
695
697 {
698 if constexpr (std::is_same_v<T, float>)
699 {
700 return UE_SERIALIZE_VARIANT_FROM_MISMATCHED_TAG(Ar, Box, Box3f, Box3d);
701 }
702 else if constexpr (std::is_same_v<T, double>)
703 {
704 return UE_SERIALIZE_VARIANT_FROM_MISMATCHED_TAG(Ar, Box, Box3d, Box3f);
705 }
706 else
707 {
708 static_assert(sizeof(T) == 0, "Unimplemented");
709 return false;
710 }
711 }
712};
713
714/* TBox<T> inline functions
715 *****************************************************************************/
716
717template<typename T>
719{
720 if (IsValid)
721 {
722 DiagnosticCheck();
723 // Not testing Other.DiagnosticCheck() since TVector is not initialized to NaN
724
725 Min.X = FMath::Min(Min.X, Other.X);
726 Min.Y = FMath::Min(Min.Y, Other.Y);
727 Min.Z = FMath::Min(Min.Z, Other.Z);
728
729 Max.X = FMath::Max(Max.X, Other.X);
730 Max.Y = FMath::Max(Max.Y, Other.Y);
731 Max.Z = FMath::Max(Max.Z, Other.Z);
732 }
733 else
734 {
735 Min = Max = Other;
736 IsValid = 1;
737 }
738
739 return *this;
740}
741
742
743template<typename T>
745{
746 if (IsValid && Other.IsValid)
747 {
748 DiagnosticCheck();
749 // Testing Other.DiagnosticCheck() since TBox can be initialized to NaN
750 Other.DiagnosticCheck();
751
752 Min.X = FMath::Min(Min.X, Other.Min.X);
753 Min.Y = FMath::Min(Min.Y, Other.Min.Y);
754 Min.Z = FMath::Min(Min.Z, Other.Min.Z);
755
756 Max.X = FMath::Max(Max.X, Other.Max.X);
757 Max.Y = FMath::Max(Max.Y, Other.Max.Y);
758 Max.Z = FMath::Max(Max.Z, Other.Max.Z);
759 }
760 else if (Other.IsValid)
761 {
762 *this = Other;
763 }
764
765 return *this;
766}
767
768template<typename T>
770{
771 DiagnosticCheck();
772
773 // start by considering the point inside the box
774 TVector<T> ClosestPoint = Point;
775
776 // now clamp to inside box if it's outside
777 if (Point.X < Min.X)
778 {
779 ClosestPoint.X = Min.X;
780 }
781 else if (Point.X > Max.X)
782 {
783 ClosestPoint.X = Max.X;
784 }
785
786 // now clamp to inside box if it's outside
787 if (Point.Y < Min.Y)
788 {
789 ClosestPoint.Y = Min.Y;
790 }
791 else if (Point.Y > Max.Y)
792 {
793 ClosestPoint.Y = Max.Y;
794 }
795
796 // Now clamp to inside box if it's outside.
797 if (Point.Z < Min.Z)
798 {
799 ClosestPoint.Z = Min.Z;
800 }
801 else if (Point.Z > Max.Z)
802 {
803 ClosestPoint.Z = Max.Z;
804 }
805
806 return ClosestPoint;
807}
808
809
810template<typename T>
811inline bool TBox<T>::Intersect( const TBox<T>& Other ) const
812{
813 DiagnosticCheck();
814 // Testing Other.DiagnosticCheck() since TBox can be initialized to NaN
815 Other.DiagnosticCheck();
816
817 if ((Min.X > Other.Max.X) || (Other.Min.X > Max.X))
818 {
819 return false;
820 }
821
822 if ((Min.Y > Other.Max.Y) || (Other.Min.Y > Max.Y))
823 {
824 return false;
825 }
826
827 if ((Min.Z > Other.Max.Z) || (Other.Min.Z > Max.Z))
828 {
829 return false;
830 }
831
832 return true;
833}
834
835
836template<typename T>
837inline bool TBox<T>::IntersectXY( const TBox<T>& Other ) const
838{
839 DiagnosticCheck();
840 // Testing Other.DiagnosticCheckUninitialized() since TBox can be initialized to NaN
841 Other.DiagnosticCheck();
842
843 if ((Min.X > Other.Max.X) || (Other.Min.X > Max.X))
844 {
845 return false;
846 }
847
848 if ((Min.Y > Other.Max.Y) || (Other.Min.Y > Max.Y))
849 {
850 return false;
851 }
852
853 return true;
854}
855
856
857template<typename T>
859{
860 return FString::Printf(TEXT("IsValid=%s, Min=(%s), Max=(%s)"), IsValid ? TEXT("true") : TEXT("false"), *Min.ToString(), *Max.ToString());
861}
862
863template<typename T>
865{
866 return IsValid ? FString::Printf(TEXT("Min=(%s), Max=(%s)"), *Min.ToString(), *Max.ToString()) : TEXT("IsValid=false");
867}
868
869
870template<typename T>
872{
873 // if we are not valid, return another invalid box.
874 if (!IsValid)
875 {
876 return TBox<T>(ForceInit);
877 }
878
879 DiagnosticCheck();
880
882
885
890
891 const TVectorRegisterType<T> Half = VectorSetFloat1((T)0.5f); // VectorSetFloat1() can be faster than SetFloat3(0.5, 0.5, 0.5, 0.0). Okay if 4th element is 0.5, it's multiplied by 0.0 below and we discard W anyway.
894
895 TVectorRegisterType<T> NewOrigin = VectorMultiply(VectorReplicate(Origin, 0), m0);
896 NewOrigin = VectorMultiplyAdd(VectorReplicate(Origin, 1), m1, NewOrigin);
897 NewOrigin = VectorMultiplyAdd(VectorReplicate(Origin, 2), m2, NewOrigin);
898 NewOrigin = VectorAdd(NewOrigin, m3);
899
903
906
909
910 NewBox.IsValid = 1;
911
912 return NewBox;
913}
914
915template<typename T>
917{
918 return TransformBy(M.ToMatrixWithScale());
919}
920
921template<typename T>
922void TBox<T>::GetVertices(TVector<T>(&Vertices)[8]) const
923{
924 DiagnosticCheck();
925
926 Vertices[0] = TVector<T>(Min);
927 Vertices[1] = TVector<T>(Min.X, Min.Y, Max.Z);
928 Vertices[2] = TVector<T>(Min.X, Max.Y, Min.Z);
929 Vertices[3] = TVector<T>(Max.X, Min.Y, Min.Z);
930 Vertices[4] = TVector<T>(Max.X, Max.Y, Min.Z);
931 Vertices[5] = TVector<T>(Max.X, Min.Y, Max.Z);
932 Vertices[6] = TVector<T>(Min.X, Max.Y, Max.Z);
933 Vertices[7] = TVector<T>(Max);
934}
935
936template<typename T>
938{
939 // if we are not valid, return another invalid box.
940 if (!IsValid)
941 {
942 return TBox<T>(ForceInit);
943 }
944
945 TVector<T> Vertices[8];
946 GetVertices(Vertices);
947
949
950 for (int32 VertexIndex = 0; VertexIndex < UE_ARRAY_COUNT(Vertices); VertexIndex++)
951 {
952 TVector<T> ProjectedVertex = M.InverseTransformPosition(Vertices[VertexIndex]);
954 }
955
956 return NewBox;
957}
958
959template<typename T>
961{
962 // if we are not valid, return another invalid box.
963 if (!IsValid)
964 {
965 return TBox<T>(ForceInit);
966 }
967
968 TVector<T> Vertices[8];
969 GetVertices(Vertices);
970
972
973 for (int32 VertexIndex = 0; VertexIndex < UE_ARRAY_COUNT(Vertices); VertexIndex++)
974 {
975 TVector4<T> ProjectedVertex = ProjM.TransformPosition(Vertices[VertexIndex]);
977 }
978
979 return NewBox;
980}
981
982template<typename T>
984{
985 if (Intersect(Other) == false)
986 {
987 static TBox<T> EmptyBox(ForceInit);
988 return EmptyBox;
989 }
990
991 // otherwise they overlap
992 // so find overlapping box
994
995 MinVector.X = FMath::Max(Min.X, Other.Min.X);
996 MaxVector.X = FMath::Min(Max.X, Other.Max.X);
997
998 MinVector.Y = FMath::Max(Min.Y, Other.Min.Y);
999 MaxVector.Y = FMath::Min(Max.Y, Other.Max.Y);
1000
1001 MinVector.Z = FMath::Max(Min.Z, Other.Min.Z);
1002 MaxVector.Z = FMath::Min(Max.Z, Other.Max.Z);
1003
1004 return TBox<T>(MinVector, MaxVector);
1005}
1006
1007template<typename T>
1009{
1010 return !Box.IsValid ? 0 // All invalid boxes are the same
1012}
1013} // namespace UE::Math
1014
1016
1017//template<> struct TCanBulkSerialize<FBox3f> { enum { Value = true }; };
1018template<> struct TIsPODType<FBox3f> { enum { Value = true }; };
1019template<> struct TIsUECoreVariant<FBox3f> { enum { Value = true }; };
1020
1021//template<> struct TCanBulkSerialize<FBox3d> { enum { Value = false }; }; // LWC_TODO: This can be done (via versioning) once LWC is fixed to on.
1022template<> struct TIsPODType<FBox3d> { enum { Value = true }; };
1023template<> struct TIsUECoreVariant<FBox3d> { enum { Value = true }; };
1024
1025/* FMath inline functions
1026 *****************************************************************************/
1027
1028template<typename FReal>
1030 (
1033 )
1034{
1035 return (Point.X >= Box.Min.X && Point.X <= Box.Max.X &&
1036 Point.Y >= Box.Min.Y && Point.Y <= Box.Max.Y &&
1037 Point.Z >= Box.Min.Z && Point.Z <= Box.Max.Z);
1038}
1039
1040template<typename FReal>
1042 (
1044 const UE::Math::TVector<FReal>& Start,
1047 )
1048{
1049 return LineBoxIntersection(Box, Start, End, StartToEnd, StartToEnd.Reciprocal());
1050}
1051
1052template<typename FReal>
1054 (
1056 const UE::Math::TVector<FReal>& Start,
1060 )
1061{
1063 bool bStartIsOutside = false;
1064
1065 if(Start.X < Box.Min.X)
1066 {
1067 bStartIsOutside = true;
1068 if(End.X >= Box.Min.X)
1069 {
1070 Time.X = (Box.Min.X - Start.X) * OneOverStartToEnd.X;
1071 }
1072 else
1073 {
1074 return false;
1075 }
1076 }
1077 else if(Start.X > Box.Max.X)
1078 {
1079 bStartIsOutside = true;
1080 if(End.X <= Box.Max.X)
1081 {
1082 Time.X = (Box.Max.X - Start.X) * OneOverStartToEnd.X;
1083 }
1084 else
1085 {
1086 return false;
1087 }
1088 }
1089 else
1090 {
1091 Time.X = 0.0f;
1092 }
1093
1094 if(Start.Y < Box.Min.Y)
1095 {
1096 bStartIsOutside = true;
1097 if(End.Y >= Box.Min.Y)
1098 {
1099 Time.Y = (Box.Min.Y - Start.Y) * OneOverStartToEnd.Y;
1100 }
1101 else
1102 {
1103 return false;
1104 }
1105 }
1106 else if(Start.Y > Box.Max.Y)
1107 {
1108 bStartIsOutside = true;
1109 if(End.Y <= Box.Max.Y)
1110 {
1111 Time.Y = (Box.Max.Y - Start.Y) * OneOverStartToEnd.Y;
1112 }
1113 else
1114 {
1115 return false;
1116 }
1117 }
1118 else
1119 {
1120 Time.Y = 0.0f;
1121 }
1122
1123 if(Start.Z < Box.Min.Z)
1124 {
1125 bStartIsOutside = true;
1126 if(End.Z >= Box.Min.Z)
1127 {
1128 Time.Z = (Box.Min.Z - Start.Z) * OneOverStartToEnd.Z;
1129 }
1130 else
1131 {
1132 return false;
1133 }
1134 }
1135 else if(Start.Z > Box.Max.Z)
1136 {
1137 bStartIsOutside = true;
1138 if(End.Z <= Box.Max.Z)
1139 {
1140 Time.Z = (Box.Max.Z - Start.Z) * OneOverStartToEnd.Z;
1141 }
1142 else
1143 {
1144 return false;
1145 }
1146 }
1147 else
1148 {
1149 Time.Z = 0.0f;
1150 }
1151
1152 if(bStartIsOutside)
1153 {
1154 const FReal MaxTime = Max3(Time.X,Time.Y,Time.Z);
1155
1156 if(MaxTime >= 0.0f && MaxTime <= 1.0f)
1157 {
1158 const UE::Math::TVector<FReal> Hit = Start + StartToEnd * MaxTime;
1159 const FReal BOX_SIDE_THRESHOLD = 0.1f;
1160 if( Hit.X > Box.Min.X - BOX_SIDE_THRESHOLD && Hit.X < Box.Max.X + BOX_SIDE_THRESHOLD &&
1161 Hit.Y > Box.Min.Y - BOX_SIDE_THRESHOLD && Hit.Y < Box.Max.Y + BOX_SIDE_THRESHOLD &&
1162 Hit.Z > Box.Min.Z - BOX_SIDE_THRESHOLD && Hit.Z < Box.Max.Z + BOX_SIDE_THRESHOLD)
1163 {
1164 return true;
1165 }
1166 }
1167
1168 return false;
1169 }
1170 else
1171 {
1172 return true;
1173 }
1174}
1175
1189template<typename FReal>
1191{
1192 // Accumulates the distance as we iterate axis
1193 FReal DistSquared = 0.f;
1194 // Check each axis for min/max and add the distance accordingly
1195 // NOTE: Loop manually unrolled for > 2x speed up
1196 if (SphereCenter.X < AABB.Min.X)
1197 {
1198 DistSquared += FMath::Square(SphereCenter.X - AABB.Min.X);
1199 }
1200 else if (SphereCenter.X > AABB.Max.X)
1201 {
1202 DistSquared += FMath::Square(SphereCenter.X - AABB.Max.X);
1203 }
1204 if (SphereCenter.Y < AABB.Min.Y)
1205 {
1206 DistSquared += FMath::Square(SphereCenter.Y - AABB.Min.Y);
1207 }
1208 else if (SphereCenter.Y > AABB.Max.Y)
1209 {
1210 DistSquared += FMath::Square(SphereCenter.Y - AABB.Max.Y);
1211 }
1212 if (SphereCenter.Z < AABB.Min.Z)
1213 {
1214 DistSquared += FMath::Square(SphereCenter.Z - AABB.Min.Z);
1215 }
1216 else if (SphereCenter.Z > AABB.Max.Z)
1217 {
1218 DistSquared += FMath::Square(SphereCenter.Z - AABB.Max.Z);
1219 }
1220 // If the distance is less than or equal to the radius, they intersect
1221 return DistSquared <= RadiusSquared;
1222}
1223
1227template<typename FReal>
1229{
1231 // If the distance is less than or equal to the radius, they intersect
1232 return SphereAABBIntersection(Sphere.Center, RadiusSquared, AABB);
1233}
1234
#define ensureAlwaysMsgf(InExpression, InFormat,...)
Definition AssertionMacros.h:467
#define check(expr)
Definition AssertionMacros.h:314
ENoInit
Definition CoreMiscDefines.h:158
EForceInit
Definition CoreMiscDefines.h:154
@ ForceInit
Definition CoreMiscDefines.h:155
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
#define UE_FORCEINLINE_HINT
Definition Platform.h:723
T ComputeSquaredDistanceFromBoxToPoint(const UE::Math::TVector< T > &Mins, const UE::Math::TVector< T > &Maxs, const UE::Math::TVector< U > &Point)
Definition Vector.h:2630
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define UE_SERIALIZE_VARIANT_FROM_MISMATCHED_TAG(AR_OR_SLOT, ALIAS, TYPE, ALT_TYPE)
Definition LargeWorldCoordinatesSerializer.h:9
#define UE_DECLARE_LWC_TYPE(...)
Definition LargeWorldCoordinates.h:27
#define logOrEnsureNanError(_FormatString_,...)
Definition LogMacros.h:436
@ Num
Definition MetalRHIPrivate.h:234
FVector MaxVector(const FVector &VectorA, const FVector &VectorB)
Definition PhysicsFieldComponent.cpp:172
FVector MinVector(const FVector &VectorA, const FVector &VectorB)
Definition PhysicsFieldComponent.cpp:167
#define SA_VALUE(Name, Value)
Definition StructuredArchiveNameHelpers.h:77
constexpr uint32 HashCombineFast(uint32 A, uint32 B)
Definition TypeHash.h:74
FORCEINLINE VectorRegister4Float VectorSubtract(const VectorRegister4Float &Vec1, const VectorRegister4Float &Vec2)
Definition UnrealMathFPU.h:731
FORCEINLINE VectorRegister4Float VectorSetFloat1(float F)
Definition UnrealMathFPU.h:518
FORCEINLINE VectorRegister4Float VectorMultiply(const VectorRegister4Float &Vec1, const VectorRegister4Float &Vec2)
Definition UnrealMathFPU.h:758
VectorRegister4Float VectorLoadAligned(const float *Ptr)
Definition UnrealMathFPU.h:451
FORCEINLINE VectorRegister4Float VectorMultiplyAdd(const VectorRegister4Float &Vec1, const VectorRegister4Float &Vec2, const VectorRegister4Float &Vec3)
Definition UnrealMathFPU.h:786
FORCEINLINE VectorRegister4Float VectorAbs(const VectorRegister4Float &Vec)
Definition UnrealMathFPU.h:661
FORCEINLINE VectorRegister4Float VectorAdd(const VectorRegister4Float &Vec1, const VectorRegister4Float &Vec2)
Definition UnrealMathFPU.h:704
FORCEINLINE void VectorStoreFloat3(const VectorRegister4Float &Vec, float *Dst)
Definition UnrealMathFPU.h:594
#define VectorReplicate(Vec, ElementIndex)
Definition UnrealMathFPU.h:627
#define UE_KINDA_SMALL_NUMBER
Definition UnrealMathUtility.h:131
FORCEINLINE VectorRegister4Float VectorLoadFloat3_W0(const float *Ptr)
VectorLoadFloat3_W0.
Definition UnrealMathVectorCommon.h.inl:129
#define UE_ARRAY_COUNT(array)
Definition UnrealTemplate.h:212
typename UE::Math::VectorRegisterPrivate::TVectorRegisterTypeHelper< T >::Type TVectorRegisterType
Definition VectorRegister.h:49
uint32 Offset
Definition VulkanMemory.cpp:4033
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
bool ContainsNaN() const
Definition Vector.h:188
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 Array.h:670
Definition Sphere.cpp:10
uint32 GetTypeHash(const TBox< T > &Box)
Definition Box.h:1008
U16 Index
Definition radfft.cpp:71
static bool PointBoxIntersection(const UE::Math::TVector< FReal > &Point, const UE::Math::TBox< FReal > &Box)
Definition Box.h:1030
static bool SphereAABBIntersection(const UE::Math::TVector< FReal > &SphereCenter, const FReal RadiusSquared, const UE::Math::TBox< FReal > &AABB)
Definition Box.h:1190
static constexpr UE_FORCEINLINE_HINT T Square(const T A)
Definition UnrealMathUtility.h:578
static bool LineBoxIntersection(const UE::Math::TBox< FReal > &Box, const UE::Math::TVector< FReal > &Start, const UE::Math::TVector< FReal > &End, const UE::Math::TVector< FReal > &Direction)
Definition Box.h:1042
static constexpr UE_FORCEINLINE_HINT T Max3(const T A, const T B, const T C)
Definition UnrealMathUtility.h:551
Definition IsPODType.h:12
@ Value
Definition IsPODType.h:13
Definition IsUECoreType.h:19
@ Value
Definition IsUECoreType.h:20
Definition Box.h:31
Definition Box.h:35
bool IsInside(const TVector< T > &In) const
Definition Box.h:495
bool ContainsNaN() const
Definition Box.h:112
TBox(const TSphere< T > &Sphere)
Definition Box.h:176
UE_FORCEINLINE_HINT bool IsInsideOrOn(const TBox< T > &Other) const
Definition Box.h:542
UE_FORCEINLINE_HINT bool operator!=(const TBox< T > &Other) const
Definition Box.h:197
TVector< T > GetCenter() const
Definition Box.h:375
UE_FORCEINLINE_HINT TBox< T > operator+(const TBox< T > &Other) const
Definition Box.h:249
void GetCenterAndExtents(TVector< T > &Center, TVector< T > &Extents) const
Definition Box.h:388
friend FArchive & operator<<(FArchive &Ar, TBox< T > &Box)
Definition Box.h:667
bool IsInsideXY(const TVector< T > &In) const
Definition Box.h:557
UE_FORCEINLINE_HINT TBox< T > ExpandBy(T W) const
Definition Box.h:318
T FReal
Definition Box.h:36
static TBox< T > BuildAABB(const TVector< T > &Origin, const TVector< T > &Extent)
Definition Box.h:651
TBox(const TVector< T > *Points, const int32 Count)
Definition Box.h:149
bool IntersectXY(const TBox< T > &Other) const
Definition Box.h:837
const TVector< T > & operator[](int32 Index) const
Definition Box.h:277
T ComputeSquaredDistanceToBox(const TBox< T > &Box) const
Definition Box.h:305
TBox< T > MoveTo(const TVector< T > &Destination) const
Definition Box.h:363
constexpr TBox()
Definition Box.h:61
friend void operator<<(FStructuredArchive::FSlot Slot, TBox< T > &Box)
Definition Box.h:678
TBox< T > & operator+=(const TVector< T > &Other)
Definition Box.h:718
bool Serialize(FArchive &Ar)
Definition Box.h:684
TBox< T > InverseTransformBy(const TTransform< T > &M) const
Definition Box.h:937
TBox< T > TransformBy(const TMatrix< T > &M) const
Definition Box.h:871
uint8 IsValid
Definition Box.h:45
UE_FORCEINLINE_HINT bool IsInside(const TBox< T > &Other) const
Definition Box.h:527
TBox(const TVector4< T > &InMin, const TVector4< T > &InMax)
Definition Box.h:135
TBox(const TVector< FArg > &InMin, const TVector< FArg > &InMax)
Definition Box.h:124
TBox< T > TransformBy(const TTransform< T > &M) const
Definition Box.h:916
UE_FORCEINLINE_HINT T ComputeSquaredDistanceToPoint(const TVector< T > &Point) const
Definition Box.h:297
void Init()
Definition Box.h:441
void GetVertices(TVector< T >(&Vertices)[8]) const
Definition Box.h:922
UE_FORCEINLINE_HINT TBox< T > ExpandBy(const TVector< T > &V) const
Definition Box.h:329
TVector< T > GetClosestPointTo(const TVector< T > &Point) const
Definition Box.h:769
TVector< T > & operator[](int32 Index)
Definition Box.h:260
TBox< T > ExpandBy(const TVector< T > &Neg, const TVector< T > &Pos) const
Definition Box.h:341
TVector< T > GetExtent() const
Definition Box.h:408
bool Equals(const TBox< T > &Other, T Tolerance=UE_KINDA_SMALL_NUMBER) const
Definition Box.h:211
UE_FORCEINLINE_HINT bool operator==(const TBox< T > &Other) const
Definition Box.h:187
TBox< T > Overlap(const TBox< T > &Other) const
Definition Box.h:983
TBox< T > & operator+=(const TBox< T > &Other)
Definition Box.h:744
constexpr TBox(ENoInit)
Definition Box.h:75
TBox(const TBox< FArg > &From)
Definition Box.h:166
TVector< T > GetSize() const
Definition Box.h:420
bool IsInsideOrOnXY(const TVector< T > &In) const
Definition Box.h:573
FString ToString() const
Definition Box.h:858
bool IsInsideOrOn(const TVector< T > &In) const
Definition Box.h:511
FString ToCompactString() const
Definition Box.h:864
UE_FORCEINLINE_HINT bool IsInsideXY(const TBox< T > &Other) const
Definition Box.h:589
constexpr TBox(EForceInit)
Definition Box.h:80
constexpr TBox(EForceInit, TBoxConstInit)
Definition Box.h:88
UE_FORCEINLINE_HINT TBox< T > operator+(const TVector< T > &Other) const
Definition Box.h:230
bool Serialize(FStructuredArchive::FSlot Slot)
Definition Box.h:690
TVector< T > Min
Definition Box.h:39
UE_FORCEINLINE_HINT void DiagnosticCheck() const
Definition Box.h:109
TVector< T > Max
Definition Box.h:42
TBox(const TArray< TVector< T > > &Points)
Definition Box.h:162
bool SerializeFromMismatchedTag(FName StructTag, FArchive &Ar)
Definition Box.h:696
bool Intersect(const TBox< T > &Other) const
Definition Box.h:811
T GetVolume() const
Definition Box.h:432
TBox< T > TransformProjectBy(const TMatrix< T > &ProjM) const
Definition Box.h:960
UE_FORCEINLINE_HINT TBox< T > ShiftBy(const TVector< T > &Offset) const
Definition Box.h:352
Definition Matrix.h:43
T M[4][4]
Definition Matrix.h:49
Definition Sphere.h:29
Definition TransformNonVectorized.h:39
TVector< T > InverseTransformPosition(const TVector< T > &V) const
Definition TransformNonVectorized.h:1456
TMatrix< T > ToMatrixWithScale() const
Definition TransformNonVectorized.h:241
Definition Vector4.h:30
T W
Definition Vector4.h:52
Definition Vector.h:44
Definition Vector.h:51
T Z
Definition Vector.h:68
T Y
Definition Vector.h:65
static UE_FORCEINLINE_HINT T DotProduct(const TVector< T > &A, const TVector< T > &B)
Definition Vector.h:1559
static TVector< T > Max(const TVector< T > &A, const TVector< T > &B)
Definition Vector.h:2506
T X
Definition Vector.h:62