A modular C++20 computational geometry library with comprehensive testing.
- Modular CMake Architecture: Dedicated CMake files for each module
- Modern C++20: Uses latest language features and best practices
- Eigen Integration: Built on the robust Eigen linear algebra library
- Google Test Framework: Professional testing with comprehensive coverage
- Cross-Platform: Supports Linux, Windows, and macOS
- Continuous Integration: Automated testing, static analysis, and code coverage
- Configurable scalar types (float/double precision)
- Eigen integration and type aliases
- Project-wide configuration header
- Ray3d: 3D ray with origin and direction
- Triangle3d: 3D triangle with utility methods
- Ray-Triangle Intersection: Möller–Trumbore algorithm
- Distance Calculations: Ray to triangle distance
- Intersection Testing: Fast boolean intersection checks
- CMake 3.22 or higher
- C++20 compatible compiler
- Eigen3 library (auto-downloaded by CMake)
- Google Test (auto-downloaded by CMake)
git clone https://github.com/VitalyVorobyev/geometry.git
cd geometry
mkdir build && cd build
cmake .. -DGEOM_BUILD_TESTS=ON
cmake --build .
#include "geom/primitives/ray.hpp"
#include "geom/primitives/triangle.hpp"
#include "geom/algorithms/intersect.hpp"
using namespace geom;
// Create a ray
Ray3d ray;
ray.origin = Ray3d::Vec3(0, 0, -1);
ray.dir = Ray3d::Vec3(0, 0, 1);
// Create a triangle
Triangle3d triangle;
triangle.a = Triangle3d::Vec3(-1, -1, 0);
triangle.b = Triangle3d::Vec3( 1, -1, 0);
triangle.c = Triangle3d::Vec3( 0, 1, 0);
// Test intersection
auto hit = intersect(ray, triangle);
if (hit.hit) {
std::cout << "Intersection at t=" << hit.t << std::endl;
}
GEOM_USE_DOUBLE
: Use double precision (default: ON)GEOM_BUILD_TESTS
: Build unit tests (default: ON)
The project uses Google Test framework for comprehensive unit testing.
# Build with tests enabled
cmake .. -DGEOM_BUILD_TESTS=ON
cmake --build .
# Run all tests
ctest --output-on-failure
# Run tests with verbose output
ctest --verbose
# Run specific test suites
./tests/geometry_gtests --gtest_filter="RayTest.*"
./tests/geometry_gtests --gtest_filter="TriangleTest.*"
./tests/geometry_gtests --gtest_filter="IntersectionTest.*"
Documentation is generated with Doxygen and automatically deployed to GitHub Pages via GitHub Actions.
To enable automatic deployments:
- In the repository's Settings > Pages, set Build and deployment → Source to GitHub Actions.
- Ensure the
github-pages
environment exists (GitHub creates it automatically after the first successful deploy).
The docs
workflow publishes the site on every push to main
.
geometry/
├── CMakeLists.txt # Main project configuration
├── include/geom/ # Public API headers
│ ├── core/ # Core configuration
│ │ └── config.hpp # Scalar types and config
│ ├── primitives/ # Geometric primitives
│ │ ├── ray.hpp # Ray3d definition
│ │ └── triangle.hpp # Triangle3d definition
│ └── algorithms/ # Geometric algorithms
│ └── intersect.hpp # Intersection algorithms
├── src/ # Implementation files
│ ├── core/
│ │ └── CMakeLists.txt # Core module config
│ ├── primitives/
│ │ ├── CMakeLists.txt # Primitives module config
│ │ ├── ray.cpp # Ray implementations
│ │ └── triangle.cpp # Triangle implementations
│ └── algorithms/
│ ├── CMakeLists.txt # Algorithms module config
│ └── intersect.cpp # Intersection implementations
├── tests/ # Google Test suite
│ ├── CMakeLists.txt # Test configuration
│ ├── test_primitives_gtest.cpp # Primitives tests
│ └── test_intersect_gtest.cpp # Intersection tests
├── .github/workflows/ # CI/CD automation
├── cmake/ # CMake configuration
└── docs/ # Documentation
The project uses a modular CMake structure:
- Root CMakeLists.txt: Main project coordination and global settings
- src/*/CMakeLists.txt: Dedicated module configurations
- tests/CMakeLists.txt: Google Test integration with CTest
geom_core
: Interface library with Eigen and configurationgeom_primitives
: Static library with Ray3d and Triangle3dgeom_algorithms
: Static library with intersection algorithmsgeom
: Main library target combining all modulesgeometry_gtests
: Google Test executable
See CONTRIBUTING.md for development guidelines.
See LICENSE file for details.