added more noexcept

This commit is contained in:
2025-05-05 02:24:23 +03:00
parent 50ddf2d31e
commit 5489c296e9
4 changed files with 15 additions and 14 deletions

View File

@@ -15,16 +15,16 @@ namespace omath::pathfinding
public: public:
[[nodiscard]] [[nodiscard]]
static std::vector<Vector3<float>> find_path(const Vector3<float>& start, const Vector3<float>& end, static std::vector<Vector3<float>> find_path(const Vector3<float>& start, const Vector3<float>& end,
const NavigationMesh& nav_mesh); const NavigationMesh& nav_mesh) noexcept;
private: private:
[[nodiscard]] [[nodiscard]]
static std::vector<Vector3<float>> static std::vector<Vector3<float>>
reconstruct_final_path(const std::unordered_map<Vector3<float>, PathNode>& closed_list, reconstruct_final_path(const std::unordered_map<Vector3<float>, PathNode>& closed_list,
const Vector3<float>& current); const Vector3<float>& current) noexcept;
[[nodiscard]] [[nodiscard]]
static auto get_perfect_node(const std::unordered_map<Vector3<float>, PathNode>& open_list, static auto get_perfect_node(const std::unordered_map<Vector3<float>, PathNode>& open_list,
const Vector3<float>& end_vertex); const Vector3<float>& end_vertex) noexcept;
}; };
} // namespace omath::pathfinding } // namespace omath::pathfinding

View File

@@ -20,17 +20,17 @@ namespace omath::pathfinding
{ {
public: public:
[[nodiscard]] [[nodiscard]]
std::expected<Vector3<float>, std::string> get_closest_vertex(const Vector3<float>& point) const; std::expected<Vector3<float>, std::string> get_closest_vertex(const Vector3<float>& point) const noexcept;
[[nodiscard]] [[nodiscard]]
const std::vector<Vector3<float>>& get_neighbors(const Vector3<float>& vertex) const; const std::vector<Vector3<float>>& get_neighbors(const Vector3<float>& vertex) const noexcept;
[[nodiscard]] [[nodiscard]]
bool empty() const; bool empty() const;
[[nodiscard]] std::vector<uint8_t> serialize() const; [[nodiscard]] std::vector<uint8_t> serialize() const noexcept;
void deserialize(const std::vector<uint8_t>& raw); void deserialize(const std::vector<uint8_t>& raw) noexcept;
std::unordered_map<Vector3<float>, std::vector<Vector3<float>>> m_vertex_map; std::unordered_map<Vector3<float>, std::vector<Vector3<float>>> m_vertex_map;
}; };

View File

@@ -17,7 +17,7 @@ namespace omath::pathfinding
std::vector<Vector3<float>> std::vector<Vector3<float>>
Astar::reconstruct_final_path(const std::unordered_map<Vector3<float>, PathNode>& closed_list, Astar::reconstruct_final_path(const std::unordered_map<Vector3<float>, PathNode>& closed_list,
const Vector3<float>& current) const Vector3<float>& current) noexcept
{ {
std::vector<Vector3<float>> path; std::vector<Vector3<float>> path;
std::optional current_opt = current; std::optional current_opt = current;
@@ -38,7 +38,7 @@ namespace omath::pathfinding
return path; return path;
} }
auto Astar::get_perfect_node(const std::unordered_map<Vector3<float>, PathNode>& open_list, auto Astar::get_perfect_node(const std::unordered_map<Vector3<float>, PathNode>& open_list,
const Vector3<float>& end_vertex) const Vector3<float>& end_vertex) noexcept
{ {
return std::ranges::min_element(open_list, return std::ranges::min_element(open_list,
[&end_vertex](const auto& a, const auto& b) [&end_vertex](const auto& a, const auto& b)
@@ -50,7 +50,7 @@ namespace omath::pathfinding
} }
std::vector<Vector3<float>> Astar::find_path(const Vector3<float>& start, const Vector3<float>& end, std::vector<Vector3<float>> Astar::find_path(const Vector3<float>& start, const Vector3<float>& end,
const NavigationMesh& nav_mesh) const NavigationMesh& nav_mesh) noexcept
{ {
std::unordered_map<Vector3<float>, PathNode> closed_list; std::unordered_map<Vector3<float>, PathNode> closed_list;
std::unordered_map<Vector3<float>, PathNode> open_list; std::unordered_map<Vector3<float>, PathNode> open_list;

View File

@@ -6,7 +6,8 @@
#include <stdexcept> #include <stdexcept>
namespace omath::pathfinding namespace omath::pathfinding
{ {
std::expected<Vector3<float>, std::string> NavigationMesh::get_closest_vertex(const Vector3<float>& point) const std::expected<Vector3<float>, std::string>
NavigationMesh::get_closest_vertex(const Vector3<float>& point) const noexcept
{ {
const auto res = std::ranges::min_element(m_vertex_map, [&point](const auto& a, const auto& b) const auto res = std::ranges::min_element(m_vertex_map, [&point](const auto& a, const auto& b)
{ return a.first.distance_to(point) < b.first.distance_to(point); }); { return a.first.distance_to(point) < b.first.distance_to(point); });
@@ -17,7 +18,7 @@ namespace omath::pathfinding
return res->first; return res->first;
} }
const std::vector<Vector3<float>>& NavigationMesh::get_neighbors(const Vector3<float>& vertex) const const std::vector<Vector3<float>>& NavigationMesh::get_neighbors(const Vector3<float>& vertex) const noexcept
{ {
return m_vertex_map.at(vertex); return m_vertex_map.at(vertex);
} }
@@ -27,7 +28,7 @@ namespace omath::pathfinding
return m_vertex_map.empty(); return m_vertex_map.empty();
} }
std::vector<uint8_t> NavigationMesh::serialize() const std::vector<uint8_t> NavigationMesh::serialize() const noexcept
{ {
auto dump_to_vector = []<typename T>(const T& t, std::vector<uint8_t>& vec) auto dump_to_vector = []<typename T>(const T& t, std::vector<uint8_t>& vec)
{ {
@@ -50,7 +51,7 @@ namespace omath::pathfinding
return raw; return raw;
} }
void NavigationMesh::deserialize(const std::vector<uint8_t>& raw) void NavigationMesh::deserialize(const std::vector<uint8_t>& raw) noexcept
{ {
auto load_from_vector = [](const std::vector<uint8_t>& vec, size_t& offset, auto& value) auto load_from_vector = [](const std::vector<uint8_t>& vec, size_t& offset, auto& value)
{ {