1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:57:35 +00:00

LibGfx: Templatize Point, Size, and Rect

This commit is contained in:
Matthew Olsson 2020-07-25 21:31:47 -07:00 committed by Andreas Kling
parent 7a1c328417
commit 335916d8db
33 changed files with 404 additions and 835 deletions

View file

@ -27,7 +27,6 @@
#include <AK/LogStream.h>
#include <AK/Optional.h>
#include <LibGfx/AffineTransform.h>
#include <LibGfx/FloatRect.h>
#include <LibGfx/Rect.h>
namespace Gfx {
@ -97,37 +96,36 @@ void AffineTransform::map(float unmapped_x, float unmapped_y, float& mapped_x, f
mapped_y = (m_values[1] * unmapped_x + m_values[3] * unmapped_y + m_values[5]);
}
template<>
IntPoint AffineTransform::map(const IntPoint& point) const
{
float mapped_x;
float mapped_y;
map(point.x(), point.y(), mapped_x, mapped_y);
return IntPoint(roundf(mapped_x), roundf(mapped_y));
return { roundf(mapped_x), roundf(mapped_y) };
}
template<>
FloatPoint AffineTransform::map(const FloatPoint& point) const
{
float mapped_x;
float mapped_y;
map(point.x(), point.y(), mapped_x, mapped_y);
return FloatPoint(mapped_x, mapped_y);
return { mapped_x, mapped_y };
}
template<>
IntSize AffineTransform::map(const IntSize& size) const
{
return IntSize(roundf(size.width() * x_scale()), roundf(y_scale()));
return { roundf(size.width() * x_scale()), roundf(size.height() * y_scale()) };
}
template<>
FloatSize AffineTransform::map(const FloatSize& size) const
{
return { size.width() * x_scale(), size.height() * y_scale() };
}
IntRect AffineTransform::map(const IntRect& rect) const
{
return enclosing_int_rect(map(FloatRect(rect)));
}
template<typename T>
static T smallest_of(T p1, T p2, T p3, T p4)
{
@ -140,6 +138,7 @@ static T largest_of(T p1, T p2, T p3, T p4)
return max(max(p1, p2), max(p3, p4));
}
template<>
FloatRect AffineTransform::map(const FloatRect& rect) const
{
FloatPoint p1 = map(rect.top_left());
@ -153,6 +152,12 @@ FloatRect AffineTransform::map(const FloatRect& rect) const
return { left, top, right - left, bottom - top };
}
template<>
IntRect AffineTransform::map(const IntRect& rect) const
{
return enclosing_int_rect(map(FloatRect(rect)));
}
const LogStream& operator<<(const LogStream& stream, const AffineTransform& value)
{
if (value.is_identity())