mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:57:45 +00:00
LibGfx: Add AffineTransform::rotation()
Extracts the rotation from a 2D matrix.
This commit is contained in:
parent
8c1dacecba
commit
a77accf3f4
2 changed files with 12 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Math.h>
|
||||
#include <AK/Optional.h>
|
||||
#include <LibGfx/AffineTransform.h>
|
||||
#include <LibGfx/Quad.h>
|
||||
|
@ -229,4 +230,14 @@ Quad<float> AffineTransform::map_to_quad(Rect<float> const& rect) const
|
|||
};
|
||||
}
|
||||
|
||||
float AffineTransform::rotation() const
|
||||
{
|
||||
auto rotation = AK::atan2(b(), a());
|
||||
while (rotation < -AK::Pi<float>)
|
||||
rotation += 2.0f * AK::Pi<float>;
|
||||
while (rotation > AK::Pi<float>)
|
||||
rotation -= 2.0f * AK::Pi<float>;
|
||||
return rotation;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -54,6 +54,7 @@ public:
|
|||
[[nodiscard]] float x_translation() const;
|
||||
[[nodiscard]] float y_translation() const;
|
||||
[[nodiscard]] FloatPoint translation() const;
|
||||
[[nodiscard]] float rotation() const;
|
||||
|
||||
AffineTransform& scale(float sx, float sy);
|
||||
AffineTransform& scale(FloatPoint s);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue