forked from rozukke/mcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoordinate.cpp
More file actions
97 lines (77 loc) · 2.54 KB
/
coordinate.cpp
File metadata and controls
97 lines (77 loc) · 2.54 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include "../include/mcpp/coordinate.h"
#include <string>
namespace mcpp {
Coordinate Coordinate::operator+(const Coordinate& obj) const {
Coordinate result;
result.x = this->x + obj.x;
result.y = this->y + obj.y;
result.z = this->z + obj.z;
return result;
}
Coordinate Coordinate::operator+(const Coordinate2D& obj) const {
Coordinate result;
result.x = this->x + obj.x;
result.y = this->y;
result.z = this->z + obj.z;
return result;
}
bool Coordinate::operator==(const Coordinate& obj) const {
return (this->x == obj.x) && (this->y == obj.y) && (this->z == obj.z);
}
bool Coordinate::operator!=(const Coordinate& obj) const { return !(*this == obj); }
Coordinate Coordinate::operator-(const Coordinate& obj) const {
Coordinate result;
result.x = this->x - obj.x;
result.y = this->y - obj.y;
result.z = this->z - obj.z;
return result;
}
std::size_t Coordinate::operator()(const mcpp::Coordinate& obj) const {
int lower = -3e7, upper = 3e7;
size_t base = upper - lower + 1;
size_t nx = obj.x - lower;
size_t ny = obj.y - lower;
size_t nz = obj.z - lower;
return nx * base * base + ny * base + nz;
}
std::string to_string(const Coordinate& coord) {
using std::to_string;
return "(" + to_string(coord.x) + "," + to_string(coord.y) + "," + to_string(coord.z) + ")";
}
std::ostream& operator<<(std::ostream& out, const Coordinate& coord) {
out << to_string(coord);
return out;
}
Coordinate Coordinate2D::with_height(int y) const { return Coordinate(this->x, y, this->z); }
Coordinate2D Coordinate2D::operator+(const Coordinate2D& obj) const {
Coordinate2D result;
result.x = this->x + obj.x;
result.z = this->z + obj.z;
return result;
}
bool Coordinate2D::operator==(const Coordinate2D& obj) const {
return (this->x == obj.x) && (this->z == obj.z);
}
bool Coordinate2D::operator!=(const Coordinate2D& obj) const { return !(*this == obj); }
Coordinate2D Coordinate2D::operator-(const Coordinate2D& obj) const {
Coordinate2D result;
result.x = this->x - obj.x;
result.z = this->z - obj.z;
return result;
}
std::size_t Coordinate2D::operator()(const mcpp::Coordinate2D& obj) const {
int lower = -3e7, upper = 3e7;
size_t base = upper - lower + 1;
size_t nx = obj.x - lower;
size_t nz = obj.z - lower;
return nx * base + nz;
}
std::string to_string(const Coordinate2D& coord) {
using std::to_string;
return "(" + to_string(coord.x) + "," + to_string(coord.z) + ")";
}
std::ostream& operator<<(std::ostream& out, const Coordinate2D& coord) {
out << to_string(coord);
return out;
}
} // namespace mcpp