Skip to content

Commit ce1c51d

Browse files
committed
Use Coordinate2D for height-related functions
1 parent 6c67d4a commit ce1c51d

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

include/mcpp/mcpp.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,30 +125,30 @@ class MinecraftConnection {
125125
Chunk getBlocks(const Coordinate& loc1, const Coordinate& loc2);
126126

127127
/**
128-
* @brief Returns the height of the specific provided x and z coordinate
128+
* @brief Returns the height of the specific provided 2D coordinate
129129
*
130130
* ***IMPORTANT:***
131131
* DO NOT USE FOR LARGE AREAS, IT WILL BE VERY SLOW
132132
* USE getHeights() INSTEAD
133133
*
134-
* Gets the y-value of the highest non-air block at the specified (x, z)
134+
* Gets the y-value of the highest non-air block at the specified 2D
135135
* coordinate.
136-
* @param x
137-
* @param z
136+
* @param loc 2D coordinate
138137
* @return Returns the integer y-height at the requested coordinate.
139138
*/
140-
int getHeight(int x, int z);
139+
int getHeight(Coordinate2D loc);
141140

142141
/**
143142
* @brief Provides a scaled option of the getHeight call to allow for
144143
* considerable performance gains.
145144
*
146145
* \par USE THIS instead of getHeight in a for loop.
147146
*
148-
* @param loc1
149-
* @param loc2
147+
* @param loc1 1st corner of rectangle
148+
* @param loc2 2nd corner of rectangle
150149
* @return Returns a vector of integers representing the 2D area of heights.
151150
*/
152-
const HeightMap getHeights(const Coordinate& loc1, const Coordinate& loc2);
151+
const HeightMap getHeights(const Coordinate2D& loc1,
152+
const Coordinate2D& loc2);
153153
};
154154
} // namespace mcpp

include/mcpp/util.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ struct HeightMap {
451451

452452
Iterator begin() { return Iterator(&raw_heights[0]); }
453453
Iterator end() { return Iterator(&raw_heights[_x_len * _z_len]); }
454-
HeightMap(const Coordinate& loc1, const Coordinate& loc2,
454+
HeightMap(const Coordinate2D& loc1, const Coordinate2D& loc2,
455455
const std::vector<int>& heights);
456456

457457
~HeightMap();
@@ -469,10 +469,10 @@ struct HeightMap {
469469

470470
/**
471471
* Get the height at a Minecraft coordinate if saved inside the height map
472-
* @param loc: Coordinate in Minecraft world to access in the map
472+
* @param loc: 2D coordinate in Minecraft world to access in the map
473473
* @return: height at specified coordinate
474474
*/
475-
int get_worldspace(const Coordinate& loc) const;
475+
int get_worldspace(const Coordinate2D& loc) const;
476476

477477
/**
478478
* Fill a coordinate inplace with the highest y coordinate at the `loc`'s x
@@ -494,13 +494,13 @@ struct HeightMap {
494494
int z_len() const;
495495

496496
/**
497-
* Gets the minimum coordinate in the HeightMap.
498-
* @return the minimum coordinate in the HeightMap.
497+
* Gets the minimum 2D coordinate in the HeightMap.
498+
* @return the minimum 2D coordinate in the HeightMap.
499499
*/
500-
Coordinate base_pt() const;
500+
Coordinate2D base_pt() const;
501501

502502
private:
503-
Coordinate _base_pt;
503+
Coordinate2D _base_pt;
504504
int _x_len;
505505
int _z_len;
506506
int* raw_heights;

src/mcpp.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,14 @@ Chunk MinecraftConnection::getBlocks(const Coordinate& loc1,
112112
return Chunk{loc1, loc2, result};
113113
}
114114

115-
int MinecraftConnection::getHeight(int x, int z) {
116-
std::string returnValue = conn->sendReceiveCommand("world.getHeight", x, z);
115+
int MinecraftConnection::getHeight(Coordinate2D loc) {
116+
std::string returnValue =
117+
conn->sendReceiveCommand("world.getHeight", loc.x, loc.z);
117118
return stoi(returnValue);
118119
}
119120

120-
const HeightMap MinecraftConnection::getHeights(const Coordinate& loc1,
121-
const Coordinate& loc2) {
121+
const HeightMap MinecraftConnection::getHeights(const Coordinate2D& loc1,
122+
const Coordinate2D& loc2) {
122123
std::string returnValue = conn->sendReceiveCommand(
123124
"world.getHeights", loc1.x, loc1.z, loc2.x, loc2.z);
124125

src/util.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ int Chunk::z_len() const { return this->_z_len; }
156156

157157
Coordinate Chunk::base_pt() const { return this->_base_pt.clone(); }
158158

159-
HeightMap::HeightMap(const Coordinate& loc1, const Coordinate& loc2,
159+
HeightMap::HeightMap(const Coordinate2D& loc1, const Coordinate2D& loc2,
160160
const std::vector<int>& heights) {
161161
_base_pt = Coordinate{
162162
std::min(loc1.x, loc2.x),
@@ -203,7 +203,7 @@ int HeightMap::get(int x, int z) const {
203203
return raw_heights[x * _z_len + z];
204204
}
205205

206-
int HeightMap::get_worldspace(const Coordinate& loc) const {
206+
int HeightMap::get_worldspace(const Coordinate2D& loc) const {
207207
return get(loc.x - _base_pt.x, loc.z - _base_pt.z);
208208
}
209209

@@ -215,6 +215,6 @@ int HeightMap::x_len() const { return this->_x_len; }
215215

216216
int HeightMap::z_len() const { return this->_z_len; }
217217

218-
Coordinate HeightMap::base_pt() const { return this->_base_pt.clone(); }
218+
Coordinate2D HeightMap::base_pt() const { return this->_base_pt.clone(); }
219219

220220
} // namespace mcpp

0 commit comments

Comments
 (0)