Skip to content
Closed
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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ endif()

project(mcpp VERSION ${PROJECT_VERSION})

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 17)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
Expand Down
3 changes: 3 additions & 0 deletions include/mcpp/util.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma once

Check notice on line 1 in include/mcpp/util.h

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on include/mcpp/util.h

File include/mcpp/util.h does not conform to Custom style guidelines. (lines 83)

#include "block.h"
#include <cstddef>
Expand Down Expand Up @@ -75,6 +75,9 @@
*/
[[nodiscard]] Coordinate clone() const;


std::size_t operator()(const Coordinate& obj) const;

/**
* @brief Outputs the Coordinate object to an ostream.
*
Expand Down
14 changes: 14 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "../include/mcpp/util.h"

Check notice on line 1 in src/util.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on src/util.cpp

File src/util.cpp does not conform to Custom style guidelines. (lines 43)
#include <stdexcept>
#include <string>
#include <vector>
Expand Down Expand Up @@ -40,6 +40,20 @@
result.z = this->z - obj.z;
return result;
}
std::size_t Coordinate::operator()(const mcpp::Coordinate& obj) const {
// Minecraft coordinate bounds
int lower = -3e7, upper = 3e7;
size_t base = upper - lower + 1;

// Convert coordinate attributes to non-negative values
size_t nx = obj.x - lower;
size_t ny = obj.y - lower;
size_t nz = obj.z - lower;

// Combine and weight coordinate values using the boundary range
return nx * base * base + ny * base + nz;
}


Coordinate Coordinate::clone() const {
return Coordinate(this->x, this->y, this->z);
Expand Down
21 changes: 20 additions & 1 deletion test/local_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN

Check notice on line 1 in test/local_tests.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter

Run clang-format on test/local_tests.cpp

File test/local_tests.cpp does not conform to Custom style guidelines. (lines 39, 44, 55)

#include "../include/mcpp/block.h"
#include "../include/mcpp/util.h"
#include "doctest.h"
#include <random>

using namespace mcpp;

Expand Down Expand Up @@ -35,7 +36,25 @@

CHECK_EQ(testCoord, testCoordRHS);
}

SUBCASE("Test hash no collision"){
std::set<size_t> hashes;
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<int> dis(-3e7, 3e7);
std::uniform_int_distribution<int> dis2(-64, 256);

Coordinate hashing;
for (int i = 0; i < 100; i++) {
Coordinate testCoord(dis(gen), dis2(gen), dis(gen));
size_t hash = hashing(testCoord);
if (hashes.count(hash)) {
FAIL("Collision");
}
hashes.insert(hash);
}
CHECK_EQ(hashes.size(), 100);

}
SUBCASE("Test not equals") {
Coordinate testCoord(3, 2, 1);
Coordinate testCoordRHS(2, 2, 1);
Expand Down
Loading