Skip to content

Commit a7ccb57

Browse files
authored
docs: document compile-time limits and add consistency check (#5)
Document the public compile-time capacity limits and their defining headers. Add a CTest consistency check to prevent the README values from drifting out of sync with the public constants. Closes #4.
2 parents 1e683c5 + a98fc5f commit a7ccb57

3 files changed

Lines changed: 37 additions & 0 deletions

File tree

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ scripts/format.sh
6363
It pins clang-format 18; a different major version formats differently and CI
6464
will reject the result.
6565

66+
## Compile-time limits
67+
68+
motionkit uses fixed-size storage to keep its core algorithms allocation-free.
69+
The following public limits are intentionally fixed and cannot currently be
70+
overridden through CMake:
71+
72+
| Constant | Defining header | Limit |
73+
|---|---|---:|
74+
| `kMaxPathKnots` | `motionkit/core/cartesian.hpp` | 65 |
75+
| `kMaxWaypoints` | `motionkit/core/cartesian.hpp` | 16 |
76+
| `kMaxObstacles` | `motionkit/core/collision.hpp` | 32 |
77+
6678
## Use it downstream
6779

6880
```cmake

tests/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ FetchContent_MakeAvailable(googletest)
1010

1111
include(GoogleTest)
1212

13+
add_test(NAME readme_limits
14+
COMMAND ${CMAKE_COMMAND}
15+
-DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
16+
-P ${CMAKE_CURRENT_SOURCE_DIR}/check_readme_limits.cmake)
17+
set_tests_properties(readme_limits PROPERTIES LABELS unit)
18+
1319
add_executable(motionkit_tests
1420
test_vec3.cpp
1521
test_so3.cpp

tests/check_readme_limits.cmake

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
file(READ "${PROJECT_SOURCE_DIR}/README.md" readme)
2+
3+
function(check_limit name header)
4+
file(READ "${PROJECT_SOURCE_DIR}/include/${header}" declaration)
5+
string(REGEX MATCH "${name} = ([0-9]+)" match "${declaration}")
6+
if(NOT match)
7+
message(FATAL_ERROR "Could not find ${name} in ${header}")
8+
endif()
9+
set(value "${CMAKE_MATCH_1}")
10+
string(FIND "${readme}" "| `${name}` | `${header}` | ${value} |" documented)
11+
if(documented EQUAL -1)
12+
message(FATAL_ERROR
13+
"README limit for ${name} does not match ${header} (${value})")
14+
endif()
15+
endfunction()
16+
17+
check_limit(kMaxPathKnots motionkit/core/cartesian.hpp)
18+
check_limit(kMaxWaypoints motionkit/core/cartesian.hpp)
19+
check_limit(kMaxObstacles motionkit/core/collision.hpp)

0 commit comments

Comments
 (0)