mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:17:35 +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:
parent
5d8f4ab878
commit
2af8bb14d7
2 changed files with 15 additions and 2 deletions
|
@ -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
|
||||
*/
|
||||
|
||||
#include <AK/Optional.h>
|
||||
#include <LibGfx/AffineTransform.h>
|
||||
#include <LibGfx/Quad.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
@ -211,4 +212,14 @@ IntRect AffineTransform::map(IntRect const& rect) const
|
|||
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()),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
*/
|
||||
|
@ -37,6 +37,8 @@ public:
|
|||
template<typename T>
|
||||
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 b() const { return m_values[1]; }
|
||||
[[nodiscard]] ALWAYS_INLINE float c() const { return m_values[2]; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue