mirror of
https://github.com/SerenityOS/serenity
synced 2024-09-06 17:06:31 +00:00
LibGfx: Add AffineTransform::determinant()
This commit is contained in:
parent
16b487c270
commit
9ecc78db1b
|
@ -134,18 +134,23 @@ AffineTransform& AffineTransform::rotate_radians(float radians)
|
|||
return *this;
|
||||
}
|
||||
|
||||
float AffineTransform::determinant() const
|
||||
{
|
||||
return a() * d() - b() * c();
|
||||
}
|
||||
|
||||
Optional<AffineTransform> AffineTransform::inverse() const
|
||||
{
|
||||
auto determinant = a() * d() - b() * c();
|
||||
if (determinant == 0)
|
||||
auto det = determinant();
|
||||
if (det == 0)
|
||||
return {};
|
||||
return AffineTransform {
|
||||
d() / determinant,
|
||||
-b() / determinant,
|
||||
-c() / determinant,
|
||||
a() / determinant,
|
||||
(c() * f() - d() * e()) / determinant,
|
||||
(b() * e() - a() * f()) / determinant,
|
||||
d() / det,
|
||||
-b() / det,
|
||||
-c() / det,
|
||||
a() / det,
|
||||
(c() * f() - d() * e()) / det,
|
||||
(b() * e() - a() * f()) / det,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -68,6 +68,7 @@ public:
|
|||
AffineTransform& skew_radians(float x_radians, float y_radians);
|
||||
AffineTransform& multiply(AffineTransform const&);
|
||||
|
||||
float determinant() const;
|
||||
Optional<AffineTransform> inverse() const;
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue