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

LibGfx: Unify Rect, Point, and Size

This commit unifies methods and method/param names between the above
classes, as well as adds [[nodiscard]] and ALWAYS_INLINE where
appropriate. It also renamed the various move_by methods to
translate_by, as that more closely matches the transformation
terminology.
This commit is contained in:
Matthew Olsson 2021-04-12 11:47:09 -07:00 committed by Andreas Kling
parent ac238b3bd6
commit 88cfaf7bf0
48 changed files with 282 additions and 187 deletions

View file

@ -8,6 +8,7 @@
#include <AK/Format.h>
#include <LibGfx/Orientation.h>
#include <LibGfx/Point.h>
#include <LibIPC/Forward.h>
namespace Gfx {
@ -15,7 +16,7 @@ namespace Gfx {
template<typename T>
class Size {
public:
Size() { }
Size() = default;
Size(T w, T h)
: m_width(w)
@ -37,16 +38,54 @@ public:
{
}
bool is_null() const { return !m_width && !m_height; }
bool is_empty() const { return m_width <= 0 || m_height <= 0; }
[[nodiscard]] ALWAYS_INLINE T width() const { return m_width; }
[[nodiscard]] ALWAYS_INLINE T height() const { return m_height; }
[[nodiscard]] ALWAYS_INLINE T area() const { return width() * height(); }
T width() const { return m_width; }
T height() const { return m_height; }
ALWAYS_INLINE void set_width(T w) { m_width = w; }
ALWAYS_INLINE void set_height(T h) { m_height = h; }
T area() const { return width() * height(); }
[[nodiscard]] ALWAYS_INLINE bool is_null() const { return !m_width && !m_height; }
[[nodiscard]] ALWAYS_INLINE bool is_empty() const { return m_width <= 0 || m_height <= 0; }
void set_width(T w) { m_width = w; }
void set_height(T h) { m_height = h; }
void scale_by(T dx, T dy)
{
m_width *= dx;
m_height *= dy;
}
void transform_by(const AffineTransform& transform) { *this = transform.map(*this); }
ALWAYS_INLINE void scale_by(T dboth) { scale_by(dboth, dboth); }
ALWAYS_INLINE void scale_by(const Point<T>& s) { scale_by(s.x(), s.y()); }
Size scaled_by(T dx, T dy) const
{
Size<T> size = *this;
size.scale_by(dx, dy);
return size;
}
Size scaled_by(T dboth) const
{
Size<T> size = *this;
size.scale_by(dboth);
return size;
}
Size scaled_by(const Point<T>& s) const
{
Size<T> size = *this;
size.scale_by(s);
return size;
}
Size transformed_by(const AffineTransform& transform) const
{
Size<T> size = *this;
size.transform_by(transform);
return size;
}
template<typename U>
bool contains(const Size<U>& other) const
@ -118,7 +157,7 @@ public:
}
template<typename U>
Size<U> to_type() const
ALWAYS_INLINE Size<U> to_type() const
{
return Size<U>(*this);
}