From 3685f1334438449dd676e9f84659e4ff0266bf38 Mon Sep 17 00:00:00 2001 From: Orange Date: Wed, 3 Dec 2025 13:34:35 +0300 Subject: [PATCH] back to static --- include/omath/collision/epa_algorithm.hpp | 25 ++++++++--------------- tests/general/unit_test_epa.cpp | 4 ++-- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/include/omath/collision/epa_algorithm.hpp b/include/omath/collision/epa_algorithm.hpp index dc85d57..9dd7de5 100644 --- a/include/omath/collision/epa_algorithm.hpp +++ b/include/omath/collision/epa_algorithm.hpp @@ -25,15 +25,6 @@ namespace omath::collision class Epa final { public: - explicit Epa(std::shared_ptr mem_resource = {std::shared_ptr{}, - std::pmr::get_default_resource()}, - const int max_iterations = 64, const float tolerance = 1e-4f) - : m_memory_resource(std::move(mem_resource)), m_max_iterations(max_iterations), m_tolerance(tolerance) - { - } - std::shared_ptr m_memory_resource; - int m_max_iterations{64}; - float m_tolerance{1e-4f}; using VectorType = ColliderType::VectorType; static_assert(EpaVector, "VertexType must satisfy EpaVector concept"); @@ -55,17 +46,19 @@ namespace omath::collision // Precondition: simplex.size()==4 and contains the origin. [[nodiscard]] - std::optional solve(const ColliderType& a, const ColliderType& b, const Simplex& simplex, - const Params params = {}) + static std::optional solve(const ColliderType& a, const ColliderType& b, + const Simplex& simplex, const Params params = {}, + std::shared_ptr mem_resource = { + std::shared_ptr{}, std::pmr::get_default_resource()}) { // --- Build initial polytope from simplex (4 points) --- - std::pmr::vector vertexes{m_memory_resource.get()}; + std::pmr::vector vertexes{mem_resource.get()}; vertexes.reserve(64); for (std::size_t i = 0; i < simplex.size(); ++i) vertexes.push_back(simplex[i]); // Initial tetra faces (windings corrected in make_face) - std::pmr::vector faces{m_memory_resource.get()}; + std::pmr::vector faces{mem_resource.get()}; faces.reserve(128); faces.emplace_back(make_face(vertexes, 0, 1, 2)); faces.emplace_back(make_face(vertexes, 0, 2, 3)); @@ -118,8 +111,8 @@ namespace omath::collision vertexes.push_back(p); // Mark faces visible from p and collect their horizon - std::pmr::vector to_delete(faces.size(), 0, m_memory_resource.get()); - std::pmr::vector boundary{m_memory_resource.get()}; + std::pmr::vector to_delete(faces.size(), 0, mem_resource.get()); + std::pmr::vector boundary{mem_resource.get()}; boundary.reserve(faces.size() * 2); for (int i = 0; i < static_cast(faces.size()); ++i) @@ -137,7 +130,7 @@ namespace omath::collision } // Remove visible faces - std::pmr::vector new_faces{m_memory_resource.get()}; + std::pmr::vector new_faces{mem_resource.get()}; new_faces.reserve(faces.size() + boundary.size()); for (int i = 0; i < static_cast(faces.size()); ++i) if (!to_delete[i]) diff --git a/tests/general/unit_test_epa.cpp b/tests/general/unit_test_epa.cpp index 4e686be..1b9cd5b 100644 --- a/tests/general/unit_test_epa.cpp +++ b/tests/general/unit_test_epa.cpp @@ -45,7 +45,7 @@ TEST(UnitTestEpa, TestCollisionTrue) auto pool = std::make_shared(1024); params.max_iterations = 64; params.tolerance = 1e-4f; - auto epa = EPA(pool).solve(A, B, gjk.simplex, params); + auto epa = EPA::solve(A, B, gjk.simplex, params, pool); ASSERT_TRUE(epa.has_value()) << "EPA should converge"; // Normal is unit @@ -119,7 +119,7 @@ TEST(UnitTestEpa, TestCollisionTrue2) params.max_iterations = 64; params.tolerance = 1e-4f; auto pool = std::make_shared(1024); - auto epa = EPA(pool).solve(A, B, gjk.simplex, params); + auto epa = EPA::solve(A, B, gjk.simplex, params, pool); ASSERT_TRUE(epa.has_value()) << "EPA should converge"; // Normal is unit-length