diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2024-03-24 12:32:15 +0100 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-03-24 12:32:15 +0100 |
commit | a59e43496fb3e2aae6bf0fbdddc01dba4db1b219 (patch) | |
tree | daebfa7d3e98aff737c32404c70772ab61dd0889 /src | |
parent | edf5b8abd3435aae6dd65fcfbd26839071fc9c7e (diff) |
w
Diffstat (limited to 'src')
-rw-r--r-- | src/search-astar.hpp | 2 | ||||
-rw-r--r-- | src/search-node.hpp | 2 | ||||
-rw-r--r-- | src/search-result.cpp | 23 | ||||
-rw-r--r-- | src/search-result.hpp | 23 |
4 files changed, 35 insertions, 15 deletions
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<point>& src, std::vector<path_search_result::pair>& 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<const pair> +{ + 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<point, vector_wrapper_repr::ref> path_search_result::raw_path() { fm_assert(_node); return {_node->vec}; } ArrayView<const point> 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 <Corrade/Containers/Pointer.h> @@ -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> _node; - float _time = 0; - uint32_t _cost = 0, _distance = (uint32_t)-1; - bool _found : 1 = false; - - static Pointer<node> _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<const pair> simplified(); vector_wrapper<point, vector_wrapper_repr::ref> raw_path(); - vector_wrapper<point, vector_wrapper_repr::ref> raw_simplified_path(); + vector_wrapper<pair, vector_wrapper_repr::ref> raw_simplified_path(); ArrayView<const point> path() const; explicit operator ArrayView<const point>() 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> _node; + float _time = 0; + uint32_t _cost = 0, _distance = (uint32_t)-1; + bool _found : 1 = false; + + static Pointer<node> _pool; // NOLINT(*-avoid-non-const-global-variables) }; } // namespace floormat |