mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:27: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;
|
||||
}
|
||||
|
||||
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];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue