From 00e7c564fd5c72d44a6db887c2faa3e00e2ba8e3 Mon Sep 17 00:00:00 2001 From: Orange Date: Thu, 11 Jun 2026 16:18:42 +0300 Subject: [PATCH] added gcem --- CMakeLists.txt | 10 +++++++++ CMakePresets.json | 2 +- .../internal/optional_constexpr_math.hpp | 12 ++++++++++ include/omath/trigonometry/angle.hpp | 22 ++++++++++++++++--- vcpkg.json | 7 ++++++ 5 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 include/omath/internal/optional_constexpr_math.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index fd24fcd..8da5a63 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ option(OMATH_ENABLE_FORCE_INLINE option(OMATH_ENABLE_LUA "omath bindings for lua" OFF) option(OMATH_ENABLE_HOOKING "omath will HooksManager that can hook DirectX/OpenGL automatically" OFF) +option(OMATH_USE_GCEM "omath will use gcem library to make more functions/methods constexpr" OFF) if(VCPKG_MANIFEST_FEATURES) foreach(omath_feature IN LISTS VCPKG_MANIFEST_FEATURES) @@ -50,6 +51,8 @@ if(VCPKG_MANIFEST_FEATURES) set(OMATH_ENABLE_LUA ON) elseif(omath_feature STREQUAL "hooking") set(OMATH_ENABLE_HOOKING ON) + elseif (omath_feature STREQUAL "gcem") + set(OMATH_USE_GCEM ON) endif() endforeach() @@ -80,6 +83,7 @@ if(${PROJECT_IS_TOP_LEVEL}) message(STATUS "[${PROJECT_NAME}]: Coverage feature status ${OMATH_ENABLE_COVERAGE}") message(STATUS "[${PROJECT_NAME}]: Valgrind feature status ${OMATH_ENABLE_VALGRIND}") message(STATUS "[${PROJECT_NAME}]: Lua feature status ${OMATH_ENABLE_LUA}") + message(STATUS "[${PROJECT_NAME}]: Gcem feature status ${OMATH_USE_GCEM}") endif() if(OMATH_STATIC_MSVC_RUNTIME_LIBRARY) @@ -120,6 +124,12 @@ if (OMATH_ENABLE_HOOKING) endif () endif () + +if (OMATH_USE_GCEM) + target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_USE_GCEM) + find_package(gcem CONFIG REQUIRED) + target_link_libraries(${PROJECT_NAME} PUBLIC gcem) +endif () add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) target_compile_definitions(${PROJECT_NAME} PUBLIC OMATH_VERSION="${PROJECT_VERSION}") diff --git a/CMakePresets.json b/CMakePresets.json index 2ed29f2..f067ed3 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -57,7 +57,7 @@ "inherits": ["windows-base", "vcpkg-base"], "cacheVariables": { "VCPKG_TARGET_TRIPLET": "x64-windows-static", - "VCPKG_MANIFEST_FEATURES": "tests;imgui;avx2;examples;hooking", + "VCPKG_MANIFEST_FEATURES": "tests;imgui;avx2;examples;hooking;gcem", "OMATH_STATIC_MSVC_RUNTIME_LIBRARY": "ON" } }, diff --git a/include/omath/internal/optional_constexpr_math.hpp b/include/omath/internal/optional_constexpr_math.hpp new file mode 100644 index 0000000..ecc49dd --- /dev/null +++ b/include/omath/internal/optional_constexpr_math.hpp @@ -0,0 +1,12 @@ +// +// Created by orange on 6/11/2026. +// +#pragma once + + +#ifdef OMATH_USE_GCEM +#include +#define OMATH_CONSTEXPR constexpr +#else +#define OMATH_CONSTEXPR +#endif \ No newline at end of file diff --git a/include/omath/trigonometry/angle.hpp b/include/omath/trigonometry/angle.hpp index 4506e0c..7b687ee 100644 --- a/include/omath/trigonometry/angle.hpp +++ b/include/omath/trigonometry/angle.hpp @@ -7,6 +7,7 @@ #include #include #include +#include "omath/internal/optional_constexpr_math.hpp" namespace omath { @@ -70,21 +71,36 @@ namespace omath } [[nodiscard]] - Type sin() const noexcept + OMATH_CONSTEXPR Type sin() const noexcept { +#ifdef OMATH_USE_GCEM + return gcem::sin(as_radians()); +#else return std::sin(as_radians()); + +#endif } [[nodiscard]] - Type cos() const noexcept + OMATH_CONSTEXPR Type cos() const noexcept { +#ifdef OMATH_USE_GCEM + return gcem::cos(as_radians()); +#else return std::cos(as_radians()); + +#endif } [[nodiscard]] - Type tan() const noexcept + OMATH_CONSTEXPR Type tan() const noexcept { +#ifdef OMATH_USE_GCEM + return gcem::tan(as_radians()); +#else return std::tan(as_radians()); + +#endif } [[nodiscard]] diff --git a/vcpkg.json b/vcpkg.json index 27e3bef..5b68917 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -82,6 +82,13 @@ "lua", "sol2" ] + }, + "gcem": + { + "description": "Improve constexpr compatibility using gcem", + "dependencies": [ + "gcem" + ] } } }