From a59e43496fb3e2aae6bf0fbdddc01dba4db1b219 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 24 Mar 2024 12:32:15 +0100 Subject: w --- src/search-astar.hpp | 2 +- src/search-node.hpp | 2 +- src/search-result.cpp | 23 ++++++++++++++++++++++- src/search-result.hpp | 23 +++++++++++------------ 4 files changed, 35 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/search-astar.hpp b/src/search-astar.hpp index ea150c76..c31b348f 100644 --- a/src/search-astar.hpp +++ b/src/search-astar.hpp @@ -11,7 +11,7 @@ namespace floormat { class world; struct point; -class path_search_result; +struct path_search_result; class astar { diff --git a/src/search-node.hpp b/src/search-node.hpp index c911e735..06bef04f 100644 --- a/src/search-node.hpp +++ b/src/search-node.hpp @@ -15,7 +15,7 @@ struct path_search_result::pair struct path_search_result::node { - friend class path_search_result; + friend struct path_search_result; friend struct test_app; node() noexcept; diff --git a/src/search-result.cpp b/src/search-result.cpp index 71cb9793..a35bc65a 100644 --- a/src/search-result.cpp +++ b/src/search-result.cpp @@ -11,7 +11,14 @@ namespace floormat { namespace { -constexpr size_t min_length = TILE_MAX_DIM*2; +constexpr auto min_length = TILE_MAX_DIM*2; + +void simplify_path(const std::vector& src, std::vector& dest) +{ + dest.clear(); + fm_assert(!src.empty()); + +} } // namespace @@ -77,6 +84,19 @@ bool path_search_result::is_found() const { return _found; } void path_search_result::set_found(bool value) { _found = value; } uint32_t path_search_result::distance() const { return _distance; } void path_search_result::set_distance(uint32_t dist) { _distance = dist; } +bool path_search_result::is_simplified() const { /*fm_assert(!_node->vec.empty());*/ return !_node->vec_.empty(); } +auto path_search_result::simplified() -> ArrayView +{ + if (!_node->vec_.empty()) + return { _node->vec_.data(), _node->vec_.size() }; + else + { + //fm_assert(!_node->vec.empty()); + simplify_path(_node->vec, _node->vec_); + fm_assert(!_node->vec_.empty()); + return { _node->vec_.data(), _node->vec_.size() }; + } +} auto path_search_result::data() const -> const point* { return _node->vec.data(); } path_search_result::operator bool() const { return !_node->vec.empty(); } @@ -93,6 +113,7 @@ const point& path_search_result::operator[](size_t index) const fm_debug_assert(index < _node->vec.size()); return data()[index]; } + vector_wrapper path_search_result::raw_path() { fm_assert(_node); return {_node->vec}; } ArrayView path_search_result::path() const { fm_assert(_node); return {_node->vec.data(), _node->vec.size()}; } diff --git a/src/search-result.hpp b/src/search-result.hpp index fc5397a0..1ca13cf2 100644 --- a/src/search-result.hpp +++ b/src/search-result.hpp @@ -1,5 +1,4 @@ #pragma once -#include "compat/defs.hpp" #include "compat/vector-wrapper-fwd.hpp" #include "src/global-coords.hpp" #include @@ -8,20 +7,12 @@ namespace floormat { struct point; -class path_search_result final +struct path_search_result final { friend struct test_app; struct pair; struct node; - Pointer _node; - float _time = 0; - uint32_t _cost = 0, _distance = (uint32_t)-1; - bool _found : 1 = false; - - static Pointer _pool; // NOLINT(*-avoid-non-const-global-variables) - -public: const point* data() const; const point& operator[](size_t index) const; size_t size() const; @@ -34,10 +25,10 @@ public: uint32_t distance() const; void set_distance(uint32_t dist); bool is_simplified() const; - const pair& simplified(); + ArrayView simplified(); vector_wrapper raw_path(); - vector_wrapper raw_simplified_path(); + vector_wrapper raw_simplified_path(); ArrayView path() const; explicit operator ArrayView() const; explicit operator bool() const; @@ -48,6 +39,14 @@ public: path_search_result(path_search_result&&) noexcept; path_search_result& operator=(path_search_result&&) noexcept; ~path_search_result() noexcept; + +private: + Pointer _node; + float _time = 0; + uint32_t _cost = 0, _distance = (uint32_t)-1; + bool _found : 1 = false; + + static Pointer _pool; // NOLINT(*-avoid-non-const-global-variables) }; } // namespace floormat -- cgit v1.2.3