diff options
author | Matthew Olsson <matthewcolsson@gmail.com> | 2020-07-25 21:31:47 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-07-27 01:06:26 +0200 |
commit | 335916d8db8421565c4cc232b36a397d6a7fb864 (patch) | |
tree | cbc8215d0f07d1eb014f0b2287d3d4f5aa16419c /Libraries/LibGfx/Point.cpp | |
parent | 7a1c328417972efc33af8bc7cbc745340369a8f0 (diff) | |
download | serenity-335916d8db8421565c4cc232b36a397d6a7fb864.zip |
LibGfx: Templatize Point, Size, and Rect
Diffstat (limited to 'Libraries/LibGfx/Point.cpp')
-rw-r--r-- | Libraries/LibGfx/Point.cpp | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/Libraries/LibGfx/Point.cpp b/Libraries/LibGfx/Point.cpp index b575dbafb5..5dba69ad00 100644 --- a/Libraries/LibGfx/Point.cpp +++ b/Libraries/LibGfx/Point.cpp @@ -26,26 +26,38 @@ #include <AK/String.h> #include <LibGfx/Point.h> -#include <LibGfx/FloatPoint.h> +#include <LibGfx/Rect.h> #include <LibIPC/Decoder.h> #include <LibIPC/Encoder.h> namespace Gfx { -IntPoint::IntPoint(const FloatPoint& other) - : m_x(other.x()) - , m_y(other.y()) +template<typename T> +void Point<T>::constrain(const Rect<T>& rect) { + if (x() < rect.left()) { + set_x(rect.left()); + } else if (x() > rect.right()) { + set_x(rect.right()); + } + + if (y() < rect.top()) { + set_y(rect.top()); + } else if (y() > rect.bottom()) { + set_y(rect.bottom()); + } } +template<> String IntPoint::to_string() const { return String::format("[%d,%d]", x(), y()); } -const LogStream& operator<<(const LogStream& stream, const IntPoint& value) +template<> +String FloatPoint::to_string() const { - return stream << value.to_string(); + return String::format("[%f,%f]", x(), y()); } } @@ -71,3 +83,6 @@ bool decode(Decoder& decoder, Gfx::IntPoint& point) } } + +template class Gfx::Point<int>; +template class Gfx::Point<float>; |