Skip to content

Commit 7558c78

Browse files
committed
Make some member functions const
`Chunk::get_worldspace`, `Chunk::get`, `HeightMap::fill_coord`
1 parent 637166e commit 7558c78

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

include/mcpp/util.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ struct Chunk {
204204
* for
205205
* @return BlockType at specified location
206206
*/
207-
BlockType get_worldspace(const Coordinate& pos);
207+
BlockType get_worldspace(const Coordinate& pos) const;
208208

209209
/**
210210
* Local equivalent of get_worldspace, equivalent to a 3D array access of
@@ -214,7 +214,7 @@ struct Chunk {
214214
* @param z: z element of array access
215215
* @return BlockType at specified location
216216
*/
217-
BlockType get(int x, int y, int z);
217+
BlockType get(int x, int y, int z) const;
218218

219219
/**
220220
* Gets the x length of the Chunk.
@@ -371,7 +371,7 @@ struct HeightMap {
371371
* and z components.
372372
* @param loc: Coordinate to fill y value for
373373
*/
374-
void fill_coord(Coordinate& out);
374+
void fill_coord(Coordinate& out) const;
375375

376376
/**
377377
* Gets the x length of the HeightMap.

src/util.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Chunk& Chunk::operator=(const Chunk& other) noexcept {
9090
return *this;
9191
}
9292

93-
BlockType Chunk::get(int x, int y, int z) {
93+
BlockType Chunk::get(int x, int y, int z) const {
9494
if ((x < 0 || y < 0 || z < 0) ||
9595
(x > _x_len - 1 || y > _y_len - 1 || z > _z_len - 1)) {
9696
throw std::out_of_range("Out of bounds Chunk access at " +
@@ -99,7 +99,7 @@ BlockType Chunk::get(int x, int y, int z) {
9999
return raw_data[y * _x_len * _z_len + x * _z_len + z];
100100
}
101101

102-
BlockType Chunk::get_worldspace(const Coordinate& pos) {
102+
BlockType Chunk::get_worldspace(const Coordinate& pos) const {
103103
Coordinate array_pos = pos - _base_pt;
104104
if ((array_pos.x < 0 || array_pos.y < 0 || array_pos.z < 0) ||
105105
(array_pos.x > _x_len - 1 || array_pos.y > _y_len - 1 ||
@@ -171,7 +171,9 @@ int HeightMap::get_worldspace(const Coordinate& loc) const {
171171
return get(loc.x - _base_pt.x, loc.z - _base_pt.z);
172172
}
173173

174-
void HeightMap::fill_coord(Coordinate& out) { out.y = get_worldspace(out); }
174+
void HeightMap::fill_coord(Coordinate& out) const {
175+
out.y = get_worldspace(out);
176+
}
175177

176178
int HeightMap::x_len() const { return this->_x_len; }
177179

0 commit comments

Comments
 (0)