mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:07:45 +00:00
LibGfx: Add AffineTransform::inverse
This commit is contained in:
parent
a3c80f05ba
commit
9c97bd0de4
2 changed files with 17 additions and 0 deletions
|
@ -125,6 +125,21 @@ AffineTransform& AffineTransform::rotate_radians(float radians)
|
||||||
return *this;
|
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
|
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];
|
mapped_x = a() * unmapped_x + b() * unmapped_y + m_values[4];
|
||||||
|
|
|
@ -62,6 +62,8 @@ public:
|
||||||
AffineTransform& rotate_radians(float);
|
AffineTransform& rotate_radians(float);
|
||||||
AffineTransform& multiply(const AffineTransform&);
|
AffineTransform& multiply(const AffineTransform&);
|
||||||
|
|
||||||
|
Optional<AffineTransform> inverse() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float m_values[6] { 0 };
|
float m_values[6] { 0 };
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue