1
0
mirror of https://github.com/slendidev/smath.git synced 2026-03-17 02:26:50 +02:00

Add optional interop headers

Those headers are used for interoping with various popular C++
libraries. For now, those libraries are Eigen, GLM, HandmadeMath,
Raylib, and SFML. Some other ones may be added in the future.

Those are disabled by default, as most projects I would imagine would
not use them. But in case you need any of them for special reasons like
I did, they are there.

Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2026-03-12 01:32:35 +02:00
parent 2a161e36ab
commit 224b924772
8 changed files with 583 additions and 14 deletions

View File

@@ -12,13 +12,26 @@
</a>
</p>
## 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`:
```cpp
#include <print>
#include <smath.hpp>
#include <smath/smath.hpp>
int main() {
using namespace smath;
@@ -39,17 +52,20 @@ g++ -std=c++23 -Iinclude main.cpp -o quickstart
./quickstart
```
## Features
## Interop Headers
- 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.
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`:
```cpp
auto v = smath::from_external(external_value);
auto ext = smath::to_external<ExternalType>(smath_value);
```
## License