6#include "Math/UnrealMathUtility.h"
7#include "Math/Vector.h"
8#include "Math/Vector4.h"
13 template<
typename U >
using TVector = UE::Math::TVector<U>;
14 template<
typename U >
using TVector4 = UE::Math::TVector4<U>;
17 TVector4<T> Min = TVector4<T>( TNumericLimits<T>::Max(), TNumericLimits<T>::Max(), TNumericLimits<T>::Max() );
18 TVector4<T> Max = TVector4<T>( -TNumericLimits<T>::Max(), -TNumericLimits<T>::Max(), -TNumericLimits<T>::Max() );
29 VectorStoreAligned( VectorMin( VectorLoadAligned( &Min ), VectorLoadFloat3( &Other ) ), &Min );
30 VectorStoreAligned( VectorMax( VectorLoadAligned( &Max ), VectorLoadFloat3( &Other ) ), &Max );
36 VectorStoreAligned( VectorMin( VectorLoadAligned( &Min ), VectorLoadAligned( &Other.Min ) ), &Min );
37 VectorStoreAligned( VectorMax( VectorLoadAligned( &Max ), VectorLoadAligned( &Other.Max ) ), &Max );
41 FORCEINLINE TBounds<T> operator+(
const TBounds<T>& Other )
const
43 return TBounds<T>(*
this) += Other;
49 Separated = VectorAnyGreaterThan( VectorLoadAligned( &Min ), VectorLoadAligned( &Other.Max ) );
50 Separated |= VectorAnyGreaterThan( VectorLoadAligned( &Other.Min ), VectorLoadAligned( &Max ) );
52 return Separated == 0;
57 int MaskMin = VectorMaskBits( VectorCompareLE( VectorLoadAligned( &Min ), VectorLoadAligned( &Other.Min ) ) );
58 int MaskMax = VectorMaskBits( VectorCompareGE( VectorLoadAligned( &Max ), VectorLoadAligned( &Other.Max ) ) );
59 return ( MaskMin & MaskMax & 7 ) == 7;
64 auto rMin = VectorLoadAligned( &Min );
65 auto rMax = VectorLoadAligned( &Max );
66 auto rPoint = VectorLoadFloat3( &Point );
67 auto rClosest = VectorSubtract( VectorMin( VectorMax( rPoint, rMin ), rMax ), rPoint );
68 return VectorDot3Scalar( rClosest, rClosest );
73 return (Max + Min) * 0.5;
78 return (Max - Min) * 0.5;
83 TVector<T> Size = Max - Min;
84 return 0.5 * (Size.X * Size.Y + Size.X * Size.Z + Size.Y * Size.Z);
87 template<
typename U >
90 using CommonType =
typename std::common_type<T, U>::type;
92 TBounds< CommonType > Bounds;
93 Bounds.Min = TVector4< CommonType >( Min ) + TVector4< CommonType >( Offset, 0.0 );
94 Bounds.Max = TVector4< CommonType >( Max ) + TVector4< CommonType >( Offset, 0.0 );
98 template<
typename U >
99 FORCEINLINE TBounds<
float > ToRelative(
const TVector<U>& Offset )
const
101 using CommonType =
typename std::common_type<T, U>::type;
103 TBounds<
float > Bounds;
104 Bounds.Min = TVector4<
float >( TVector4< CommonType >( Min ) - TVector4< CommonType >( Offset, 0.0 ) );
105 Bounds.Max = TVector4<
float >( TVector4< CommonType >( Max ) - TVector4< CommonType >( Offset, 0.0 ) );
109 FORCEINLINE friend FArchive& operator<<( FArchive& Ar, TBounds<T>& Bounds )
117using FBounds3f = TBounds<
float >;
118using FBounds3d = TBounds<
double >;