From 2af8bb14d7e3d7f9466d2160dd36158128e8714b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 7 Apr 2022 14:05:30 +0200 Subject: [PATCH] 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. --- Userland/Libraries/LibGfx/AffineTransform.cpp | 13 ++++++++++++- Userland/Libraries/LibGfx/AffineTransform.h | 4 +++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibGfx/AffineTransform.cpp b/Userland/Libraries/LibGfx/AffineTransform.cpp index 1c60eb508d..7347df38a5 100644 --- a/Userland/Libraries/LibGfx/AffineTransform.cpp +++ b/Userland/Libraries/LibGfx/AffineTransform.cpp @@ -1,11 +1,12 @@ /* - * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2020-2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include #include +#include #include namespace Gfx { @@ -211,4 +212,14 @@ IntRect AffineTransform::map(IntRect const& rect) const return enclosing_int_rect(map(FloatRect(rect))); } +Quad AffineTransform::map_to_quad(Rect const& rect) const +{ + return { + map(rect.top_left()), + map(rect.top_right()), + map(rect.bottom_right()), + map(rect.bottom_left()), + }; +} + } diff --git a/Userland/Libraries/LibGfx/AffineTransform.h b/Userland/Libraries/LibGfx/AffineTransform.h index 87a8f30b7a..5069c6ae57 100644 --- a/Userland/Libraries/LibGfx/AffineTransform.h +++ b/Userland/Libraries/LibGfx/AffineTransform.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020, Andreas Kling + * Copyright (c) 2020-2022, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ @@ -37,6 +37,8 @@ public: template Rect map(Rect const&) const; + Quad map_to_quad(Rect 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]; }