Skip to content

Commit

Permalink
Merge pull request #98 from dxrcy/main
Browse files Browse the repository at this point in the history
Make some member functions `const`
  • Loading branch information
rozukke authored Oct 24, 2024
2 parents 637166e + 7558c78 commit bc94f6b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 3 additions & 3 deletions include/mcpp/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ struct Chunk {
* for
* @return BlockType at specified location
*/
BlockType get_worldspace(const Coordinate& pos);
BlockType get_worldspace(const Coordinate& pos) const;

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

/**
* Gets the x length of the Chunk.
Expand Down Expand Up @@ -371,7 +371,7 @@ struct HeightMap {
* and z components.
* @param loc: Coordinate to fill y value for
*/
void fill_coord(Coordinate& out);
void fill_coord(Coordinate& out) const;

/**
* Gets the x length of the HeightMap.
Expand Down
8 changes: 5 additions & 3 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Chunk& Chunk::operator=(const Chunk& other) noexcept {
return *this;
}

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

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

void HeightMap::fill_coord(Coordinate& out) { out.y = get_worldspace(out); }
void HeightMap::fill_coord(Coordinate& out) const {
out.y = get_worldspace(out);
}

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

Expand Down

0 comments on commit bc94f6b

Please sign in to comment.