-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIvec2.h
More file actions
84 lines (76 loc) · 1.51 KB
/
Ivec2.h
File metadata and controls
84 lines (76 loc) · 1.51 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#pragma once
#include <iostream>
class Ivec2
{
public:
Ivec2()
{
x = 0;
y = 0;
}
Ivec2(const Ivec2& _vec)
{
x = _vec.x;
y = _vec.y;
}
Ivec2(int _x, int _y)
{
x = _x;
y = _y;
}
~Ivec2()
{
}
Ivec2 operator+(const Ivec2& _vec) const
{
return Ivec2(x + _vec.x, y + _vec.y);
}
Ivec2 operator-(const Ivec2& _vec) const
{
return Ivec2(x - _vec.x, y - _vec.y);
}
Ivec2 operator*(const Ivec2& _vec) const
{
return Ivec2(x * _vec.x, y * _vec.y);
}
Ivec2 operator/(const Ivec2& _vec) const
{
if (_vec.x == 0 || _vec.y == 0) {
std::cerr << "Error: Division by zero." << std::endl;
}
return Ivec2(x / _vec.x, y / _vec.y);
}
bool operator==(const Ivec2& _vec) const
{
return (x == _vec.x) && (y == _vec.y);
}
bool operator!=(const Ivec2& _vec) const
{
return !(*this == _vec);
}
Ivec2 left()
{
return Ivec2(x - 1, y);
}
Ivec2 right()
{
return Ivec2(x + 1, y);
}
Ivec2 up()
{
return Ivec2(x, y - 1);
}
Ivec2 down()
{
return Ivec2(x, y + 1);
}
/// @brief ここから引数までのマンハッタン距離を返す
/// @param _vec もう一つの座標
/// @return マンハッタン距離
int manhattan(class Ivec2 _vec)
{
return abs(x - _vec.x) + abs(y - _vec.y);
}
int x, y;
private:
};