-
Notifications
You must be signed in to change notification settings - Fork 0
/
extent.hpp
46 lines (37 loc) · 961 Bytes
/
extent.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once
#include <cstdint>
namespace nlrs
{
template<typename T>
struct Extent2
{
T x = T(0);
T y = T(0);
constexpr Extent2() noexcept = default;
constexpr Extent2(T xx, T yy) noexcept
: x(xx),
y(yy)
{
}
template<typename U>
constexpr explicit Extent2(const Extent2<U>& other) noexcept
: x(static_cast<T>(other.x)),
y(static_cast<T>(other.y))
{
}
constexpr bool operator==(const Extent2& rhs) const noexcept = default;
};
using Extent2i = Extent2<std::int32_t>;
using Extent2u = Extent2<std::uint32_t>;
using Extent2f = Extent2<float>;
template<typename T>
constexpr float aspectRatio(const Extent2<T>& extent) noexcept
{
return static_cast<float>(extent.x) / static_cast<float>(extent.y);
}
template<typename T>
constexpr bool operator==(const Extent2<T>& lhs, const Extent2<T>& rhs) noexcept
{
return lhs.x == rhs.x && lhs.y == rhs.y;
}
} // namespace nlrs