ndml (n-dimensional mathematics library) is a general purpose modular C++26 linear algebra library with a focus on simplicity and standard-compliance.
Main features include vectors, matrices, and quaternions, operations over them and transformations.
Note that the floating-point versions of these structures are considered "primary" for this library, since a lot of operations that are available for floating-point vectors, matrices, and quaternions are not available or unstable for integral versions. Therefore, most tests focus only on the floating-point subset of them.
The library's implementation of a mathematical vector is ndml::vec<N, T>, given N - number of elements, and T - element type.
Vector components can be accessed either directly via member variables x, y, z, and w, or via a subscript operator taking a component index as its sole parameter. Indexing an out of range component will result in std::out_of_range thrown.
Vectors are supported for up to four dimensions so that each component may be accessed via struct member variables.
- dot product;
- cross product;
- norm calculation;
- normalization;
- projection;
- reciprocal calculation;
- general transformation.
The library's implementation of a matrix is ndml::mat<C, R, T>, given C - number of columns, R - number of rows, and T - element type. Matrices are column-major, so given a matrix m, m[c] will return a reference to column of m at index c.
Multi-parameter subscript is also available, so m[c, r] will return a reference to the element at the intersection of column c and row r.
Note that there is no boundary checks for indexing columns, and so it is undefined behavior to access an out of range column.
The coordinate system used for all transformations is right-handed, +X pointing right, +Y - upwards, and +Z - backwards (towards the camera).
- transposition;
- row echelon form calculation;
- determinant calculation;
- inverse calculation via Gauss-Jordan elimination;
- trace calculation.
- vector cross matrix;
- vector outer product matrix;
- scale matrix;
- translation matrix;
- rotation matrices;
- look-at matrix;
- orthogonal projection matrix;
- perspective projection matrix.
The library's implementation of a quaternion is ndml::quat<T>, given T - element type.
They are represented as an extension of four-dimensional vectors, and so vector operations are also available to them.
- conjugate calculation;
- inverse calculation;
- axis-angle extraction;
- Hamilton multiplication of quaternions;
- conjugation of a vector by a quaternion.
- construction of a versor (unit quaternion) from axis and angle;
- conversion of a quaternion to an identical three-dimensional rotation matrix.
The library provides several features usable in metaprogramming, such as a burn type and assignment functors.
Burn type is available as ndml::meta::burn_t<T>, where T is any type.
It can be constructed from any parameters, but cannot be assigned to. It is used in place of unusable vector components, e.g. the Z or W components for one- or two-dimensional vectors. Trying to use this type in almost any manner will result in a compile-time error.
Assignment functors are also available for use. These are functors that provide a static binary operator() such that when it's called, an assignment operator is called for its parameters.
For instance, ndml::meta::addition_assignment<T, U> will perform lhs += rhs when invoked.
The following requirements must be met to use the library:
- C++26 support;
- CMake 4.3.2 or newer.
See CONTRIBUTING.md for the contribution guidelines.
The library is licensed under the MIT License. A copy of the license is available in the LICENSE file.
A.A.A. (contact at aeverless dot dev)