1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:27:43 +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
*/
#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()),
};
}
}