|
7 | 7 | * |
8 | 8 | */ |
9 | 9 | namespace mcpp { |
| 10 | + |
| 11 | +struct Coordinate2D; |
| 12 | + |
10 | 13 | /** |
11 | 14 | * Represented using integers since sub-unit coordinates are not of particular |
12 | 15 | * relevance. Allows for operations such as addition between coordinates. |
@@ -49,6 +52,8 @@ struct Coordinate { |
49 | 52 | */ |
50 | 53 | Coordinate operator+(const Coordinate& obj) const; |
51 | 54 |
|
| 55 | + Coordinate operator+(const Coordinate2D& obj) const; |
| 56 | + |
52 | 57 | /** |
53 | 58 | * @brief Checks if two Coordinate objects are equal. |
54 | 59 | * |
@@ -93,6 +98,106 @@ struct Coordinate { |
93 | 98 | friend std::ostream& operator<<(std::ostream& out, const Coordinate& coord); |
94 | 99 | }; |
95 | 100 |
|
| 101 | +/** |
| 102 | + * @brief Height-agnostic coordinate class. |
| 103 | + * |
| 104 | + * Represented using integers since sub-unit coordinates are not of particular |
| 105 | + * relevance. Allows for operations such as addition between flat coordinates. |
| 106 | + */ |
| 107 | +struct Coordinate2D { |
| 108 | + /** |
| 109 | + * @brief Constructs a Coordinate2D object with integer values. |
| 110 | + * |
| 111 | + * @param x The x-coordinate. |
| 112 | + * @param z The z-coordinate. |
| 113 | + */ |
| 114 | + constexpr Coordinate2D(int x, int z) : x(x), z(z) {} |
| 115 | + |
| 116 | + /** |
| 117 | + * @brief Constructs a Coordinate2D object with zero values. |
| 118 | + */ |
| 119 | + constexpr Coordinate2D() : x(0), z(0) {} |
| 120 | + |
| 121 | + /** |
| 122 | + * @brief Constructs a Coordinate2D object with double values. |
| 123 | + * |
| 124 | + * @param x The x-coordinate as a double. |
| 125 | + * @param z The z-coordinate as a double. |
| 126 | + */ |
| 127 | + constexpr Coordinate2D(double x, double z) : x(static_cast<int>(x)), z(static_cast<int>(z)) {} |
| 128 | + |
| 129 | + /** |
| 130 | + * @brief Constructs a Coordinate2D object from a Coordinate object. |
| 131 | + * |
| 132 | + * @param coord The Coordinate object. |
| 133 | + */ |
| 134 | + constexpr Coordinate2D(const Coordinate& coord) : x(coord.x), z(coord.z) {} |
| 135 | + |
| 136 | + /** |
| 137 | + * @brief Constructs a Coordinate object from a Coordinate2D object and a |
| 138 | + * y value. |
| 139 | + * |
| 140 | + * @param coord The Coordinate2D object. |
| 141 | + * @param y The y value. |
| 142 | + */ |
| 143 | + Coordinate with_height(int y) const; |
| 144 | + |
| 145 | + /** |
| 146 | + * @brief Adds two Coordinate2D objects. |
| 147 | + * |
| 148 | + * @param obj The Coordinate2D object to add. |
| 149 | + * @return A new Coordinate2D object representing the sum of the two |
| 150 | + * coordinates. |
| 151 | + */ |
| 152 | + Coordinate2D operator+(const Coordinate2D& obj) const; |
| 153 | + |
| 154 | + /** |
| 155 | + * @brief Checks if two Coordinate2D objects are equal. |
| 156 | + * |
| 157 | + * @param obj The Coordinate2D object to compare with. |
| 158 | + * @return True if the flat coordinates are equal, false otherwise. |
| 159 | + */ |
| 160 | + bool operator==(const Coordinate2D& obj) const; |
| 161 | + |
| 162 | + /** |
| 163 | + * @brief Checks if two Coordinate2D objects are not equal. |
| 164 | + * |
| 165 | + * @param obj The Coordinate2D object to compare with. |
| 166 | + * @return True if the flat coordinates are not equal, false otherwise. |
| 167 | + */ |
| 168 | + bool operator!=(const Coordinate2D& obj) const; |
| 169 | + |
| 170 | + /** |
| 171 | + * @brief Subtracts one Coordinate2D object from another. |
| 172 | + * |
| 173 | + * @param obj The Coordinate2D object to subtract. |
| 174 | + * @return A new Coordinate2D object representing the difference between |
| 175 | + * the two coordinates. |
| 176 | + */ |
| 177 | + Coordinate2D operator-(const Coordinate2D& obj) const; |
| 178 | + |
| 179 | + /** |
| 180 | + * @brief Implements hash algorithm for Coordinate2D object using non-negative |
| 181 | + * mapping and weighted coordinate values. |
| 182 | + * |
| 183 | + * @param obj The Coordinate2D object to hash. |
| 184 | + * @return Hash of Coordinate2D object. |
| 185 | + */ |
| 186 | + std::size_t operator()(const Coordinate2D& obj) const; |
| 187 | + |
| 188 | + /** |
| 189 | + * @brief Outputs the Coordinate2D object to an ostream. |
| 190 | + * |
| 191 | + * @param out The output stream. |
| 192 | + * @param coord The Coordinate2D object to output. |
| 193 | + * @return The output stream with the Coordinate object's values. |
| 194 | + */ |
| 195 | + friend std::ostream& operator<<(std::ostream& out, const Coordinate2D& coord); |
| 196 | + |
| 197 | + int x; |
| 198 | + int z; |
| 199 | +}; |
| 200 | + |
96 | 201 | /** |
97 | 202 | * @brief Convert coordinate to string representation. |
98 | 203 | * |
|
0 commit comments