-
Notifications
You must be signed in to change notification settings - Fork 496
Expand file tree
/
Copy pathcoord2d.methods.inc
More file actions
45 lines (40 loc) · 1005 Bytes
/
coord2d.methods.inc
File metadata and controls
45 lines (40 loc) · 1005 Bytes
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
coord2d(int16_t _x, int16_t _y) : x(_x), y(_y) {}
bool isValid() const { return x >= 0; }
void clear() { x = y = -30000; }
bool operator==(const coord2d &other) const
{
return (x == other.x) && (y == other.y);
}
bool operator!=(const coord2d &other) const
{
return (x != other.x) || (y != other.y);
}
bool operator<(const coord2d &other) const
{
if (x != other.x) return (x < other.x);
return y < other.y;
}
coord2d operator+(const coord2d &other) const
{
return coord2d(x + other.x, y + other.y);
}
coord2d operator-(const coord2d &other) const
{
return coord2d(x - other.x, y - other.y);
}
coord2d operator/(int number) const
{
return coord2d((x < 0 ? x - number : x)/number, (y < 0 ? y - number : y)/number);
}
coord2d operator*(int number) const
{
return coord2d(x*number, y*number);
}
coord2d operator%(int number) const
{
return coord2d((x+number)%number, (y+number)%number);
}
coord2d operator&(int number) const
{
return coord2d(x&number, y&number);
}