6#include "Misc/AssertionMacros.h"
7#include "Math/UnrealMathUtility.h"
8#include "Math/Vector2D.h"
9#include "Math/TransformCalculus.h"
26template<
typename T>
class TMatrix2x2;
62 return Transform + Point;
80
81
82template<
typename PositionType>
85 return Transform * Point;
88template<
typename PositionType>
91 return Transform * Point;
95
96
97template<
typename VectorType>
100 return Transform * Vector;
103template<
typename VectorType>
106 return Transform * Vector;
113 static_assert(
std::is_floating_point_v<T>,
"T must be floating point");
117 using Vector2Type =
UE::
Math::TVector2<T>;
126 template<
typename ArgType>
130 template<
typename ArgType>
137 template<
typename ArgType>
187
188
189
190
191
195 static_assert(
std::is_floating_point_v<T>,
"T must be floating point");
199 using Vector2Type =
UE::
Math::TVector2<T>;
206 template<
typename VType>
210
211
212
213
214 template<
typename VType>
227
228
229
230
231 template<
typename ArgType>
237 template<
typename ArgType>
244
245
246
247
248
252
253
254
255
256
287
288
289
290
291
292
296 static_assert(
std::is_floating_point_v<T>,
"T must be floating point");
300 using Vector2Type =
UE::
Math::TVector2<T>;
307 template<
typename VType>
311
312
313
314
315
316
317
318
319
320
321 template<
typename ArgType>
329
330
331 template<
typename ArgType>
337
338
339
340
341
342
343
344
345
346
347
348
349
355
356
357
358
390
391
392
393
397 static_assert(
std::is_floating_point_v<T>,
"T must be floating point");
401 using Vector2Type =
UE::
Math::TVector2<T>;
406 M[0][0] = 1; M[0][1] = 0;
407 M[1][0] = 0; M[1][1] = 1;
412 M[0][0] = m00; M[0][1] = m01;
413 M[1][0] = m10; M[1][1] = m11;
420 M[0][0] = UniformScale; M[0][1] = 0;
421 M[1][0] = 0; M[1][1] = UniformScale;
427 T ScaleX = (T)Scale.GetVector().X;
428 T ScaleY = (T)Scale.GetVector().Y;
429 M[0][0] = ScaleX; M[0][1] = 0;
430 M[1][0] = 0; M[1][1] = ScaleY;
436 T XX = (T)Shear.GetVector().X;
437 T YY = (T)Shear.GetVector().Y;
438 M[0][0] = 1; M[0][1] =YY;
439 M[1][0] =XX; M[1][1] = 1;
445 T CosAngle = (T)Rotation.GetVector().X;
446 T SinAngle = (T)Rotation.GetVector().Y;
447 M[0][0] = CosAngle; M[0][1] = SinAngle;
448 M[1][0] = -SinAngle; M[1][1] = CosAngle;
452
453
454
455
456 template<
typename ArgType>
459 return UE::Math::TVector2<ArgType>(
460 Point.X * (ArgType)M[0][0] + Point.Y * (ArgType)M[1][0],
461 Point.X * (ArgType)M[0][1] + Point.Y * (ArgType)M[1][1]);
464
465
466 template<
typename ArgType>
469 return TransformPoint(Vector);
472
473
474
475
479 GetMatrix(A, B, C, D);
481 RHS.GetMatrix(E, F, G, H);
483 A*E + B*G, A*F + B*H,
484 C*E + D*G, C*F + D*H);
487
488
492 GetMatrix(A, B, C, D);
493 T InvDet = InverseDeterminant();
496 -C*InvDet, A*InvDet);
503 GetMatrix(A, B, C, D);
505 RHS.GetMatrix(E, F, G, H);
516 return !operator==(Other);
519 void GetMatrix(
float& A,
float& B,
float& C,
float& D)
const
521 A = (
float)M[0][0]; B = (
float)M[0][1];
522 C = (
float)M[1][0]; D = (
float)M[1][1];
525 void GetMatrix(
double& A,
double& B,
double& C,
double& D)
const
527 A = (
double)M[0][0]; B = (
double)M[0][1];
528 C = (
double)M[1][0]; D = (
double)M[1][1];
534 GetMatrix(A, B, C, D);
540 T Det = Determinant();
549 GetMatrix(A, B, C, D);
550 return TScale2<T>(A*A + B*B, C*C + D*D);
556 TScale2<T> ScaleSquared = GetScaleSquared();
557 return TScale2<T>(FMath::Sqrt(ScaleSquared.GetVector().X), FMath::Sqrt(ScaleSquared.GetVector().Y));
564 GetMatrix(A, B, C, D);
565 return FMath::Atan(C / D);
571 return M[0][0] == 1.0f && M[0][1] == 0.0f
572 && M[1][0] == 0.0f && M[1][1] == 1.0f;
578 FMath::IsNearlyEqual(M[0][0], 1.0f, ErrorTolerance) &&
579 FMath::IsNearlyEqual(M[0][1], 0.0f, ErrorTolerance) &&
580 FMath::IsNearlyEqual(M[1][0], 0.0f, ErrorTolerance) &&
581 FMath::IsNearlyEqual(M[1][1], 1.0f, ErrorTolerance);
599 T XXB = (T)RHS.Shear.X;
600 T YYB = (T)RHS.Shear.Y;
601 return TMatrix2x2<T>(
609 T InvDet = 1.0f / T(1.0f - Shear.X*Shear.Y);
610 return TMatrix2x2<T>(
611 InvDet, T(-Shear.Y * InvDet),
612 T(-Shear.X * InvDet), InvDet);
636
637
638
639
640
641
645 static_assert(
std::is_floating_point_v<T>,
"T must be floating point");
649 using Vector2Type =
UE::
Math::TVector2<T>;
650 using Matrix2Type = TMatrix2x2<T>;
653 template<
typename VType =
float>
660 template<
typename VType =
float>
667 template<
typename VType =
float>
674 template<
typename VType =
float>
681 template<
typename VType =
float>
688 template<
typename VType =
float>
689 explicit TTransform2(
const TMatrix2x2<T>& Transform,
const UE::
Math::TVector2<VType>& Translation =
UE::
Math::TVector2<VType>(0.f, 0.f))
695
696
697 template<
typename VType>
704
705
706 template<
typename VType>
713
714
715
716
717
718
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
779 template<
typename VType>
783
784
791
792
827template<
typename T,
typename V>
830 return TTransform2<T>(Scale, Translation);
834template<
typename T,
typename V>
837 return TTransform2<T>(Shear, Translation);
841template<
typename T,
typename V>
844 return TTransform2<T>(Rot, Translation);
848template<
typename T,
typename V>
851 return TTransform2<T>(Transform, Translation);
855template<
typename T,
typename V>
858 return TTransform2<T>(Transform.GetMatrix(), Concatenate((UE::Math::TVector2<T>)Transform.GetTranslation(), (UE::Math::TVector2<T>)Translation));
862template<
typename T,
typename V>
865 return TTransform2<T>(Scale, ::TransformPoint(Scale, Translation));
869template<
typename T,
typename V>
872 return TTransform2<T>(Shear, ::TransformPoint(Shear, Translation));
876template<
typename T,
typename V>
879 return TTransform2<T>(Rot, ::TransformPoint(Rot, Translation));
883template<
typename T,
typename V>
886 return TTransform2<T>(Transform, ::TransformPoint(Transform, Translation));
890template<
typename T,
typename V>
893 return TTransform2<T>(Transform.GetMatrix(), Concatenate(::TransformPoint(Transform.GetMatrix(), (UE::Math::TVector2<T>)Translation), (UE::Math::TVector2<T>)Transform.GetTranslation()));
#define UE_KINDA_SMALL_NUMBER
bool operator!=(const TMatrix2x2 &Other) const
void GetMatrix(float &A, float &B, float &C, float &D) const
TScale2< T > GetScaleSquared() const
bool IsNearlyIdentity(T ErrorTolerance=UE_KINDA_SMALL_NUMBER) const
UE::Math::TVector2< ArgType > TransformPoint(const UE::Math::TVector2< ArgType > &Point) const
TMatrix2x2(const TScale2< T > &Scale)
TMatrix2x2(const FQuat2D &Rotation)
T InverseDeterminant() const
void GetMatrix(double &A, double &B, double &C, double &D) const
bool operator==(const TMatrix2x2 &RHS) const
TMatrix2x2(T UniformScale)
TMatrix2x2 Concatenate(const TMatrix2x2 &RHS) const
T GetRotationAngle() const
TMatrix2x2(T m00, T m01, T m10, T m11)
TMatrix2x2(const TShear2< T > &Shear)
UE::Math::TVector2< ArgType > TransformVector(const UE::Math::TVector2< ArgType > &Vector) const
TScale2< T > GetScale() const
TMatrix2x2 Inverse() const
UE::Math::TVector2< ArgType > TransformPoint(const UE::Math::TVector2< ArgType > &Point) const
bool operator==(const TQuat2 &Other) const
TQuat2(const UE::Math::TVector2< VType > &InRot)
const Vector2Type & GetVector() const
UE::Math::TVector2< ArgType > TransformVector(const UE::Math::TVector2< ArgType > &Vector) const
bool operator!=(const TQuat2 &Other) const
TQuat2 Concatenate(const TQuat2 &RHS) const
const Vector2Type & GetVector() const
TScale2(const UE::Math::TVector2< ArgType > &InScale)
UE::Math::TVector2< ArgType > TransformVector(const UE::Math::TVector2< ArgType > &Vector) const
bool operator==(const TScale2 &Other) const
TScale2(T InScaleX, T InScaleY)
bool operator!=(const TScale2 &Other) const
UE::Math::TVector2< ArgType > TransformPoint(const UE::Math::TVector2< ArgType > &Point) const
TScale2 Concatenate(const TScale2 &RHS) const
TMatrix2x2< T > Inverse() const
TShear2(T ShearX, T ShearY)
bool operator==(const TShear2 &Other) const
TShear2(const UE::Math::TVector2< VType > &InShear)
bool operator!=(const TShear2 &Other) const
TMatrix2x2< T > Concatenate(const TShear2 &RHS) const
static TShear2 FromShearAngles(const UE::Math::TVector2< VType > &InShearAngles)
UE::Math::TVector2< ArgType > TransformPoint(const UE::Math::TVector2< ArgType > &Point) const
const Vector2Type & GetVector() const
UE::Math::TVector2< ArgType > TransformVector(const UE::Math::TVector2< ArgType > &Vector) const
UE::Math::TVector2< T > Concatenate(const UE::Math::TVector2< T > &LHS, const UE::Math::TVector2< T > &RHS)
TMatrix2x2< T > ResultType
TMatrix2x2< T > ResultType
TMatrix2x2< T > ResultType
TMatrix2x2< T > ResultType
TMatrix2x2< T > ResultType
TMatrix2x2< T > ResultType
TMatrix2x2< T > ResultType
TMatrix2x2< T > ResultType
TMatrix2x2< T > ResultType
TMatrix2x2< T > ResultType
TMatrix2x2< T > ResultType
TMatrix2x2< T > ResultType
TMatrix2x2< T > ResultType
TMatrix2x2< T > ResultType
TMatrix2x2< T > ResultType
TMatrix2x2< T > ResultType