2014-12-17 08:38:14 +03:00
|
|
|
// Copyright 2013 Dolphin Emulator Project / 2014 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
2013-09-05 04:17:46 +04:00
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2014-08-17 21:45:50 +04:00
|
|
|
#pragma once
|
2013-09-05 04:17:46 +04:00
|
|
|
|
2015-05-14 17:16:15 +03:00
|
|
|
#include <cstdlib>
|
2014-11-13 22:25:39 +03:00
|
|
|
#include <type_traits>
|
2013-09-05 04:17:46 +04:00
|
|
|
|
2019-02-27 06:47:49 +03:00
|
|
|
namespace Common {
|
2013-09-05 04:17:46 +04:00
|
|
|
|
2020-09-02 18:58:15 +03:00
|
|
|
constexpr float PI = 3.1415926535f;
|
2016-12-12 00:27:30 +03:00
|
|
|
|
2016-09-18 03:38:01 +03:00
|
|
|
template <class T>
|
|
|
|
struct Rectangle {
|
2018-08-02 17:47:31 +03:00
|
|
|
T left{};
|
|
|
|
T top{};
|
|
|
|
T right{};
|
|
|
|
T bottom{};
|
2014-04-02 02:20:08 +04:00
|
|
|
|
2018-11-21 09:57:32 +03:00
|
|
|
constexpr Rectangle() = default;
|
2014-04-02 02:20:08 +04:00
|
|
|
|
2020-10-14 09:51:14 +03:00
|
|
|
constexpr Rectangle(T left_, T top_, T right_, T bottom_)
|
|
|
|
: left(left_), top(top_), right(right_), bottom(bottom_) {}
|
2014-04-02 02:20:08 +04:00
|
|
|
|
2020-08-14 16:38:45 +03:00
|
|
|
[[nodiscard]] T GetWidth() const {
|
2019-12-26 07:42:31 +03:00
|
|
|
if constexpr (std::is_floating_point_v<T>) {
|
|
|
|
return std::abs(right - left);
|
|
|
|
} else {
|
2020-10-22 05:14:21 +03:00
|
|
|
return static_cast<T>(std::abs(static_cast<std::make_signed_t<T>>(right - left)));
|
2019-12-26 07:42:31 +03:00
|
|
|
}
|
2016-09-18 03:38:01 +03:00
|
|
|
}
|
2019-12-26 07:42:31 +03:00
|
|
|
|
2020-08-14 16:38:45 +03:00
|
|
|
[[nodiscard]] T GetHeight() const {
|
2019-12-26 07:42:31 +03:00
|
|
|
if constexpr (std::is_floating_point_v<T>) {
|
|
|
|
return std::abs(bottom - top);
|
|
|
|
} else {
|
2020-10-22 05:14:21 +03:00
|
|
|
return static_cast<T>(std::abs(static_cast<std::make_signed_t<T>>(bottom - top)));
|
2019-12-26 07:42:31 +03:00
|
|
|
}
|
2016-09-18 03:38:01 +03:00
|
|
|
}
|
2019-12-26 07:42:31 +03:00
|
|
|
|
2020-08-14 16:38:45 +03:00
|
|
|
[[nodiscard]] Rectangle<T> TranslateX(const T x) const {
|
2016-11-05 10:47:05 +03:00
|
|
|
return Rectangle{left + x, top, right + x, bottom};
|
|
|
|
}
|
2019-12-26 07:42:31 +03:00
|
|
|
|
2020-08-14 16:38:45 +03:00
|
|
|
[[nodiscard]] Rectangle<T> TranslateY(const T y) const {
|
2016-11-05 10:47:05 +03:00
|
|
|
return Rectangle{left, top + y, right, bottom + y};
|
|
|
|
}
|
2019-12-26 07:42:31 +03:00
|
|
|
|
2020-08-14 16:38:45 +03:00
|
|
|
[[nodiscard]] Rectangle<T> Scale(const float s) const {
|
2021-10-20 01:33:03 +03:00
|
|
|
return Rectangle{left, top, static_cast<T>(static_cast<float>(left + GetWidth()) * s),
|
|
|
|
static_cast<T>(static_cast<float>(top + GetHeight()) * s)};
|
2016-11-05 10:47:05 +03:00
|
|
|
}
|
2013-09-05 04:17:46 +04:00
|
|
|
};
|
|
|
|
|
2019-05-29 09:47:01 +03:00
|
|
|
template <typename T>
|
2020-08-11 18:08:10 +03:00
|
|
|
Rectangle(T, T, T, T) -> Rectangle<T>;
|
2019-05-29 09:47:01 +03:00
|
|
|
|
2019-02-27 06:47:49 +03:00
|
|
|
} // namespace Common
|