mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 10:47:35 +00:00
LibGfx: Add small convenience functions for Lines and AA Painter
This patch adds the following some convenience functions: - Lines do now support rotated(), scaled() and translated() - AntiAliasingPainter has now a draw_line function that takes a FloatLine as argument
This commit is contained in:
parent
95c469ca4c
commit
e7ceaf8a6d
2 changed files with 31 additions and 0 deletions
|
@ -129,9 +129,36 @@ public:
|
|||
Point<T> const& a() const { return m_a; }
|
||||
Point<T> const& b() const { return m_b; }
|
||||
|
||||
Line<T> rotated(float radians)
|
||||
{
|
||||
Gfx::AffineTransform rotation_transform;
|
||||
rotation_transform.rotate_radians(radians);
|
||||
|
||||
Line<T> line = *this;
|
||||
line.set_a(line.a().transformed(rotation_transform));
|
||||
line.set_b(line.b().transformed(rotation_transform));
|
||||
return line;
|
||||
}
|
||||
|
||||
void set_a(Point<T> const& a) { m_a = a; }
|
||||
void set_b(Point<T> const& b) { m_b = b; }
|
||||
|
||||
Line<T> scaled(T sx, T sy) const
|
||||
{
|
||||
Line<T> line = *this;
|
||||
line.set_a(line.a().scaled(sx, sy));
|
||||
line.set_b(line.b().scaled(sx, sy));
|
||||
return line;
|
||||
}
|
||||
|
||||
Line<T> translated(Point<T> const& delta) const
|
||||
{
|
||||
Line<T> line = *this;
|
||||
line.set_a(line.a().translated(delta));
|
||||
line.set_b(line.b().translated(delta));
|
||||
return line;
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
requires(!IsSame<T, U>)
|
||||
[[nodiscard]] ALWAYS_INLINE constexpr Line<U> to_type() const
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue