diff --git a/CMakeLists.txt b/CMakeLists.txt index 8338ee9..3d61db9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -23,6 +23,15 @@ option(OMATH_SUPRESS_SAFETY_CHECKS "Supress some safety checks in release build option(OMATH_USE_UNITY_BUILD "Will enable unity build to speed up compilation" OFF) option(OMATH_ENABLE_LEGACY "Will enable legacy classes that MUST be used ONLY for backward compatibility" OFF) +if (CMAKE_TOOLCHAIN_FILE) + foreach (omath_feature IN LISTS VCPKG_MANIFEST_FEATURES) + if (omath_feature STREQUAL "imgui") + set(OMATH_IMGUI_INTEGRATION ON) + elseif (omath_feature STREQUAL "avx2") + set(OMATH_USE_AVX2 ${COMPILER_SUPPORTS_AVX2}) + endif () + endforeach () +endif () if (OMATH_USE_AVX2 AND NOT COMPILER_SUPPORTS_AVX2) message(WARNING "OMATH_USE_AVX2 requested, but compiler/target does not support AVX2. Disabling.") set(OMATH_USE_AVX2 OFF CACHE BOOL "Omath will use AVX2 to boost performance" FORCE) diff --git a/include/omath/linear_algebra/vector2.hpp b/include/omath/linear_algebra/vector2.hpp index 2994144..7f16173 100644 --- a/include/omath/linear_algebra/vector2.hpp +++ b/include/omath/linear_algebra/vector2.hpp @@ -221,7 +221,7 @@ namespace omath } #ifdef OMATH_IMGUI_INTEGRATION [[nodiscard]] - ImVec2 to_im_vec2() const noexcept + constexpr ImVec2 to_im_vec2() const noexcept { return {static_cast(this->x), static_cast(this->y)}; } diff --git a/include/omath/linear_algebra/vector4.hpp b/include/omath/linear_algebra/vector4.hpp index 25d6a6d..48b0278 100644 --- a/include/omath/linear_algebra/vector4.hpp +++ b/include/omath/linear_algebra/vector4.hpp @@ -184,7 +184,7 @@ namespace omath #ifdef OMATH_IMGUI_INTEGRATION [[nodiscard]] - ImVec4 to_im_vec4() const noexcept + constexpr ImVec4 to_im_vec4() const noexcept { return { static_cast(this->x), diff --git a/tests/general/unit_test_imgui_intergration.cpp b/tests/general/unit_test_imgui_intergration.cpp new file mode 100644 index 0000000..0e6ddea --- /dev/null +++ b/tests/general/unit_test_imgui_intergration.cpp @@ -0,0 +1,39 @@ +// +// Created by Vlad on 10/23/2025. +// +#ifdef OMATH_IMGUI_INTEGRATION +#include +#include + +#define IMGUI_DEFINE_MATH_OPERATORS +#include + + + +using namespace omath; + +TEST(unit_test_imgui_intergration, Vector2ToImVec2) +{ + constexpr Vector2 omath_vector_2d = {1.f, 2.f}; + constexpr ImVec2 imgui_vector_2d = {1, 2.f}; + + constexpr auto converted = omath_vector_2d.to_im_vec2(); + EXPECT_NEAR(converted.x, imgui_vector_2d.x, 1.e-5f); + EXPECT_NEAR(converted.y, imgui_vector_2d.y, 1.e-5f); +} + +TEST(unit_test_imgui_intergration, Vector4ToImVec4) +{ + constexpr Vector4 omath_vector_2d = {1.f, 2.f, 3.f, 4.f}; + constexpr ImVec4 imgui_vector_4d = {1, 2.f, 3.f, 4.f}; + + constexpr auto converted = omath_vector_2d.to_im_vec4(); + + EXPECT_NEAR(converted.x, imgui_vector_4d.x, 1.e-5f); + EXPECT_NEAR(converted.y, imgui_vector_4d.y, 1.e-5f); + EXPECT_NEAR(converted.z, imgui_vector_4d.z, 1.e-5f); + EXPECT_NEAR(converted.w, imgui_vector_4d.w, 1.e-5f); +} + + +#endif diff --git a/vcpkg.json b/vcpkg.json new file mode 100644 index 0000000..0a8c9c1 --- /dev/null +++ b/vcpkg.json @@ -0,0 +1,31 @@ +{ + "name": "omath", + "version": "3.10.1", + "description": "General purpose math library", + "homepage": "https://github.com/orange-cpp/omath", + "license": "Zlib", + "supports": "windows | linux", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + + ], + "features": { + "avx2": { + "description": "Omath will use AVX2 to boost performance", + "supports": "!arm" + }, + "imgui": { + "description": "Omath will define method to convert omath types to imgui types", + "dependencies": [ + "imgui" + ] + } + } +} \ No newline at end of file