From 5b5b4f57fa5f338b606341c8bb4cbf319851784b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Fri, 21 Oct 2022 14:23:12 +0200 Subject: [PATCH] LibGfx: Add Size::aspect_ratio This can compute the aspect ratio of the size. It can use another type for these computations, which is important for integer sizes. --- Userland/Libraries/LibGfx/Size.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Userland/Libraries/LibGfx/Size.h b/Userland/Libraries/LibGfx/Size.h index e66c247656..200e764c5e 100644 --- a/Userland/Libraries/LibGfx/Size.h +++ b/Userland/Libraries/LibGfx/Size.h @@ -87,6 +87,12 @@ public: return size; } + [[nodiscard]] constexpr float aspect_ratio() const + { + VERIFY(height() != 0); + return static_cast(width()) / static_cast(height()); + } + template [[nodiscard]] constexpr bool contains(Size const& other) const {