1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 12:07:45 +00:00

LibGfx: Add AffineTransform::map_to_quad(Rect)

Unlike map(Rect) which returns a Rect, mapping a Rect to a Quad allows
us to represent the actual result of mapping all four corners of the
Rect through the matrix.
This commit is contained in:
Andreas Kling 2022-04-07 14:05:30 +02:00
parent 5d8f4ab878
commit 2af8bb14d7
2 changed files with 15 additions and 2 deletions

View file

@ -1,11 +1,12 @@
/* /*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <AK/Optional.h> #include <AK/Optional.h>
#include <LibGfx/AffineTransform.h> #include <LibGfx/AffineTransform.h>
#include <LibGfx/Quad.h>
#include <LibGfx/Rect.h> #include <LibGfx/Rect.h>
namespace Gfx { namespace Gfx {
@ -211,4 +212,14 @@ IntRect AffineTransform::map(IntRect const& rect) const
return enclosing_int_rect(map(FloatRect(rect))); return enclosing_int_rect(map(FloatRect(rect)));
} }
Quad<float> AffineTransform::map_to_quad(Rect<float> const& rect) const
{
return {
map(rect.top_left()),
map(rect.top_right()),
map(rect.bottom_right()),
map(rect.bottom_left()),
};
}
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2020-2022, Andreas Kling <kling@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -37,6 +37,8 @@ public:
template<typename T> template<typename T>
Rect<T> map(Rect<T> const&) const; Rect<T> map(Rect<T> const&) const;
Quad<float> map_to_quad(Rect<float> const&) const;
[[nodiscard]] ALWAYS_INLINE float a() const { return m_values[0]; } [[nodiscard]] ALWAYS_INLINE float a() const { return m_values[0]; }
[[nodiscard]] ALWAYS_INLINE float b() const { return m_values[1]; } [[nodiscard]] ALWAYS_INLINE float b() const { return m_values[1]; }
[[nodiscard]] ALWAYS_INLINE float c() const { return m_values[2]; } [[nodiscard]] ALWAYS_INLINE float c() const { return m_values[2]; }