### GET /quaternion/as-matrix Source: https://smath.slendi.dev/structsmath_1_1Quaternion.html Converts the current quaternion instance into a 4x4 homogeneous rotation matrix. ```APIDOC ## GET /quaternion/as-matrix ### Description Converts the quaternion representation into a 4x4 rotation matrix suitable for linear algebra transformations. ### Method GET ### Endpoint /quaternion/as-matrix ### Parameters #### Path Parameters - **id** (string) - Required - The unique identifier of the quaternion instance. ### Response #### Success Response (200) - **matrix** (Mat<4, 4, T>) - The 4x4 rotation matrix. #### Response Example { "matrix": [ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ] } ``` -------------------------------- ### Define C++ class hierarchy for Doxygen graph generation Source: https://smath.slendi.dev/graph_legend.html A collection of C++ class definitions demonstrating various inheritance types, template usage, and documentation states. These examples are used by Doxygen to generate visual inheritance and collaboration graphs. ```cpp /*! Invisible class because of truncation */ class Invisible { }; /*! Truncated class, inheritance relation is hidden */ class Truncated : public Invisible { }; /* Class not documented with doxygen comments */ class Undocumented { }; /*! Class that is inherited using public inheritance */ class PublicBase : public Truncated { }; /*! A template class */ template class Templ { }; /*! Class that is inherited using protected inheritance */ class ProtectedBase { }; /*! Class that is inherited using private inheritance */ class PrivateBase { }; /*! Class that is used by the Inherited class */ class Used { }; /*! Super class that inherits a number of other classes */ class Inherited : public PublicBase, protected ProtectedBase, private PrivateBase, public Undocumented, public Templ { private: Used *m_usedClass; }; ``` -------------------------------- ### Vector Element Accessors Source: https://smath.slendi.dev/smath_8hpp_source.html Provides standard access to vector elements using template-based get functions, supporting both mutable and immutable references with compile-time bounds checking. ```cpp template constexpr T &get(Vec &v) noexcept { static_assert(I < N); return v[I]; } template constexpr T const &get(Vec const &v) noexcept { static_assert(I < N); return v[I]; } ``` -------------------------------- ### Constructor Methods Source: https://smath.slendi.dev/structsmath_1_1Mat.html Methods for initializing matrices, including zero matrices, diagonal matrices, and column-based initialization. ```APIDOC ## POST /smath/Mat/construct ### Description Constructs a new matrix instance. Supports zero initialization, diagonal initialization, or column-based initialization. ### Method POST ### Endpoint /smath/Mat/construct ### Parameters #### Request Body - **type** (string) - Required - 'zero', 'diagonal', or 'columns' - **diag** (T) - Optional - Value for diagonal matrix - **cols** (Vec[]) - Optional - Array of column vectors ### Response #### Success Response (200) - **matrix** (Object) - The constructed matrix object ``` -------------------------------- ### Vector Initialization and Unpacking Source: https://smath.slendi.dev/smath_8hpp_source.html Constructors for initializing vectors from scalars or variadic arguments, and utility methods for unpacking vector components into references. ```cpp constexpr Vec(T const &s) noexcept; constexpr Vec(Args &&...args) noexcept; constexpr auto unpack(Args &...args) noexcept -> void; ``` -------------------------------- ### Camera and Projection Matrix Generation Source: https://smath.slendi.dev/smath_8hpp_source.html Functions for creating view and projection matrices, including orthographic, perspective, and infinite perspective projections, as well as LookAt camera matrices. ```cpp template [[nodiscard]] inline auto matrix_ortho3d(T const left, T const right, T const bottom, T const top, T const near, T const far, bool const flip_z_axis = true) -> Mat<4, 4, T> { Mat<4, 4, T> res {}; res[0, 0] = 2 / (right - left); res[1, 1] = 2 / (top - bottom); res[2, 2] = -2 / (far - near); res[0, 3] = -(right + left) / (right - left); res[1, 3] = -(top + bottom) / (top - bottom); res[2, 3] = -(far + near) / (far - near); res[3, 3] = 1; if (flip_z_axis) { res[2] = -res[2]; } return res; } template [[nodiscard]] inline auto matrix_look_at(Vec<3, T> const eye, Vec<3, T> const center, Vec<3, T> const up) -> Mat<4, 4, T> { auto f = (center - eye).normalized_safe(); auto s = f.cross(up).normalized_safe(); auto u = s.cross(f); return Mat<4, 4, T> { Vec<4, T> { s.x(), u.x(), -f.x(), 0 }, Vec<4, T> { s.y(), u.y(), -f.y(), 0 }, Vec<4, T> { s.z(), u.z(), -f.z(), 0 }, Vec<4, T> { -s.dot(eye), -u.dot(eye), f.dot(eye), 1 }, }; } ``` -------------------------------- ### Matrix Constructors Source: https://smath.slendi.dev/structsmath_1_1Mat.html Constructors for initializing matrices as zero-filled, diagonal-filled, or from a set of column vectors. These constructors are constexpr and noexcept for optimal performance. ```cpp template Mat m1; // Zero matrix Mat m2(5.0f); // Diagonal matrix with 5.0 Mat m3(col1, col2, col3); // Initialized from columns ``` -------------------------------- ### Constants Source: https://smath.slendi.dev/structsmath_1_1Mat.html Static configuration constants for the matrix class. ```APIDOC ## [DATA] EPS_DEFAULT ### Description The default epsilon value used for floating point comparisons within the matrix class. ### Value 1e-6 ### Type static constexpr T ``` -------------------------------- ### Vector Initialization Source: https://smath.slendi.dev/smath_8hpp_source.html Basic vector structure definitions for the smath library, supporting zero-initialization and component access. ```cpp constexpr Vec() noexcept; ``` -------------------------------- ### Basic Vector Operations with smath Source: https://smath.slendi.dev/ Demonstrates the basic usage of smath's Vec class for vector addition, dot product, and normalization. It requires the smath library and C++23 standard. ```cpp #include #include int main() { using namespace smath; Vec3 a{1.0f, 2.0f, 3.0f}; Vec3 b{3.0f, 2.0f, 1.0f}; std::println("a + b = {}", a + b); std::println("dot(a, b) = {}", a.dot(b)); std::println("normalized(a) = {}", a.normalized()); } ``` -------------------------------- ### POST /quaternion/from-axis-angle Source: https://smath.slendi.dev/structsmath_1_1Quaternion.html Constructs a new quaternion instance based on a provided rotation axis and angle. ```APIDOC ## POST /quaternion/from-axis-angle ### Description Builds a quaternion from a 3D rotation axis and an angle. This is a static factory method used to represent rotations. ### Method POST ### Endpoint /quaternion/from-axis-angle ### Parameters #### Request Body - **axis** (Vec<3, T>) - Required - The rotation axis vector. - **angle** (T) - Required - The rotation angle in configured units. ### Request Example { "axis": [0, 1, 0], "angle": 1.57 } ### Response #### Success Response (200) - **quaternion** (Quaternion) - The resulting rotation quaternion. #### Response Example { "x": 0.0, "y": 0.707, "z": 0.0, "w": 0.707 } ``` -------------------------------- ### Vector Normalization Utilities Source: https://smath.slendi.dev/smath_8hpp_source.html Provides safe and standard normalization methods to produce unit vectors. Includes checks for epsilon values to prevent division by zero. ```cpp constexpr auto normalized_safe(U eps = EPS_DEFAULT) const noexcept -> Vec { auto m = magnitude(); return (m > eps) ? (*this) / m : Vec {}; } [[nodiscard]] constexpr auto normalized() noexcept -> Vec requires std::is_floating_point_v { return (*this) / this->magnitude(); } ``` -------------------------------- ### Vec Constructors Source: https://smath.slendi.dev/structsmath_1_1Vec.html Documentation for the various constructors of the Vec class. ```APIDOC ## Constructors ### Vec() [1/3] ```cpp template constexpr smath::Vec< N, T >::Vec() noexcept ``` **Description:** Constructs a zero-initialized vector. ### Vec() [2/3] ```cpp template constexpr smath::Vec< N, T >::Vec(T const &s) noexcept ``` **Description:** Fills all components with the same scalar value. **Parameters:** - **s** (T): Scalar value assigned to every component. ### Vec() [3/3] ```cpp template template requires ((detail::is_scalar_v || detail::is_Vec_v) && ...) && (total_extent() == N) && (!(sizeof...(Args) == 1 && (detail::is_Vec_v && ...))) constexpr smath::Vec< N, T >::Vec(Args &&...args) noexcept ``` **Description:** Constructs a vector from a variadic list of arguments, which can be scalars or other Vec objects, ensuring the total extent matches N. ``` -------------------------------- ### Quaternion Transformations Source: https://smath.slendi.dev/smath_8hpp_source.html Handles quaternion-based rotations and conversions. Includes methods for Hamilton product calculation and conversion to 4x4 rotation matrices. ```cpp constexpr auto as_matrix() const noexcept -> Mat< 4, 4, T >; constexpr auto operator*(Quaternion const &rhs) const noexcept -> Quaternion; static constexpr auto from_axis_angle(Vec< 3, T > const &axis, T const angle) noexcept -> Quaternion; ``` -------------------------------- ### Matrix Equality and Comparison Source: https://smath.slendi.dev/structsmath_1_1Mat.html Methods for comparing matrices, including an approximate equality check for floating-point values and standard equality/inequality operators. ```cpp bool eq = mat.approx_equal(rhs, 1e-5f); bool is_equal = (mat == rhs); bool is_not_equal = (mat != rhs); ``` -------------------------------- ### POST /quaternion/multiply Source: https://smath.slendi.dev/structsmath_1_1Quaternion.html Performs the Hamilton product between two quaternions. ```APIDOC ## POST /quaternion/multiply ### Description Calculates the Hamilton product of two quaternions, effectively combining two rotations. ### Method POST ### Endpoint /quaternion/multiply ### Parameters #### Request Body - **lhs** (Quaternion) - Required - The left-hand quaternion. - **rhs** (Quaternion) - Required - The right-hand quaternion. ### Request Example { "lhs": {"x": 0, "y": 0, "z": 0, "w": 1}, "rhs": {"x": 1, "y": 0, "z": 0, "w": 0} } ### Response #### Success Response (200) - **result** (Quaternion) - The product of the two quaternions. #### Response Example { "x": 1, "y": 0, "z": 0, "w": 0 } ``` -------------------------------- ### Compile-time Vector Swizzling Source: https://smath.slendi.dev/smath_8hpp_source.html Implements GLSL-style swizzling for vectors using template metaprogramming. It validates component characters and bounds at compile-time to ensure type safety. ```cpp template requires detail::ValidSwizzle constexpr auto swizzle(Vec const &v) -> VecOrScalar { return detail::swizzle_impl(v, std::make_index_sequence {}); } ``` -------------------------------- ### Matrix Orthographic Projection (C++) Source: https://smath.slendi.dev/smath_8hpp_source.html Builds an orthographic projection matrix for 3D space. It takes parameters defining the boundaries of the view frustum (left, right, bottom, top, near, far) and an optional flag to flip the Z-axis. This is useful for creating 2D-like views within a 3D environment. ```cpp auto matrix_ortho3d(T const left, T const right, T const bottom, T const top, T const near, T const far, bool const flip_z_axis=true) -> Mat< 4, 4, T > ``` -------------------------------- ### Matrix Perspective Projection (C++) Source: https://smath.slendi.dev/smath_8hpp_source.html Builds a finite perspective projection matrix. This function takes the field of view angle (fovy), aspect ratio, near clipping plane distance, and far clipping plane distance as input. An optional flag can be used to flip the Z-axis. This is fundamental for creating realistic 3D camera views. ```cpp auto matrix_perspective(T fovy, T aspect, T znear, T zfar, bool flip_z_axis=false) -> Mat< 4, 4, T > ``` -------------------------------- ### smath Interop Conversion Source: https://smath.slendi.dev/ Shows how to convert values between smath's internal representation and external types using provided adapter functions. This is useful for integrating smath with other libraries. ```cpp auto v = smath::from_external(external_value); auto ext = smath::to_external(smath_value); ``` -------------------------------- ### Vector Cross Product and Projection Source: https://smath.slendi.dev/smath_8hpp_source.html Advanced geometric operations including 3D cross product and vector projection onto another vector. ```cpp constexpr auto cross(Vec const &r) const noexcept -> Vec requires(N == 3) { return { (*this)[1] * r[2] - (*this)[2] * r[1], (*this)[2] * r[0] - (*this)[0] * r[2], (*this)[0] * r[1] - (*this)[1] * r[0], }; } constexpr auto project_onto(Vec const &n) const noexcept -> Vec requires std::is_floating_point_v { auto d = this->dot(n); auto nn = n.dot(n); return (nn ? (d / nn) * n : Vec()); } ``` -------------------------------- ### Define smath configuration macros Source: https://smath.slendi.dev/smath_8hpp.html Configuration macros used to define library behavior, such as the default unit for angle calculations. ```cpp #define SMATH_ANGLE_UNIT rad ``` -------------------------------- ### Data Unpacking Utilities Source: https://smath.slendi.dev/namespacesmath.html Functions for unpacking packed 32-bit integers into 4-component vectors. ```APIDOC ## [FUNCTION] smath::unpack_snorm4x8 ### Description Unpacks a 32-bit signed normalized integer into a 4-component vector. ### Parameters - **packed** (std::uint32_t) - Required - The packed input value. ### Response - **return** (Vec<4, T>) - The unpacked vector. ## [FUNCTION] smath::unpack_unorm4x8 ### Description Unpacks a 32-bit unsigned normalized integer into a 4-component vector. ### Parameters - **packed** (std::uint32_t) - Required - The packed input value. ### Response - **return** (Vec<4, T>) - The unpacked vector. ``` -------------------------------- ### Static constants and conversion logic Source: https://smath.slendi.dev/structsmath_1_1Vec.html Defines the default epsilon value for floating-point comparisons and illustrates the internal logic for casting vector types. ```cpp static constexpr T EPS_DEFAULT = T(1e-6); // Conversion logic example for (std::size_t i = 0; i < N; ++i) { this->operator[](i) = static_cast(other[i]); } ``` -------------------------------- ### Utility Functions for Type Conversion in C++ Source: https://smath.slendi.dev/smath_8hpp_source.html Provides utility functions for converting between different numeric types, specifically for normalized and signed normalized 8-bit integers. These functions handle the scaling and casting required for accurate conversions to floating-point types. ```cpp template constexpr auto unpack_unorm8(std::uint8_t b) -> T { static_assert(std::is_floating_point_v); return static_cast(b) / T(255); } template constexpr auto unpack_snorm8(std::int8_t b) -> T { static_assert(std::is_floating_point_v); int i = static_cast(b); if (i < -127) i = -127; if (i > 127) i = 127; return static_cast(i) / T(127); } ``` -------------------------------- ### Data Packing/Unpacking (C++) Source: https://smath.slendi.dev/smath_8hpp_source.html Includes functions for packing and unpacking normalized 4-component vectors into and from a single 32-bit unsigned integer. These are often used for efficient storage or transmission of color or other normalized data. ```cpp constexpr auto pack_unorm4x8(Vec< 4, T > const &v) -> std::uint32_t ``` ```cpp constexpr auto unpack_unorm4x8(std::uint32_t packed) -> Vec< 4, T > ``` ```cpp constexpr auto pack_snorm4x8(Vec< 4, T > const &v) -> std::uint32_t ``` ```cpp constexpr auto unpack_snorm4x8(std::uint32_t packed) -> Vec< 4, T > ``` -------------------------------- ### Vec Constructor: Variadic Arguments Source: https://smath.slendi.dev/structsmath_1_1Vec.html Constructs a vector using a variadic number of arguments. These arguments can be scalars or other Vec objects, provided they meet specific type and size constraints. This constructor is designed for flexible initialization. ```cpp template template requires ((detail::is_scalar_v || detail::is_Vec_v) && ...) && (total_extent() == N) && (!(sizeof...(Args) == 1 && (detail::is_Vec_v && ...))) constexpr smath::Vec< N, T >::Vec(Args &&...args) noexcept; ``` -------------------------------- ### Interop Adapter (C++) Source: https://smath.slendi.dev/smath_8hpp_source.html Defines a template struct `interop_adapter` which facilitates conversion between external types (`Ext`) and `smath` types. It provides `to_smath` and `from_smath` functions for bidirectional type conversion, enabling seamless integration with other libraries or systems. ```cpp template struct interop_adapter; template constexpr auto from_external(Ext const &ext) -> typename interop_adapter::smath_type { return interop_adapter::to_smath(ext); } template constexpr auto to_external(SMathT const &value) -> Ext { return interop_adapter::from_smath(value); } ``` -------------------------------- ### 3D Projection Matrix Generation (C++) Source: https://smath.slendi.dev/namespacesmath.html Functions to generate common 3D projection matrices: orthographic, perspective, and look-at view matrices. These are fundamental for setting up the camera and viewing frustum in 3D rendering pipelines. They support customizable parameters like field of view, aspect ratio, and near/far clipping planes. ```cpp template auto | matrix_ortho3d (T const left, T const right, T const bottom, T const top, T const near, T const far, bool const flip_z_axis=true) -> Mat< 4, 4, T > | Builds an orthographic projection matrix. template auto | matrix_perspective (T fovy, T aspect, T znear, T zfar, bool flip_z_axis=false) -> Mat< 4, 4, T > | Builds a finite perspective projection matrix. template auto | matrix_look_at (Vec< 3, T > const eye, Vec< 3, T > const center, Vec< 3, T > const up) -> Mat< 4, 4, T > | Builds a right-handed look-at view matrix. template auto | matrix_infinite_perspective (T const fovy, T const aspect, T const znear, bool flip_z_axis=false) -> Mat< 4, 4, T > | Builds a perspective matrix with an infinite far plane. ``` -------------------------------- ### 2D Scaling of a 3x3 Matrix (C++) Source: https://smath.slendi.dev/smath_8hpp_source.html Applies a 2D scaling transformation to a 3x3 matrix using a 2D vector for scaling factors. ```cpp template [[nodiscard]] inline auto scale(Mat<3, 3, T> const &m, Vec<2, T> const &v) -> Mat<3, 3, T> { Mat<3, 3, T> res; res[0] = m[0] * v[0]; res[1] = m[1] * v[1]; res[2] = m[2]; return res; } ``` -------------------------------- ### Matrix Infinite Perspective Projection (C++) Source: https://smath.slendi.dev/smath_8hpp_source.html Constructs a perspective projection matrix with an infinite far plane. This is useful in scenarios where the far clipping plane is not a concern or needs to extend indefinitely. It requires the field of view angle (fovy), aspect ratio, and the near clipping plane distance. ```cpp auto matrix_infinite_perspective(T const fovy, T const aspect, T const znear, bool flip_z_axis=false) -> Mat< 4, 4, T > ``` -------------------------------- ### Normalization Packing Source: https://smath.slendi.dev/smath_8hpp_source.html Utility functions to pack 4-component floating-point vectors into a 32-bit unsigned integer using unsigned or signed normalization (unorm/snorm). ```cpp template requires std::is_floating_point_v [[nodiscard]] constexpr auto pack_unorm4x8(Vec<4, T> const &v) -> std::uint32_t { std::uint32_t r = detail::pack_unorm8(v[0]); std::uint32_t g = detail::pack_unorm8(v[1]); std::uint32_t b = detail::pack_unorm8(v[2]); std::uint32_t a = detail::pack_unorm8(v[3]); return (r) | (g << 8) | (b << 16) | (a << 24); } template requires std::is_floating_point_v [[nodiscard]] constexpr auto pack_snorm4x8(Vec<4, T> const &v) -> std::uint32_t { std::uint32_t r = static_cast(detail::pack_snorm8(v[0])); std::uint32_t g = static_cast(detail::pack_snorm8(v[1])); std::uint32_t b = static_cast(detail::pack_snorm8(v[2])); std::uint32_t a = static_cast(detail::pack_snorm8(v[3])); return (r) | (g << 8) | (b << 16) | (a << 24); } ``` -------------------------------- ### Affine Transformations (Shear, Translate, Rotate, Scale) Source: https://smath.slendi.dev/smath_8hpp_source.html Functions to apply geometric transformations to matrices. These include shearing along axes, translation, rotation, and scaling, typically used in 3D graphics pipelines. ```cpp template [[nodiscard]] inline auto shear_y(Mat<3, 3, T> const &m, T const v) -> Mat<3, 3, T> { Mat<3, 3, T> res { 1 }; res[0][1] = v; return m * res; } template [[nodiscard]] inline auto translate(Mat<4, 4, T> const &m, Vec<3, T> const &v) -> Mat<4, 4, T> { Mat<4, 4, T> res { m }; res[3] = m[0] * v[0] + m[1] * v[1] + m[2] * v[2] + m[3]; return res; } template [[nodiscard]] inline auto rotate(Mat<4, 4, T> const &m, T const angle) -> Mat<4, 4, T> { Mat<4, 4, T> res; T const c { std::cos(angle) }; T const s { std::sin(angle) }; res[0] = m[0] * c + m[1] * s; res[1] = m[0] * -s + m[1] * c; res[2] = m[2]; res[3] = m[3]; return res; } template [[nodiscard]] inline auto scale(Mat<4, 4, T> const &m, Vec<3, T> const &v) -> Mat<4, 4, T> { Mat<4, 4, T> res; res[0] = m[0] * v[0]; res[1] = m[1] * v[1]; res[2] = m[2] * v[2]; res[3] = m[3]; return res; } ``` -------------------------------- ### Identity Matrix Creation (C++) Source: https://smath.slendi.dev/smath_8hpp_source.html Creates an identity matrix of the same dimensions as the current matrix type. Requires the matrix to be square (R == C). ```cpp [[nodiscard]] static constexpr auto identity() noexcept -> Mat requires(R == C) { Mat m {}; for (std::size_t i = 0; i < R; ++i) m(i, i) = T(1); return m; } ``` -------------------------------- ### String Macro Definitions for C++ Source: https://smath.slendi.dev/smath_8hpp_source.html These macros define stringification utilities in C++. SMATH_STR converts a macro argument into a string literal, and SMATH_XSTR expands its argument before stringifying it. These are useful for debugging and compile-time string manipulation. ```cpp #define SMATH_STR(x) #x #define SMATH_XSTR(x) SMATH_STR(x) ``` -------------------------------- ### Matrix Structure and Arithmetic Source: https://smath.slendi.dev/smath_8hpp_source.html A template-based Matrix class providing column-major storage, element access via operator() and operator[], and standard arithmetic operations including addition, subtraction, and scalar multiplication. ```cpp template requires std::is_arithmetic_v struct Mat : std::array, C> { using Base = std::array, C>; constexpr auto operator[](std::size_t const row, std::size_t const column) -> T & { return col(column)[row]; } constexpr auto operator[](std::size_t const row, std::size_t const column) const -> T const & { return col(column)[row]; } constexpr Mat() noexcept { for (auto &col : *this) col = Vec {}; } constexpr explicit Mat(T const &diag) noexcept requires(R == C) { for (std::size_t c = 0; c < C; ++c) { (*this)[c] = Vec {}; (*this)[c][c] = diag; } } constexpr auto col(std::size_t j) noexcept -> Vec & { return (*this)[j]; } constexpr auto operator()(std::size_t row, std::size_t col) noexcept -> T & { return (*this)[col][row]; } constexpr auto operator-() const noexcept -> Mat { Mat r {}; for (std::size_t c = 0; c < C; ++c) r[c] = -(*this)[c]; return r; } constexpr auto operator+=(Mat const &rhs) noexcept -> Mat & { for (std::size_t c = 0; c < C; ++c) (*this)[c] += rhs[c]; return *this; } constexpr auto operator*=(T const &s) noexcept -> Mat & { for (std::size_t c = 0; c < C; ++c) (*this)[c] *= s; return *this; } }; ``` -------------------------------- ### Pack Vector Data Source: https://smath.slendi.dev/namespacesmath.html Utility functions to pack 4-component vectors into 32-bit unsigned integers using signed or unsigned normalized formats. Requires floating-point input types. ```cpp template requires std::is_floating_point_v constexpr std::uint32_t pack_snorm4x8(Vec<4, T> const& v); template requires std::is_floating_point_v constexpr std::uint32_t pack_unorm4x8(Vec<4, T> const& v); ``` -------------------------------- ### Include standard library dependencies for smath Source: https://smath.slendi.dev/smath_8hpp.html Essential C++ standard library headers required for the smath library functionality, including support for algorithms, arrays, math functions, and type traits. ```cpp #include #include #include #include #include #include #include #include #include ``` -------------------------------- ### Vec Class Constructors in C++ Source: https://smath.slendi.dev/smath_8hpp_source.html Defines constructors for the Vec class, including default, scalar, and variadic template constructors. The variadic constructor handles unpacking scalar values and other Vec instances. ```cpp template requires std::is_arithmetic_v struct Vec : std::array { // Constructors constexpr Vec() noexcept { for (auto &v : *this) v = T(0); } explicit constexpr Vec(T const &s) noexcept { for (auto &v : *this) v = s; } template requires((detail::is_scalar_v || detail::is_Vec_v) && ...) && (total_extent() == N) && (!(sizeof...(Args) == 1 && (detail::is_Vec_v && ...))) constexpr Vec(Args &&...args) noexcept { std::size_t i = 0; (fill_one(i, std::forward(args)), ...); } }; ``` -------------------------------- ### Matrix Transposition (C++) Source: https://smath.slendi.dev/smath_8hpp_source.html Returns the transpose of a matrix. The transpose is created by swapping the rows and columns of the original matrix. ```cpp [[nodiscard]] constexpr auto transposed() const noexcept -> Mat { Mat r {}; for (std::size_t c = 0; c < C; ++c) for (std::size_t r_idx = 0; r_idx < R; ++r_idx) r(r_idx, c) = (*this)(c, r_idx); return r; } ``` -------------------------------- ### Vector Formatting (C++) Source: https://smath.slendi.dev/smath_8hpp_source.html Defines a `std::formatter` specialization for `smath::Vec`. This allows `smath::Vec` objects to be directly formatted using C++'s `` library, outputting them in a readable `{x, y, z, ...}` format. ```cpp template requires std::formattable struct std::formatter> : std::formatter { constexpr auto parse(std::format_parse_context &ctx) { return std::formatter::parse(ctx); } template auto format(smath::Vec const &v, Ctx &ctx) const { auto out = ctx.out(); *out++ = '{'; for (std::size_t i = 0; i < N; ++i) { if (i) { *out++ = ','; *out++ = ' '; } out = std::formatter::format(v[i], ctx); } *out++ = '}'; return out; } }; ``` -------------------------------- ### Identity Matrix Generation Source: https://smath.slendi.dev/structsmath_1_1Mat.html Static factory method to generate an identity matrix. Requires the matrix to be square (R == C). ```cpp auto identity = smath::Mat<3, 3, float>::identity(); ``` -------------------------------- ### Component Unpacking Source: https://smath.slendi.dev/structsmath_1_1Vec.html Utility method to unpack vector components into a variadic list of output references. Useful for structured binding or passing vector data to legacy APIs. ```cpp template constexpr auto unpack(Args&... args) -> void; ``` -------------------------------- ### Packed Float-to-Uint Conversion (C++) Source: https://smath.slendi.dev/namespacesmath.html Functions for packing and unpacking 4-component floating-point vectors into a single 32-bit unsigned integer. `pack_unorm4x8` and `pack_snorm4x8` convert normalized or signed normalized floats to uint8 components, while `unpack_unorm4x8` and `unpack_snorm4x8` perform the reverse operation. Requires `std::is_floating_point_v`. ```cpp template requires std::is_floating_point_v constexpr auto | pack_unorm4x8 (Vec< 4, T > const &v) -> std::uint32_t template requires std::is_floating_point_v constexpr auto | pack_snorm4x8 (Vec< 4, T > const &v) -> std::uint32_t template requires std::is_floating_point_v constexpr auto | unpack_unorm4x8 (std::uint32_t packed) -> Vec< 4, T > template requires std::is_floating_point_v constexpr auto | unpack_snorm4x8 (std::uint32_t packed) -> Vec< 4, T > ``` -------------------------------- ### Look-At Matrix (C++) Source: https://smath.slendi.dev/smath_8hpp_source.html Builds a right-handed look-at view matrix. This function defines the orientation of a camera in 3D space by specifying its position (eye), the point it is looking at (center), and the direction considered 'up'. This is crucial for setting up camera transformations in 3D rendering. ```cpp auto matrix_look_at(Vec< 3, T > const eye, Vec< 3, T > const center, Vec< 3, T > const up) -> Mat< 4, 4, T > ``` -------------------------------- ### Matrix Inequality Comparison (C++) Source: https://smath.slendi.dev/smath_8hpp_source.html Implements the inequality operator (!=) by negating the result of the equality operator (==). This provides a concise way to check if two matrices are not equal. ```cpp [[nodiscard]] constexpr auto operator!=(Mat const &rhs) const noexcept -> bool { return !(*this == rhs); } ``` -------------------------------- ### Matrix Arithmetic Operator Overloads Source: https://smath.slendi.dev/structsmath_1_1Mat.html Provides friend operator overloads for matrix-scalar and matrix-matrix arithmetic. These allow for intuitive syntax when performing linear algebra operations. ```cpp template friend constexpr auto operator*(Mat lhs, T const &s) -> Mat; template friend constexpr auto operator*(T const &s, Mat rhs) -> Mat; template friend constexpr auto operator+(Mat lhs, Mat const &rhs) -> Mat; template friend constexpr auto operator-(Mat lhs, Mat const &rhs) -> Mat; template friend constexpr auto operator/(Mat lhs, T const &s) -> Mat; ``` -------------------------------- ### C++ Matrix Class Definition and Operators Source: https://smath.slendi.dev/structsmath_1_1Mat.html Defines the `Mat` class template for matrices with R rows, C columns, and type T. It includes constructors for zero and diagonal matrices, member functions for accessing columns and elements, and overloaded operators for arithmetic operations, equality comparison, and approximate equality checks. Dependencies include `Vec` and `std::array`. ```cpp #include template class Mat { public: using Base = std::array, C>; constexpr Mat() noexcept; constexpr Mat(T const &diag) noexcept; template requires (sizeof...(Cols) == C && (std::same_as, Vec> && ...)) constexpr Mat(Cols const &...cols) noexcept; constexpr auto col(std::size_t j) noexcept -> Vec &; constexpr auto col(std::size_t j) const noexcept -> Vec const &; constexpr auto operator[](std::size_t const row, std::size_t const column) -> T &; constexpr auto operator[](std::size_t const row, std::size_t const column) const -> T const &; constexpr auto operator()(std::size_t row, std::size_t col) noexcept -> T &; constexpr auto operator()(std::size_t row, std::size_t col) const noexcept -> T const &; constexpr auto operator-() const noexcept -> Mat; constexpr auto operator+=(Mat const &rhs) noexcept -> Mat &; constexpr auto operator-=(Mat const &rhs) noexcept -> Mat &; constexpr auto operator*=(T const &s) noexcept -> Mat &; constexpr auto operator/=(T const &s) noexcept -> Mat &; constexpr auto operator==(Mat const &rhs) const noexcept -> bool; constexpr auto operator!=(Mat const &rhs) const noexcept -> bool; template requires std::is_floating_point_v constexpr auto approx_equal(Mat const &rhs, U eps = EPS_DEFAULT) const noexcept -> bool; constexpr auto transposed() const noexcept -> Mat; static constexpr auto identity() noexcept -> Mat requires(R == C); static constexpr T EPS_DEFAULT = T(1e-6); }; constexpr auto operator+(Mat lhs, Mat const &rhs) noexcept -> Mat; constexpr auto operator-(Mat lhs, Mat const &rhs) noexcept -> Mat; constexpr auto operator*(Mat lhs, T const &s) noexcept -> Mat; constexpr auto operator*(T const &s, Mat rhs) noexcept -> Mat; constexpr auto operator/(Mat lhs, T const &s) noexcept -> Mat; ``` -------------------------------- ### Vector Geometric Calculations Source: https://smath.slendi.dev/smath_8hpp_source.html Functions to calculate magnitude, length, and dot products. Includes requirements for floating-point types to ensure mathematical correctness. ```cpp constexpr auto magnitude() const noexcept -> T requires std::is_floating_point_v { T total = 0; for (auto const &v : *this) total += v * v; return std::sqrt(total); } [[nodiscard]] constexpr auto dot(Vec const &other) const noexcept -> T { T res = 0; for (std::size_t i = 0; i < N; ++i) { res += (*this)[i] * other[i]; } return res; } ``` -------------------------------- ### 2D Transformation Matrices (C++) Source: https://smath.slendi.dev/namespacesmath.html Functions for creating and manipulating 3x3 transformation matrices for 2D graphics. This includes functions to apply translations, rotations, scaling, and shearing to existing matrices, as well as functions to create new transformation matrices from scratch. ```cpp template auto | translate (Mat< 3, 3, T > const &m, Vec< 2, T > const &v) -> Mat< 3, 3, T > | Applies translation to an existing 3x3 transform. template auto | translate (Vec< 2, T > const &v) -> Mat< 3, 3, T > | Creates a 3x3 translation matrix. template auto | rotate (Mat< 3, 3, T > const &m, T const angle) -> Mat< 3, 3, T > | Applies rotation to an existing 3x3 transform. template auto | scale (Mat< 3, 3, T > const &m, Vec< 2, T > const &v) -> Mat< 3, 3, T > | Applies scaling to an existing 3x3 transform. template auto | shear_x (Mat< 3, 3, T > const &m, T const v) -> Mat< 3, 3, T > | Applies X shear to an existing 3x3 transform. template auto | shear_y (Mat< 3, 3, T > const &m, T const v) -> Mat< 3, 3, T > | Applies Y shear to an existing 3x3 transform. ``` -------------------------------- ### Angle Unit Conversion (C++) Source: https://smath.slendi.dev/smath_8hpp_source.html Provides utility functions to convert angle values between different units: radians, degrees, and turns. This allows for flexible handling of angular data, accommodating various input formats and internal representations. ```cpp constexpr auto rad(T value) ``` ```cpp constexpr auto deg(T value) ``` ```cpp constexpr auto turns(T value) ``` -------------------------------- ### Create 3x3 Translation Matrix (C++) Source: https://smath.slendi.dev/smath_8hpp_source.html Creates a 3x3 translation matrix from a 2D vector. This matrix can then be used to apply translation to other transformations. ```cpp template [[nodiscard]] inline auto translate(Vec<2, T> const &v) -> Mat<3, 3, T> { Mat<3, 3, T> res { 1 }; res[2].x() = v.x(); res[2].y() = v.y(); return res; } ``` -------------------------------- ### Geometric Vector Operations in C++ Source: https://smath.slendi.dev/structsmath_1_1Vec.html Core geometric methods for the smath::Vec class, including cross product, dot product, magnitude, and projection. These methods are marked as constexpr and noexcept for high-performance compile-time evaluation. ```cpp template constexpr auto cross(Vec const& r) const; template constexpr auto dot(Vec const& other) const; template constexpr auto magnitude() const; template constexpr auto project_onto(Vec const& n) const; ``` -------------------------------- ### Vector Geometric Operations Source: https://smath.slendi.dev/smath_8hpp_source.html Core geometric functions including magnitude, normalization, dot product, and vector projection. Includes safe variants to handle zero-length vectors. ```cpp constexpr auto magnitude() const noexcept -> T; constexpr auto normalized() noexcept -> Vec< N, T >; constexpr auto normalize_safe(U eps=EPS_DEFAULT) const noexcept -> Vec; constexpr auto dot(Vec< N, T > const &other) const noexcept -> T; constexpr auto project_onto(Vec const &n) const noexcept -> Vec; constexpr auto cross(Vec const &r) const noexcept -> Vec; ``` -------------------------------- ### Vec Constructor: Scalar Initialization Source: https://smath.slendi.dev/structsmath_1_1Vec.html Constructs a vector of size N with elements of type T, where all components are initialized to the same scalar value. This constructor takes a constant reference to a scalar value. ```cpp template constexpr smath::Vec< N, T >::Vec(T const &s) noexcept; ``` -------------------------------- ### Generate Projection Matrices Source: https://smath.slendi.dev/namespacesmath.html Functions for creating standard 3D graphics projection matrices, including perspective and orthographic variants. These return 4x4 matrices based on input parameters like field of view, aspect ratio, and clipping planes. ```cpp template auto matrix_perspective(T fovy, T aspect, T znear, T zfar, bool flip_z_axis = false) -> Mat<4, 4, T>; template auto matrix_ortho3d(T left, T right, T bottom, T top, T near, T far, bool flip_z_axis = true) -> Mat<4, 4, T>; ``` -------------------------------- ### Matrix Transformations (C++) Source: https://smath.slendi.dev/smath_8hpp_source.html Provides functions for applying common transformations to 3x3 and 4x4 matrices, including translation, scaling, rotation, and shearing along the X, Y, and Z axes. These operations are fundamental for manipulating objects in 2D and 3D graphics. ```cpp auto translate(Mat< 3, 3, T > const &m, Vec< 2, T > const &v) -> Mat< 3, 3, T > ``` ```cpp auto scale(Mat< 3, 3, T > const &m, Vec< 2, T > const &v) -> Mat< 3, 3, T > ``` ```cpp auto rotate(Mat< 3, 3, T > const &m, T const angle) -> Mat< 3, 3, T > ``` ```cpp auto shear_x(Mat< 3, 3, T > const &m, T const v) -> Mat< 3, 3, T > ``` ```cpp auto shear_y(Mat< 3, 3, T > const &m, T const v) -> Mat< 3, 3, T > ``` ```cpp auto shear_z(Mat< 4, 4, T > const &m, T const v) -> Mat< 4, 4, T > ``` -------------------------------- ### Quaternion Vector Conversion Source: https://smath.slendi.dev/structsmath_1_1Quaternion.html Method to retrieve the vector representation of the quaternion. ```APIDOC ## [GET] smath::Quaternion::vec() ### Description Returns the quaternion represented as its vector base type. ### Method GET ### Response #### Success Response (200) - **return** (Base) - The vector base type representation of the quaternion. ```