UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TwoVectors.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"
9#include "Math/Vector.h"
10
15{
16public:
17
20
23
24public:
25
28
36
43
44public:
45
53
61
69
76 [[nodiscard]] FTwoVectors operator/( float Scale ) const;
77
85
93
94 // Binary comparison operators.
95
102 [[nodiscard]] bool operator==( const FTwoVectors& V ) const;
103
110 [[nodiscard]] bool operator!=( const FTwoVectors& V ) const;
111
119 [[nodiscard]] bool Equals( const FTwoVectors& V, float Tolerance = UE_KINDA_SMALL_NUMBER ) const;
120
121 // Unary operators.
122
129
130 // Assignment operators.
131
139
147
155
162 FTwoVectors operator/=( float V );
163
171
179
188
189public:
190
196 [[nodiscard]] FVector::FReal GetMax() const;
197
203 [[nodiscard]] FVector::FReal GetMin() const;
204
210 [[nodiscard]] FString ToString() const;
211
212public:
213
222 {
223 return Ar << TwoVectors.v1 << TwoVectors.v2;
224 }
225
226 bool Serialize( FArchive& Ar )
227 {
228 Ar << *this;
229 return true;
230 }
231};
232
233
234/* FTwoVectors inline functions
235 *****************************************************************************/
236
238{
239 return V.operator*( Scale );
240}
241
242
244 v1(0.0f),
245 v2(0.0f)
246{ }
247
248
250 : v1(In1)
251 , v2(In2)
252{ }
253
254
256 : v1(ForceInit)
257 , v2(ForceInit)
258{ }
259
260
262{
263 return FTwoVectors(
264 FVector(v1 + V.v1),
265 FVector(v2 + V.v2)
266 );
267}
268
269
271{
272 return FTwoVectors(
273 FVector(v1 - V.v1),
274 FVector(v2 - V.v2)
275 );
276}
277
278
280{
281 return FTwoVectors(
282 FVector(v1 * Scale),
283 FVector(v2 * Scale)
284 );
285}
286
287
289{
290 const float RScale = 1.f / Scale;
291
292 return FTwoVectors(
293 FVector(v1 * RScale),
294 FVector(v2 * RScale)
295 );
296}
297
298
300{
301 return FTwoVectors(
302 FVector(v1 * V.v1),
303 FVector(v2 * V.v2)
304 );
305}
306
307
309{
310 return FTwoVectors(
311 FVector(v1 / V.v1),
312 FVector(v2 / V.v2)
313 );
314}
315
316
318{
319 return ((v1 == V.v1) && (v2 == V.v2));
320}
321
322
324{
325 return ((v1 != V.v1) || (v2 != V.v2));
326}
327
328
329UE_FORCEINLINE_HINT bool FTwoVectors::Equals( const FTwoVectors& V, float Tolerance ) const
330{
331 return v1.Equals(V.v1, Tolerance) && v2.Equals(V.v2, Tolerance);
332}
333
334
336{
337 return FTwoVectors(
338 FVector(-v1),
339 FVector(-v2)
340 );
341}
342
343
345{
346 v1 += V.v1;
347 v2 += V.v2;
348
349 return *this;
350}
351
352
354{
355 v1 -= V.v1;
356 v2 -= V.v2;
357
358 return *this;
359}
360
361
363{
364 v1 *= Scale;
365 v2 *= Scale;
366
367 return *this;
368}
369
370
372{
373 const float RV = 1.f/V;
374
375 v1 *= RV;
376 v2 *= RV;
377
378 return *this;
379}
380
381
383{
384 v1 *= V.v1;
385 v2 *= V.v2;
386 return *this;
387}
388
389
391{
392 v1 /= V.v1;
393 v2 /= V.v2;
394
395 return *this;
396}
397
398
400{
401 const FVector::FReal MaxMax = FMath::Max(FMath::Max(v1.X, v1.Y), v1.Z);
402 const FVector::FReal MaxMin = FMath::Max(FMath::Max(v2.X, v2.Y), v2.Z);
403
404 return FMath::Max(MaxMax, MaxMin);
405}
406
407
409{
410 const FVector::FReal MinMax = FMath::Min(FMath::Min(v1.X, v1.Y), v1.Z);
411 const FVector::FReal MinMin = FMath::Min(FMath::Min(v2.X, v2.Y), v2.Z);
412
413 return FMath::Min(MinMax, MinMin);
414}
415
416
418{
419 check(i > -1);
420 check(i < 6);
421
422 switch(i)
423 {
424 case 0: return v1.X;
425 case 1: return v2.X;
426 case 2: return v1.Y;
427 case 3: return v2.Y;
428 case 4: return v1.Z;
429 default: return v2.Z;
430 }
431}
432
433
435{
436 return FString::Printf(TEXT("V1=(%s) V2=(%s)"), *v1.ToString(), *v2.ToString());
437}
438
439template <> struct TIsPODType<FTwoVectors> { enum { Value = true }; };
#define check(expr)
Definition AssertionMacros.h:314
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
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define FVector
Definition IOSSystemIncludes.h:8
UE_FORCEINLINE_HINT FTwoVectors operator*(float Scale, const FTwoVectors &V)
Definition TwoVectors.h:237
#define UE_KINDA_SMALL_NUMBER
Definition UnrealMathUtility.h:131
Definition Archive.h:1208
Definition TwoVectors.h:15
friend FArchive & operator<<(FArchive &Ar, FTwoVectors &TwoVectors)
Definition TwoVectors.h:221
UE_FORCEINLINE_HINT FTwoVectors()
Definition TwoVectors.h:243
UE_FORCEINLINE_HINT FTwoVectors operator-=(const FTwoVectors &V)
Definition TwoVectors.h:353
FVector v1
Definition TwoVectors.h:19
FString ToString() const
Definition TwoVectors.h:434
UE_FORCEINLINE_HINT FTwoVectors operator+=(const FTwoVectors &V)
Definition TwoVectors.h:344
UE_FORCEINLINE_HINT FTwoVectors operator*(float Scale) const
Definition TwoVectors.h:279
UE_FORCEINLINE_HINT FTwoVectors operator-() const
Definition TwoVectors.h:335
FVector::FReal GetMax() const
Definition TwoVectors.h:399
bool Serialize(FArchive &Ar)
Definition TwoVectors.h:226
bool operator!=(const FTwoVectors &V) const
Definition TwoVectors.h:323
bool operator==(const FTwoVectors &V) const
Definition TwoVectors.h:317
FVector::FReal & operator[](int32 i)
Definition TwoVectors.h:417
FVector::FReal GetMin() const
Definition TwoVectors.h:408
FTwoVectors operator/(float Scale) const
Definition TwoVectors.h:288
FTwoVectors operator/=(float V)
Definition TwoVectors.h:371
bool Equals(const FTwoVectors &V, float Tolerance=UE_KINDA_SMALL_NUMBER) const
Definition TwoVectors.h:329
UE_FORCEINLINE_HINT FTwoVectors operator+(const FTwoVectors &V) const
Definition TwoVectors.h:261
UE_FORCEINLINE_HINT FTwoVectors operator*=(float Scale)
Definition TwoVectors.h:362
FVector v2
Definition TwoVectors.h:22
Definition IsPODType.h:12
@ Value
Definition IsPODType.h:13
T Z
Definition Vector.h:68
T Y
Definition Vector.h:65
FString ToString() const
Definition Vector.h:2304
double FReal
Definition Vector.h:55
T X
Definition Vector.h:62
UE_FORCEINLINE_HINT bool Equals(const TVector< T > &V, T Tolerance=UE_KINDA_SMALL_NUMBER) const
Definition Vector.h:1601