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

Revamp Coordinate constructors #101

Merged
merged 4 commits into from
Dec 5, 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
17 changes: 12 additions & 5 deletions include/mcpp/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ struct Coordinate {
/**
* @brief Constructs a Coordinate object with integer values.
*
* @param x The x-coordinate. Default is 0.
* @param y The y-coordinate. Default is 0.
* @param z The z-coordinate. Default is 0.
* @param x The x-coordinate.
* @param y The y-coordinate.
* @param z The z-coordinate.
*/
explicit Coordinate(int x = 0, int y = 0, int z = 0);
constexpr Coordinate(int x, int y, int z) : x(x), y(y), z(z) {}

/**
* @brief Constructs a Coordinate object with zero values.
*/
constexpr Coordinate() : x(0), y(0), z(0) {}

/**
* @brief Constructs a Coordinate object with double values.
Expand All @@ -32,7 +37,9 @@ struct Coordinate {
* @param y The y-coordinate as a double.
* @param z The z-coordinate as a double.
*/
Coordinate(double x, double y, double z);
constexpr Coordinate(double x, double y, double z)
: x(static_cast<int>(x)), y(static_cast<int>(y)),
z(static_cast<int>(z)) {}

/**
* @brief Adds two Coordinate objects.
Expand Down
12 changes: 0 additions & 12 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,6 @@

namespace mcpp {

Coordinate::Coordinate(int x, int y, int z) {
this->x = x;
this->y = y;
this->z = z;
}

Coordinate::Coordinate(double x, double y, double z) {
this->x = static_cast<int>(x);
this->y = static_cast<int>(y);
this->z = static_cast<int>(z);
}

Coordinate Coordinate::operator+(const Coordinate& obj) const {
Coordinate result;
result.x = this->x + obj.x;
Expand Down