Skip to content
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
49 changes: 0 additions & 49 deletions .github/workflows/catkin_build.yml

This file was deleted.

49 changes: 49 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
name: 'Spatial Hash: Build and Test'
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Dependencies
run: sudo apt-get update && sudo apt install pipx
- name: Lint
run: pipx install pre-commit && cd ${{github.workspace}} && pre-commit run --all-files
cmake:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Dependencies
run: sudo apt-get update && sudo apt install libgtest-dev libeigen3-dev libgoogle-glog-dev
- name: Configure
run: cmake -B ${{github.workspace}}/build -DBUILD_TESTING=ON -DCMAKE_BUILD_TYPE=Release
- name: Build
run: cmake --build ${{github.workspace}}/build --config Release
- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C Release
ros2:
runs-on: ubuntu-latest
container: ros:jazzy-ros-base
steps:
- uses: actions/checkout@v4
with: {path: src/spatial_hash}
- name: Dependencies
run: |
sudo apt-get update
rosdep update --rosdistro jazzy && rosdep install --rosdistro jazzy --from-paths src --ignore-src -r -y
- name: Build
shell: bash
run: |
source /opt/ros/jazzy/setup.bash
colcon build --cmake-args --no-warn-unused-cli -DCMAKE_BUILD_TYPE=Release
- name: Test
shell: bash
run: |-
source /opt/ros/jazzy/setup.bash
colcon test
6 changes: 2 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ set(CMAKE_CXX_EXTENSIONS OFF)

add_compile_options(-Wall -Wextra)

option(SPATIAL_HASH_BUILD_TESTS "Build tests" ON)

find_package(Eigen3 REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(glog REQUIRED IMPORTED_TARGET libglog)
Expand All @@ -26,8 +24,8 @@ target_include_directories(
)
target_link_libraries(${PROJECT_NAME} PUBLIC Eigen3::Eigen PkgConfig::glog)

if(SPATIAL_HASH_BUILD_TESTS)
find_package(GTest REQUIRED)
include(CTest)
if(BUILD_TESTING)
enable_testing()
add_subdirectory(tests)
endif()
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
![Build and Test](https://github.com/MIT-SPARK/Spatial-Hash/actions/workflows/catkin_build.yml/badge.svg)
[![Spatial Hash: Build and Test](https://github.com/MIT-SPARK/Spatial-Hash/actions/workflows/ci.yaml/badge.svg)](https://github.com/MIT-SPARK/Spatial-Hash/actions/workflows/ci.yaml)

# Spatial Hash
A minimal library for spatial data structures based on voxel-block-hashing.
Expand Down Expand Up @@ -35,7 +35,7 @@ It was developed by [Lukas Schmid](https://schmluk.github.io/) at the [MIT-SPARK
cd build
cmake ..
make -j

# optionally install this package
sudo make install
```
Expand Down
21 changes: 1 addition & 20 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
if(NOT TARGET gtest)
include(FetchContent)
FetchContent_Declare(
googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG v1.13.0
)

FetchContent_GetProperties(googletest)
if(NOT googletest_POPULATED)
FetchContent_Populate(googletest)
endif()

set(BUILD_SHARED_LIBS_THIS ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS OFF CACHE INTERNAL "")
add_subdirectory(${googletest_SOURCE_DIR} ${googletest_BINARY_DIR} EXCLUDE_FROM_ALL)
set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_THIS} CACHE BOOL "")
endif()
find_package(GTest REQUIRED)

include(GoogleTest)
enable_testing()
Expand All @@ -33,7 +18,3 @@ add_executable(
target_include_directories(utest_${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(utest_${PROJECT_NAME} PRIVATE ${PROJECT_NAME} GTest::gtest_main)
gtest_add_tests(TARGET utest_${PROJECT_NAME})

install(TARGETS utest_${PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}
)
17 changes: 9 additions & 8 deletions tests/utest_hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@

namespace spatial_hash {

template <typename IndexType, typename Type>
IndexType randomIndex(const Type range) {
return IndexType(static_cast<Type>(rand() % (2 * range) - range),
static_cast<Type>(rand() % (2 * range) - range),
static_cast<Type>(rand() % (2 * range) - range));
template <typename IndexType, typename Type, typename Generator>
IndexType randomIndex(const Type range, Generator& gen) {
std::uniform_int_distribution<Type> distribution(-range, range);
return IndexType(distribution(gen), distribution(gen), distribution(gen));
}

// Compute the badness of a hash map. The lower the better the hash. 0 is optimal
Expand Down Expand Up @@ -85,13 +84,15 @@ TEST(Hash, HashMapAccess) {
// NOTE(lschmid): Takes a few seconds to compute and onlyu relevant if hash is updated (see if it
// gets better or worse, might need more thorough test cases though.)
TEST(Hash, DISABLED_HashMapCollisions) {
std::random_device rd;
std::mt19937 gen(rd());

IndexHashMap<int> map;
int range = 1290;
srand(42);

// Within range.
for (size_t i = 0; i < 100000; ++i) {
map[randomIndex<Index>(range)] = i;
map[randomIndex<Index>(range, gen)] = i;
}
double badness = computeMapBadness(map);
EXPECT_NEAR(badness, 0.002408, 1e-6);
Expand All @@ -100,7 +101,7 @@ TEST(Hash, DISABLED_HashMapCollisions) {
range = 10000;
map.clear();
for (size_t i = 0; i < 100000; ++i) {
map[randomIndex<Index>(range)] = i;
map[randomIndex<Index>(range, gen)] = i;
}
badness = computeMapBadness(map);
EXPECT_NEAR(badness, 0.0, 1e-6);
Expand Down