GeometryLib is a C++20 3D geometry library built with CMake. It provides analytic geometry primitives — points, vectors, lines, rays, and planes — a bounded shapes layer — segments, triangles, circles, and axis-aligned bounding boxes — and a spatial query layer covering intersection, parallelism, projection, and distance operations. The API is clean, well-tested, and uses scale-independent floating-point comparisons throughout.
The project exports an installable library target (GeometryLib::Geometry), ships CMake package configuration files for downstream find_package consumers, and uses GoogleTest for unit testing.
Geometry/
├── CMakeLists.txt
├── CMakePresets.json
├── cmake/
│ ├── GeometryLibConfig.cmake.in
│ ├── GeometrySources.cmake # lists all library source files
│ └── GeometryTestSources.cmake # lists all test source files
├── include/Geometry/
│ ├── Primitives/ # point, vector, line, ray, plane
│ ├── Shapes/ # segment, triangle, circle, bounding_box
│ └── Queries/ # intersect, parallel, project, distance
├── src/ # mirrors include/ layout; also contains utils/
└── tests/ # mirrors include/ layout
The documentation is published automatically at: https://psiridis.github.io/GeometryLib/
It is regenerated on every push to main via the GitHub Actions workflow in .github/workflows/docs.yml.
To build the docs locally:
doxygen Doxyfile
open docs/html/index.html- CMake 3.20 or newer
- A C++20-capable compiler
- Ninja
- Git when configuring a build with tests enabled, because GoogleTest is fetched at configure time
- Doxygen (optional — only required to build the documentation locally)
Notes:
- The provided presets use the Ninja generator explicitly.
ctestis bundled with CMake and is used to run the test suite.
The recommended workflow is to use the presets defined in CMakePresets.json.
The debug preset configures the project in build-debug, enables tests, and sets the install prefix to install/ in the source tree.
cmake --preset debug
cmake --build --preset debugThe release preset configures the project in build-release and disables tests.
cmake --preset release
cmake --build --preset releaseThe asan preset configures the project in build-asan, enables tests, and adds AddressSanitizer flags.
cmake --preset asan
cmake --build --preset asanIf you change CMakeLists.txt, presets, or files included from CMake, rerun the configure step before building:
cmake --preset debug
cmake --build --preset debugThe install rules export the library target, public headers, and package configuration files.
cmake --preset debug
cmake --build --preset install-debugFor release:
cmake --preset release
cmake --build --preset install-releasecmake --install build-debugBy default, the presets install into:
<project-root>/install
Installed package files are placed under:
install/
├── include/
└── lib/cmake/GeometryLib/
Tests are enabled in the debug and asan presets and are built into a single executable named geometry_tests.
cmake --preset debug
cmake --build --preset debug --target geometry_tests
ctest --preset debugThe debug test preset already enables output on failure.
./build-debug/geometry_testsIf CTest reports geometry_tests_NOT_BUILT, reconfigure and rebuild the target:
cmake --preset debug
cmake --build --preset debug --target geometry_tests
ctest --preset debugAfter installation, consumers can use the exported package configuration.
find_package(GeometryLib CONFIG REQUIRED)
add_executable(myapp main.cpp)
target_link_libraries(myapp PRIVATE GeometryLib::Geometry)If GeometryLib is installed in a non-standard location, point CMake at the install prefix:
cmake -S . -B build -DCMAKE_PREFIX_PATH=/path/to/Geometry/install- Library implementation files are listed in
cmake/GeometrySources.cmake. - Test source files are listed in
cmake/GeometryTestSources.cmake. - GoogleTest is fetched only when
BUILD_TESTINGis enabled. - The exported target name for consumers is
GeometryLib::Geometry. GEOM_ASSERT(condition)fires before everythrowin debug builds, providing an early abort with file and line info. Both mechanisms remain active — the assert for development, the throw for release-time error handling by callers.- Floating-point comparisons use
almost_equal(a, b)fromsrc/utils/numerical_utils.hpp. Shared tolerance constantsk_abs_eps(1e-12) andk_rel_eps(1e-9) are defined there and used consistently across all modules. All threshold checks in the query layer are scale-independent (squared ratios, no raw absolute distances).safe_acos(x)clamps its argument to [-1, 1] before callingstd::acosto prevent NaN from floating-point rounding.