mirror of
https://github.com/slendidev/smath.git
synced 2025-12-13 13:19:51 +02:00
Compare commits
7 Commits
e32204db0c
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| d3511a9b52 | |||
| eed719674f | |||
| 5f0badfe64 | |||
| 1a42238a41 | |||
| a5d669235e | |||
| 2d86e02038 | |||
| b5e0aabe37 |
29
.github/workflows/build.yml
vendored
Normal file
29
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
name: Build project
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
name: Build
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
permissions:
|
||||||
|
id-token: write
|
||||||
|
contents: read
|
||||||
|
steps:
|
||||||
|
- name: git checkout
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
- name: Install Nix
|
||||||
|
uses: DeterminateSystems/nix-installer-action@main
|
||||||
|
- name: Building default package
|
||||||
|
run: nix build .#default
|
||||||
|
- name: Upload artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: result
|
||||||
|
path: result
|
||||||
@@ -67,13 +67,17 @@ endif()
|
|||||||
if(BUILD_TESTS)
|
if(BUILD_TESTS)
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
include(FetchContent)
|
find_package(GTest QUIET)
|
||||||
FetchContent_Declare(
|
|
||||||
googletest
|
if(NOT GTest_FOUND)
|
||||||
URL https://github.com/google/googletest/archive/refs/tags/v1.15.2.zip
|
include(FetchContent)
|
||||||
)
|
FetchContent_Declare(
|
||||||
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
googletest
|
||||||
FetchContent_MakeAvailable(googletest)
|
URL https://github.com/google/googletest/archive/refs/tags/v1.15.2.zip
|
||||||
|
)
|
||||||
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||||
|
FetchContent_MakeAvailable(googletest)
|
||||||
|
endif()
|
||||||
|
|
||||||
file(GLOB TEST_SOURCES "${CMAKE_SOURCE_DIR}/tests/*.cpp")
|
file(GLOB TEST_SOURCES "${CMAKE_SOURCE_DIR}/tests/*.cpp")
|
||||||
|
|
||||||
@@ -86,3 +90,4 @@ if(BUILD_TESTS)
|
|||||||
include(GoogleTest)
|
include(GoogleTest)
|
||||||
gtest_discover_tests(smath_tests)
|
gtest_discover_tests(smath_tests)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|||||||
17
README.md
17
README.md
@@ -1,4 +1,19 @@
|
|||||||
# smath
|
# smath
|
||||||
|
|
||||||
Single-file linear algebra math library for C++23.
|
Single-file, header-only linear algebra math library for 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.).
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This library is licensed under the Apache License 2.0. See the (LICENSE.txt)[LICENSE.txt] file for more details.
|
||||||
|
|
||||||
|
|||||||
@@ -39,6 +39,9 @@ int main() {
|
|||||||
std::println("std::get<1>(v): {}", std::get<1>(v));
|
std::println("std::get<1>(v): {}", std::get<1>(v));
|
||||||
auto [x, y, z] = v;
|
auto [x, y, z] = v;
|
||||||
std::println("Bindings: [{}, {}, {}]", x, y, z);
|
std::println("Bindings: [{}, {}, {}]", x, y, z);
|
||||||
|
float x1{}, y1{}, z1{};
|
||||||
|
v.unpack(x1, y1, z1);
|
||||||
|
std::println("Unpacked: {}, {}, {}", x1, y1, z1);
|
||||||
|
|
||||||
// Let's mix and match!
|
// Let's mix and match!
|
||||||
Vec<6> v3(v, 7, swizzle<"zy">(v2));
|
Vec<6> v3(v, 7, swizzle<"zy">(v2));
|
||||||
|
|||||||
15
flake.nix
15
flake.nix
@@ -36,7 +36,11 @@
|
|||||||
|
|
||||||
src = ./.;
|
src = ./.;
|
||||||
|
|
||||||
nativeBuildInputs = [ pkgs.copyPkgconfigItems ];
|
nativeBuildInputs = with pkgs; [
|
||||||
|
cmake
|
||||||
|
gtest
|
||||||
|
copyPkgconfigItems
|
||||||
|
];
|
||||||
|
|
||||||
pkgconfigItems = [
|
pkgconfigItems = [
|
||||||
(pkgs.makePkgconfigItem rec {
|
(pkgs.makePkgconfigItem rec {
|
||||||
@@ -51,17 +55,18 @@
|
|||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
|
||||||
dontBuild = true;
|
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
runHook preInstall
|
runHook preInstall
|
||||||
mkdir -p $out/include
|
mkdir -p $out/include
|
||||||
cp include/*.hpp $out/include/
|
cp ../include/smath.hpp $out/include/
|
||||||
runHook postInstall
|
runHook postInstall
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
dontBuild = false;
|
||||||
|
doCheck = true;
|
||||||
|
|
||||||
meta = with pkgs.lib; {
|
meta = with pkgs.lib; {
|
||||||
description = desc;
|
description = "Single-file linear algebra math library for C++23.";
|
||||||
homepage = "https://github.com/slendidev/smath";
|
homepage = "https://github.com/slendidev/smath";
|
||||||
license = licenses.asl20;
|
license = licenses.asl20;
|
||||||
platforms = platforms.all;
|
platforms = platforms.all;
|
||||||
|
|||||||
1664
include/smath.hpp
1664
include/smath.hpp
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user