diff options
author | Stanislaw Halik <sthalik@misaki.pl> | 2023-10-07 02:46:16 +0200 |
---|---|---|
committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-10-07 02:46:16 +0200 |
commit | bd3855592133bff90feef4fbecfd4fb84c861368 (patch) | |
tree | 7c631fccc049bedd4be271339f04693363b9132f /src/path-search-dijkstra.cpp | |
parent | 70d32f586ad17872809ca13f24d9fb36fb9ad213 (diff) |
a
Diffstat (limited to 'src/path-search-dijkstra.cpp')
-rw-r--r-- | src/path-search-dijkstra.cpp | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/path-search-dijkstra.cpp b/src/path-search-dijkstra.cpp index 404eb852..87b72a49 100644 --- a/src/path-search-dijkstra.cpp +++ b/src/path-search-dijkstra.cpp @@ -82,28 +82,28 @@ path_search_result path_search::Dijkstra(world& w, Vector2ub own_size, object_id if (from_offset_len >= eps && is_passable(w, ch0, bb0, own_id, p)) astar.push({from, from_offset, from, from_offset}, from_offset_len); - constexpr auto dirs = [] constexpr -> std::array<Vector2i, 8> { - constexpr auto sqrt_2 = math::sqrt(2.f); - std::array<Vector2i, 8> array = {{ - { -1, -1 }, - { 1, 1 }, - { -1, 1 }, - { 1, -1 }, - { -1, 0 }, - { 0, -1 }, - { 1, 0 }, - { 0, 1 }, + struct pair { Vector2i dir; uint32_t len; }; + + constexpr auto dirs = [] constexpr -> std::array<pair, 8> { + constexpr auto len1 = path_search::div_size; + constexpr auto len2 = (uint32_t)(math::sqrt((float)len1.dot()) + 0.5f); // NOLINT + std::array<pair, 8> array = {{ + { { -1, -1 }, len2 }, + { { 1, 1 }, len2 }, + { { -1, 1 }, len2 }, + { { 1, -1 }, len2 }, + { { -1, 0 }, len1.x() }, + { { 0, -1 }, len1.y() }, + { { 1, 0 }, len1.x() }, + { { 0, 1 }, len1.y() }, }}; + for (auto& [vec, len] : array) + vec *= path_search::div_size; +#if 0 for (auto i = 0uz; i < array.size(); i++) for (auto j = 0uz; j < i; j++) - fm_assert(array[i] != array[j]); - for (auto& vec : array) - { - if (vec.product() != 0) - vec = Vector2i(Vector2(vec) * path_search::div_size * sqrt_2); - else - vec *= path_search::div_size; - } + fm_assert(array[i].dir != array[j].dir); +#endif return array; }(); |