From 7278ff66051f9b71403c28521c3f07c11d4e8ff5 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Fri, 22 Jan 2021 15:12:37 -0500 Subject: [PATCH] LibGfx: Allow comparing Points, Sizes, and Rects of different type --- Userland/Libraries/LibGfx/Point.h | 8 +++++--- Userland/Libraries/LibGfx/Rect.h | 8 +++++--- Userland/Libraries/LibGfx/Size.h | 8 +++++--- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Userland/Libraries/LibGfx/Point.h b/Userland/Libraries/LibGfx/Point.h index 753d04055a..be6a71e149 100644 --- a/Userland/Libraries/LibGfx/Point.h +++ b/Userland/Libraries/LibGfx/Point.h @@ -107,12 +107,14 @@ public: return point; } - bool operator==(const Point& other) const + template + bool operator==(const Point& other) const { - return m_x == other.m_x && m_y == other.m_y; + return x() == other.x() && y() == other.y(); } - bool operator!=(const Point& other) const + template + bool operator!=(const Point& other) const { return !(*this == other); } diff --git a/Userland/Libraries/LibGfx/Rect.h b/Userland/Libraries/LibGfx/Rect.h index f54ff43fbf..e9ad4b136e 100644 --- a/Userland/Libraries/LibGfx/Rect.h +++ b/Userland/Libraries/LibGfx/Rect.h @@ -354,12 +354,14 @@ public: Vector, 4> shatter(const Rect& hammer) const; - bool operator==(const Rect& other) const + template + bool operator==(const Rect& other) const { - return m_location == other.m_location && m_size == other.m_size; + return location() == other.location() && size() == other.size(); } - bool operator!=(const Rect& other) const + template + bool operator!=(const Rect& other) const { return !(*this == other); } diff --git a/Userland/Libraries/LibGfx/Size.h b/Userland/Libraries/LibGfx/Size.h index 7b0cbe96fc..67321a4a2d 100644 --- a/Userland/Libraries/LibGfx/Size.h +++ b/Userland/Libraries/LibGfx/Size.h @@ -74,12 +74,14 @@ public: return other.m_width <= m_width && other.m_height <= m_height; } - bool operator==(const Size& other) const + template + bool operator==(const Size& other) const { - return m_width == other.m_width && m_height == other.m_height; + return width() == other.width() && height() == other.height(); } - bool operator!=(const Size& other) const + template + bool operator!=(const Size& other) const { return !(*this == other); }