From 4f8535d0d5b2c5a0e2577c5e88578bd2ce18c8d7 Mon Sep 17 00:00:00 2001 From: tamasmeszaros Date: Tue, 7 Jun 2022 16:05:16 +0200 Subject: [PATCH 1/2] Move out invalid_id constant from MutablePriotityQueue template class Enclose it into Slic3r namespace --- src/libslic3r/MutablePriorityQueue.hpp | 10 ++++++++-- tests/libslic3r/test_mutable_priority_queue.cpp | 2 ++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libslic3r/MutablePriorityQueue.hpp b/src/libslic3r/MutablePriorityQueue.hpp index b45b8cfff..fd3e7ac2d 100644 --- a/src/libslic3r/MutablePriorityQueue.hpp +++ b/src/libslic3r/MutablePriorityQueue.hpp @@ -7,6 +7,10 @@ #include #include // adds size_t (without std::) +namespace Slic3r { + +constexpr auto InvalidQueueID = std::numeric_limits::max(); + template class MutablePriorityQueue { @@ -41,7 +45,7 @@ public: bool empty() const { return m_heap.empty(); } T& operator[](std::size_t idx) noexcept { return m_heap[idx]; } const T& operator[](std::size_t idx) const noexcept { return m_heap[idx]; } - static constexpr size_t invalid_id() { return std::numeric_limits::max(); } + static constexpr size_t invalid_id() { return InvalidQueueID; } using iterator = typename std::vector::iterator; using const_iterator = typename std::vector::const_iterator; @@ -291,7 +295,7 @@ public: bool empty() const { return m_heap.empty(); } T& operator[](std::size_t idx) noexcept { assert(! address::is_padding(idx)); return m_heap[idx]; } const T& operator[](std::size_t idx) const noexcept { assert(! address::is_padding(idx)); return m_heap[idx]; } - static constexpr size_t invalid_id() { return std::numeric_limits::max(); } + static constexpr size_t invalid_id() { return InvalidQueueID; } protected: void update_heap_up(size_t top, size_t bottom); @@ -450,4 +454,6 @@ inline void MutableSkipHeapPriorityQueue Date: Tue, 7 Jun 2022 16:05:37 +0200 Subject: [PATCH 2/2] Make AStar use InvalidQueueID constant --- src/libslic3r/AStar.hpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/libslic3r/AStar.hpp b/src/libslic3r/AStar.hpp index 61c82157b..b35b6a4af 100644 --- a/src/libslic3r/AStar.hpp +++ b/src/libslic3r/AStar.hpp @@ -53,7 +53,7 @@ template struct TracerTraits_ template using TracerNodeT = typename TracerTraits_>::Node; -constexpr size_t Unassigned = size_t(-1); +constexpr auto Unassigned = std::numeric_limits::max(); template struct QNode // Queue node. Keeps track of scores g, and h @@ -69,7 +69,11 @@ struct QNode // Queue node. Keeps track of scores g, and h size_t p = Unassigned, float gval = std::numeric_limits::infinity(), float hval = 0.f) - : node{std::move(n)}, parent{p}, queue_id{Unassigned}, g{gval}, h{hval} + : node{std::move(n)} + , parent{p} + , queue_id{InvalidQueueID} + , g{gval} + , h{hval} {} }; @@ -154,7 +158,7 @@ bool search_route(const Tracer &tracer, // The cache needs to be updated either way prev_nd = qsucc_nd; - if (queue_id == decltype(qopen)::invalid_id()) + if (queue_id == InvalidQueueID) // was in closed or unqueued, rescheduling qopen.push(succ_id); else // was in open, updating