summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/point.h57
2 files changed, 58 insertions, 0 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index eafb96b0b..7a4d9e354 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -154,6 +154,7 @@ add_library(common STATIC
154 param_package.cpp 154 param_package.cpp
155 param_package.h 155 param_package.h
156 parent_of_member.h 156 parent_of_member.h
157 point.h
157 quaternion.h 158 quaternion.h
158 ring_buffer.h 159 ring_buffer.h
159 scm_rev.cpp 160 scm_rev.cpp
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 @@
1// Copyright 2021 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <type_traits>
8
9namespace Common {
10
11// Represents a point within a 2D space.
12template <typename T>
13struct Point {
14 static_assert(std::is_arithmetic_v<T>, "T must be an arithmetic type!");
15
16 T x{};
17 T y{};
18
19#define ARITHMETIC_OP(op, compound_op) \
20 friend constexpr Point operator op(const Point& lhs, const Point& rhs) noexcept { \
21 return { \
22 .x = static_cast<T>(lhs.x op rhs.x), \
23 .y = static_cast<T>(lhs.y op rhs.y), \
24 }; \
25 } \
26 friend constexpr Point operator op(const Point& lhs, T value) noexcept { \
27 return { \
28 .x = static_cast<T>(lhs.x op value), \
29 .y = static_cast<T>(lhs.y op value), \
30 }; \
31 } \
32 friend constexpr Point operator op(T value, const Point& rhs) noexcept { \
33 return { \
34 .x = static_cast<T>(value op rhs.x), \
35 .y = static_cast<T>(value op rhs.y), \
36 }; \
37 } \
38 friend constexpr Point& operator compound_op(Point& lhs, const Point& rhs) noexcept { \
39 lhs.x = static_cast<T>(lhs.x op rhs.x); \
40 lhs.y = static_cast<T>(lhs.y op rhs.y); \
41 return lhs; \
42 } \
43 friend constexpr Point& operator compound_op(Point& lhs, T value) noexcept { \
44 lhs.x = static_cast<T>(lhs.x op value); \
45 lhs.y = static_cast<T>(lhs.y op value); \
46 return lhs; \
47 }
48 ARITHMETIC_OP(+, +=)
49 ARITHMETIC_OP(-, -=)
50 ARITHMETIC_OP(*, *=)
51 ARITHMETIC_OP(/, /=)
52#undef ARITHMETIC_OP
53
54 friend constexpr bool operator==(const Point&, const Point&) = default;
55};
56
57} // namespace Common