summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGfx/Vector2.h
diff options
context:
space:
mode:
authorJelle Raaijmakers <jelle@gmta.nl>2021-05-15 01:31:28 +0200
committerLinus Groh <mail@linusgroh.de>2021-05-15 00:41:30 +0100
commit5864aab87a1bd609cf5ebc492e37abd48ae8b88e (patch)
treee0384e6f2bbf6f9bb70d14cd23b3d20f19f9452f /Userland/Libraries/LibGfx/Vector2.h
parent9459f3728ce6cff9d371a637618efcd5ed591e66 (diff)
downloadserenity-5864aab87a1bd609cf5ebc492e37abd48ae8b88e.zip
LibGfx/Vector*: Implement Formatters
Diffstat (limited to 'Userland/Libraries/LibGfx/Vector2.h')
-rw-r--r--Userland/Libraries/LibGfx/Vector2.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGfx/Vector2.h b/Userland/Libraries/LibGfx/Vector2.h
index 2994bf1b42..a796f3c750 100644
--- a/Userland/Libraries/LibGfx/Vector2.h
+++ b/Userland/Libraries/LibGfx/Vector2.h
@@ -6,6 +6,7 @@
#pragma once
+#include <AK/String.h>
#include <math.h>
namespace Gfx {
@@ -107,6 +108,11 @@ public:
return sqrt(m_x * m_x + m_y * m_y);
}
+ constexpr String to_string() const
+ {
+ return String::formatted("[{},{}]", x(), y());
+ }
+
private:
T m_x;
T m_y;
@@ -117,6 +123,18 @@ typedef Vector2<double> DoubleVector2;
}
+namespace AK {
+
+template<typename T>
+struct Formatter<Gfx::Vector2<T>> : Formatter<StringView> {
+ void format(FormatBuilder& builder, const Gfx::Vector2<T>& value)
+ {
+ Formatter<StringView>::format(builder, value.to_string());
+ }
+};
+
+}
+
using Gfx::DoubleVector2;
using Gfx::FloatVector2;
using Gfx::Vector2;