diff options
author | Lioncash <mathew1800@gmail.com> | 2021-05-28 13:14:14 +0200 |
---|---|---|
committer | Lioncash <mathew1800@gmail.com> | 2021-05-28 14:12:49 +0200 |
commit | 8171ad65cd9f170dd9f72d1256415ebd34979d36 (patch) | |
tree | 4d8e7de9508fb37c6779c9d2e92875a12626bb26 /src/common | |
parent | Merge pull request #6375 from lioncash/iofs (diff) | |
download | yuzu-8171ad65cd9f170dd9f72d1256415ebd34979d36.tar yuzu-8171ad65cd9f170dd9f72d1256415ebd34979d36.tar.gz yuzu-8171ad65cd9f170dd9f72d1256415ebd34979d36.tar.bz2 yuzu-8171ad65cd9f170dd9f72d1256415ebd34979d36.tar.lz yuzu-8171ad65cd9f170dd9f72d1256415ebd34979d36.tar.xz yuzu-8171ad65cd9f170dd9f72d1256415ebd34979d36.tar.zst yuzu-8171ad65cd9f170dd9f72d1256415ebd34979d36.zip |
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/common/point.h | 57 |
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 param_package.cpp param_package.h parent_of_member.h + point.h quaternion.h ring_buffer.h 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 @@ +// 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 |