1
0
mirror of https://github.com/slendidev/smath.git synced 2026-03-16 18:16:50 +02:00
2026-03-15 17:21:34 +02:00
2026-03-12 00:40:20 +02:00
2026-03-12 08:35:40 +02:00
2026-03-12 03:09:02 +02:00
2025-11-14 15:21:17 +02:00
2026-03-12 01:34:35 +02:00
2025-08-24 19:20:40 +03:00
2026-03-12 02:35:04 +02:00
2025-08-24 19:20:40 +03:00
2026-03-12 08:27:02 +02:00

smath logo

Build License: Apache-2.0 C++23

Features

  • Generic Vec<N, T> class with useful aliases Vec2/Vec3/Vec4 and friendly accessors (x/y/z/w, r/g/b/a). They support approx-equal and tuple/structured bindings.
  • std::format support.
  • Compile-time swizzles via swizzle<"...">.
  • Generic matrix Mat class with useful aliases Mat2/Mat3/Mat4.
  • Quaternion<T> built on Vec4.
  • Angle helpers rad/deg/turns respecting a configurable base unit via the macro SMATH_ANGLE_UNIT.
  • Optional implicit conversions.
  • Packing utilities for normalized RGBA (pack_unorm4x8, unpack_snorm4x8, etc.).
  • C++20 modules support.
  • Built-in interop adapter and optional interop headers for various libraries.

Quick Start

Create main.cpp:

#include <print>
#include <smath/smath.hpp>

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());
}

Build and run:

g++ -std=c++23 -Iinclude main.cpp -o quickstart
./quickstart

Interop Headers

smath ships optional interop adapters under include/smath/interop/.

When installing with CMake, interop headers are gated behind:

  • -DSMATH_INSTALL_INTEROP_HEADERS=ON

All of them plug into the same generic API defined in smath.hpp:

auto v = smath::from_external(external_value);
auto ext = smath::to_external<ExternalType>(smath_value);

License

This library is licensed under the Apache License 2.0. See the LICENSE.txt file for more details.

Description
Single-file linear algebra math library for C++23.
https://smath.slendi.dev
Readme 451 KiB
Languages
C++ 91.1%
CMake 5.5%
Nix 3.4%