summaryrefslogtreecommitdiffstats
path: root/src/common/point.h
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2021-05-30 10:35:26 +0200
committerGitHub <noreply@github.com>2021-05-30 10:35:26 +0200
commita5ebba7e366dcd2b8818c6748296ca5fdeb45ad2 (patch)
treeb6be6dbfb6f5b4199cb5accaeba43493d80b2f7e /src/common/point.h
parentMerge pull request #6387 from lioncash/class-token (diff)
parenttouchscreen: Make use of common point struct (diff)
downloadyuzu-a5ebba7e366dcd2b8818c6748296ca5fdeb45ad2.tar
yuzu-a5ebba7e366dcd2b8818c6748296ca5fdeb45ad2.tar.gz
yuzu-a5ebba7e366dcd2b8818c6748296ca5fdeb45ad2.tar.bz2
yuzu-a5ebba7e366dcd2b8818c6748296ca5fdeb45ad2.tar.lz
yuzu-a5ebba7e366dcd2b8818c6748296ca5fdeb45ad2.tar.xz
yuzu-a5ebba7e366dcd2b8818c6748296ca5fdeb45ad2.tar.zst
yuzu-a5ebba7e366dcd2b8818c6748296ca5fdeb45ad2.zip
Diffstat (limited to 'src/common/point.h')
-rw-r--r--src/common/point.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/common/point.h b/src/common/point.h
new file mode 100644
index 000000000..c0a52ad8d
--- /dev/null
+++ b/src/common/point.h
@@ -0,0 +1,57 @@
+// Copyright 2021 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <type_traits>
+
+namespace Common {
+
+// Represents a point within a 2D space.
+template <typename T>
+struct Point {
+ static_assert(std::is_arithmetic_v<T>, "T must be an arithmetic type!");
+
+ T x{};
+ T y{};
+
+#define ARITHMETIC_OP(op, compound_op) \
+ friend constexpr Point operator op(const Point& lhs, const Point& rhs) noexcept { \
+ return { \
+ .x = static_cast<T>(lhs.x op rhs.x), \
+ .y = static_cast<T>(lhs.y op rhs.y), \
+ }; \
+ } \
+ friend constexpr Point operator op(const Point& lhs, T value) noexcept { \
+ return { \
+ .x = static_cast<T>(lhs.x op value), \
+ .y = static_cast<T>(lhs.y op value), \
+ }; \
+ } \
+ friend constexpr Point operator op(T value, const Point& rhs) noexcept { \
+ return { \
+ .x = static_cast<T>(value op rhs.x), \
+ .y = static_cast<T>(value op rhs.y), \
+ }; \
+ } \
+ friend constexpr Point& operator compound_op(Point& lhs, const Point& rhs) noexcept { \
+ lhs.x = static_cast<T>(lhs.x op rhs.x); \
+ lhs.y = static_cast<T>(lhs.y op rhs.y); \
+ return lhs; \
+ } \
+ friend constexpr Point& operator compound_op(Point& lhs, T value) noexcept { \
+ lhs.x = static_cast<T>(lhs.x op value); \
+ lhs.y = static_cast<T>(lhs.y op value); \
+ return lhs; \
+ }
+ ARITHMETIC_OP(+, +=)
+ ARITHMETIC_OP(-, -=)
+ ARITHMETIC_OP(*, *=)
+ ARITHMETIC_OP(/, /=)
+#undef ARITHMETIC_OP
+
+ friend constexpr bool operator==(const Point&, const Point&) = default;
+};
+
+} // namespace Common