Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make some member functions const #98

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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