From c334176d737b9042d30b596c22861899100374d4 Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 18 Jun 2023 19:46:33 +0200 Subject: [PATCH] Use std::span for makeSmoothPath polygonPath --- components/detournavigator/findsmoothpath.cpp | 2 +- components/detournavigator/findsmoothpath.hpp | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/components/detournavigator/findsmoothpath.cpp b/components/detournavigator/findsmoothpath.cpp index 04de62c89a..95b4ac9a65 100644 --- a/components/detournavigator/findsmoothpath.cpp +++ b/components/detournavigator/findsmoothpath.cpp @@ -9,7 +9,7 @@ namespace DetourNavigator { - std::size_t fixupCorridor(std::vector& path, std::size_t pathSize, const std::vector& visited) + std::size_t fixupCorridor(std::span path, std::size_t pathSize, const std::vector& visited) { std::vector::const_reverse_iterator furthestVisited; diff --git a/components/detournavigator/findsmoothpath.hpp b/components/detournavigator/findsmoothpath.hpp index 097e81dc8a..e9b6fbc442 100644 --- a/components/detournavigator/findsmoothpath.hpp +++ b/components/detournavigator/findsmoothpath.hpp @@ -14,6 +14,7 @@ #include #include +#include #include namespace DetourNavigator @@ -23,8 +24,7 @@ namespace DetourNavigator return (osg::Vec2f(v1.x(), v1.z()) - osg::Vec2f(v2.x(), v2.z())).length() < r; } - std::size_t fixupCorridor( - std::vector& path, std::size_t pathSize, const std::vector& visited); + std::size_t fixupCorridor(std::span path, std::size_t pathSize, const std::vector& visited); // This function checks if the path has a small U-turn, that is, // a polygon further in the path is adjacent to the first polygon @@ -127,9 +127,11 @@ namespace DetourNavigator template Status makeSmoothPath(const dtNavMeshQuery& navMeshQuery, const dtQueryFilter& filter, const osg::Vec3f& start, - const osg::Vec3f& end, const float stepSize, std::vector& polygonPath, std::size_t polygonPathSize, + const osg::Vec3f& end, const float stepSize, std::span polygonPath, std::size_t polygonPathSize, std::size_t maxSmoothPathSize, OutputIterator& out) { + assert(polygonPathSize <= polygonPath.size()); + // Iterate over the path to find smooth path on the detail mesh surface. osg::Vec3f iterPos; navMeshQuery.closestPointOnPoly(polygonPath.front(), start.ptr(), iterPos.ptr(), nullptr);