mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
LibGfx: Add AffineTransform::inverse
This commit is contained in:
parent
a3c80f05ba
commit
9c97bd0de4
Notes:
sideshowbarker
2024-07-17 17:10:54 +09:00
Author: https://github.com/skyrising Commit: https://github.com/SerenityOS/serenity/commit/9c97bd0de4 Pull-request: https://github.com/SerenityOS/serenity/pull/13093 Reviewed-by: https://github.com/AtkinsSJ
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];
|
||||
|
|
|
@ -62,6 +62,8 @@ public:
|
|||
AffineTransform& rotate_radians(float);
|
||||
AffineTransform& multiply(const AffineTransform&);
|
||||
|
||||
Optional<AffineTransform> inverse() const;
|
||||
|
||||
private:
|
||||
float m_values[6] { 0 };
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue