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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#pragma once
#include <Cplt/Utils/Vector.hpp>
template <class T>
class Size2 {
public:
T width;
T height;
public:
Size2()
: width{ 0 }, height{ 0 } {
}
Size2(T width, T height)
: width{ width }, height{ height } {
}
Size2(Vec2<T> vec)
: width{ vec.x }, height{ vec.y } {
}
operator Vec2<T>() const {
return { width, height };
}
Vec2<T> AsVec() const {
return { width, height };
}
friend bool operator==(const Size2<T>&, const Size2<T>&) = default;
template <class TTarget>
Size2<TTarget> Cast() const {
return {
static_cast<TTarget>(width),
static_cast<TTarget>(height),
};
}
};
template <class T>
Size2<T> operator+(Size2<T> a, Size2<T> b) {
return { a.width + b.width, a.height + b.height };
}
template <class T>
Size2<T> operator-(Size2<T> a, Size2<T> b) {
return { a.width - b.width, a.height - b.height };
}
template <class T, class N>
auto operator*(Size2<T> a, N mult) -> Size2<decltype(a.width * mult)> {
return { a.width * mult, a.height * mult };
}
template <class T, class N>
auto operator/(Size2<T> a, N mult) -> Size2<decltype(a.width / mult)> {
return { a.width / mult, a.height / mult };
}
|