- Cross-platform library with support for GCC, Cland and MSVC.
- Modern C++23
- Competitive performance (see library comparisons).
- Linear algebra types: vectors, matrices, quaternions, and normals.
- 3D graphics suitable types: bound boxes, projection matrices, camera, color.
- Type safety: correct unit conversions, transformation matrices, and normalization.
- Safe by default with explicit faster options.
- Debug visualizers for all types (MSVC (ready) and GDB (coming soon)).
- Printing types using
std::ostream
orstd::format
. - Useful utilities.
Vc
for simd wrappersGoogle Test
for tests onlyGoogle Benchmark
for benchmarks only
For functionality and usage examples see usage.
Using CPM.cmake:
CPMAddPackage("gh:4J-company/mr-math#master")
target_link_libraries(<your-project>
PUBLIC/INTERFACE/PRIVATE
mr-math-lib)
Add special 4j remote to your machine:
git clone https://github.com/4J-company/conan-center-index.git cci-4j
conan remote add 4J-company ./cci-4j --type local-recipes-index
Add "mr-math/1.1.0"
to your conanfile.
Build with Conan:
conan build . -b missing -o target=all
target
option controls which CMake targets are built. Possile values are library
(default), tests
, benchmark
, or all
.
For other options, see conanfile.py.
Once you installed all dependencies with Conan, you can build with CMake:
cmake --preset <preset-name>
cmake --build --preset <preset-name>
CMake presets are generated by Conan depending on your configuration. To see available presets, run:
cmake --list-presets
bash run-bench-viz.sh
This generates a plot with the benchmarking results
NOTE: requires python
, pandas
, matplotlib
, numpy
conan build . -b missing -o '&:target=bench'
cmake -DMR_MATH_ENABLE_BENCHMARK=ON -DMAKE_BUILD_TYPE=Release
cmake --build build/benchmark
./build/benchmark/mr-math-bench
If you are interested in specific results, you can disable particular benchmarks with the following options:
MR_MATH_ENABLE_VEC_BENCH
MR_MATH_ENABLE_MATR_BENCH
MR_MATH_ENABLE_QUAT_BENCH
MR_MATH_ENABLE_AABB_BENCH
MR_MATH_ENABLE_CAM_BENCH
MR_MATH_ENABLE_COLOR_BENCH
To enable extra optimizations use:
MR_MATH_EXTRA_OPTIMIZED
Adds-ffast-math
, this hurts accuracy a little but increases perf a lotMR_MATH_ENABLE_PROFILING
Makes changes suggested by profiling tools used by me
Adds-lprofiler -ltcmalloc
DOES NOT include any optimization
Library | Matrix Multiplication (ns) | Vector normalization (ns) | Scalar triple products (ns) |
---|---|---|---|
mr. Math | 4 | 2 | 6.5 |
DirectXMath | 4.8 | 4.3 | 2.3 |
glm | 5.7 | 3.3 | 1.6 |
cglm | 6.2 | 14.6 | 2.2 |
lin | 5.7 | 3.3 | 2.3 |