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

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.
This commit is contained in:
kleines Filmröllchen 2022-10-21 14:23:12 +02:00 committed by Andrew Kaster
parent 2be89597a8
commit 5b5b4f57fa

View file

@ -87,6 +87,12 @@ public:
return size; return size;
} }
[[nodiscard]] constexpr float aspect_ratio() const
{
VERIFY(height() != 0);
return static_cast<float>(width()) / static_cast<float>(height());
}
template<typename U> template<typename U>
[[nodiscard]] constexpr bool contains(Size<U> const& other) const [[nodiscard]] constexpr bool contains(Size<U> const& other) const
{ {