summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGfx/AffineTransform.cpp15
-rw-r--r--Userland/Libraries/LibGfx/AffineTransform.h2
2 files changed, 17 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/AffineTransform.cpp b/Userland/Libraries/LibGfx/AffineTransform.cpp
index f0c9df2382..2bd8f15f0c 100644
--- a/Userland/Libraries/LibGfx/AffineTransform.cpp
+++ b/Userland/Libraries/LibGfx/AffineTransform.cpp
@@ -125,6 +125,21 @@ AffineTransform& AffineTransform::rotate_radians(float radians)
return *this;
}
+Optional<AffineTransform> AffineTransform::inverse() const
+{
+ auto determinant = a() * d() - b() * c();
+ if (determinant == 0)
+ return {};
+ return AffineTransform {
+ d() / determinant,
+ -b() / determinant,
+ -c() / determinant,
+ a() / determinant,
+ (c() * f() - d() * e()) / determinant,
+ (b() * e() - a() * f()) / determinant,
+ };
+}
+
void AffineTransform::map(float unmapped_x, float unmapped_y, float& mapped_x, float& mapped_y) const
{
mapped_x = a() * unmapped_x + b() * unmapped_y + m_values[4];
diff --git a/Userland/Libraries/LibGfx/AffineTransform.h b/Userland/Libraries/LibGfx/AffineTransform.h
index 1ec3ace816..c2fc79820e 100644
--- a/Userland/Libraries/LibGfx/AffineTransform.h
+++ b/Userland/Libraries/LibGfx/AffineTransform.h
@@ -62,6 +62,8 @@ public:
AffineTransform& rotate_radians(float);
AffineTransform& multiply(const AffineTransform&);
+ Optional<AffineTransform> inverse() const;
+
private:
float m_values[6] { 0 };
};