Merge branch 'master' of https://github.com/prusa3d/PrusaSlicer into et_trafo_matrix

This commit is contained in:
enricoturri1966 2022-05-18 09:15:50 +02:00
commit c592367fd2
27 changed files with 8940 additions and 8877 deletions

View File

@ -43,6 +43,14 @@ set(SLIC3R_GTK "2" CACHE STRING "GTK version to use with wxWidgets on Linux")
set(IS_CROSS_COMPILE FALSE) set(IS_CROSS_COMPILE FALSE)
if (SLIC3R_STATIC)
# Prefer config scripts over find modules. This is helpful when building with
# the static dependencies. Many libraries have their own export scripts
# while having a Find<PkgName> module in standard cmake installation.
# (e.g. CURL)
set(CMAKE_FIND_PACKAGE_PREFER_CONFIG ON)
endif ()
if (APPLE) if (APPLE)
set(CMAKE_FIND_FRAMEWORK LAST) set(CMAKE_FIND_FRAMEWORK LAST)
set(CMAKE_FIND_APPBUNDLE LAST) set(CMAKE_FIND_APPBUNDLE LAST)
@ -438,23 +446,6 @@ else()
target_link_libraries(libcurl INTERFACE crypt32) target_link_libraries(libcurl INTERFACE crypt32)
endif() endif()
if (SLIC3R_STATIC AND NOT SLIC3R_STATIC_EXCLUDE_CURL)
if (NOT APPLE)
# libcurl is always linked dynamically to the system libcurl on OSX.
# On other systems, libcurl is linked statically if SLIC3R_STATIC is set.
target_compile_definitions(libcurl INTERFACE CURL_STATICLIB)
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
# As of now, our build system produces a statically linked libcurl,
# which links the OpenSSL library dynamically.
find_package(OpenSSL REQUIRED)
message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}")
message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
target_include_directories(libcurl INTERFACE ${OPENSSL_INCLUDE_DIR})
target_link_libraries(libcurl INTERFACE ${OPENSSL_LIBRARIES})
endif()
endif()
## OPTIONAL packages ## OPTIONAL packages
# Find eigen3 or use bundled version # Find eigen3 or use bundled version
@ -472,6 +463,14 @@ include_directories(BEFORE SYSTEM ${EIGEN3_INCLUDE_DIR})
find_package(EXPAT REQUIRED) find_package(EXPAT REQUIRED)
add_library(libexpat INTERFACE)
if (TARGET EXPAT::EXPAT )
target_link_libraries(libexpat INTERFACE EXPAT::EXPAT)
elseif(TARGET expat::expat)
target_link_libraries(libexpat INTERFACE expat::expat)
endif ()
find_package(PNG REQUIRED) find_package(PNG REQUIRED)
set(OpenGL_GL_PREFERENCE "LEGACY") set(OpenGL_GL_PREFERENCE "LEGACY")

View File

@ -75,7 +75,9 @@ file(TO_NATIVE_PATH ${DESTDIR}/usr/local/ _prefix)
set(_boost_flags "") set(_boost_flags "")
if (UNIX) if (UNIX)
set(_boost_flags "cflags=-fPIC;cxxflags=-fPIC") set(_boost_flags "cflags=-fPIC;cxxflags=-fPIC")
elseif(APPLE) endif ()
if(APPLE)
set(_boost_flags set(_boost_flags
"cflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};" "cflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};"
"cxxflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};" "cxxflags=-fPIC -mmacosx-version-min=${DEP_OSX_TARGET};"

7
deps/CMakeLists.txt vendored
View File

@ -179,7 +179,12 @@ include(CGAL/CGAL.cmake)
include(NLopt/NLopt.cmake) include(NLopt/NLopt.cmake)
include(OpenSSL/OpenSSL.cmake) include(OpenSSL/OpenSSL.cmake)
set(CURL_PKG "")
if (NOT CURL_FOUND)
include(CURL/CURL.cmake) include(CURL/CURL.cmake)
set(CURL_PKG dep_CURL)
endif ()
include(JPEG/JPEG.cmake) include(JPEG/JPEG.cmake)
include(TIFF/TIFF.cmake) include(TIFF/TIFF.cmake)
@ -188,7 +193,7 @@ include(wxWidgets/wxWidgets.cmake)
set(_dep_list set(_dep_list
dep_Boost dep_Boost
dep_TBB dep_TBB
dep_CURL ${CURL_PKG}
dep_wxWidgets dep_wxWidgets
dep_Cereal dep_Cereal
dep_NLopt dep_NLopt

12
deps/CURL/CURL.cmake vendored
View File

@ -48,10 +48,12 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
) )
endif () endif ()
if (BUILD_SHARED_LIBS) set(_patch_command "")
set(_curl_static OFF) if (UNIX AND NOT APPLE)
else() # On non-apple UNIX platforms, finding the location of OpenSSL certificates is necessary at runtime, as there is no standard location usable across platforms.
set(_curl_static ON) # The OPENSSL_CERT_OVERRIDE flag is understood by PrusaSlicer and will trigger the search of certificates at initial application launch.
# Then ask the user for consent about the correctness of the found location.
set (_patch_command echo set_target_properties(CURL::libcurl PROPERTIES INTERFACE_COMPILE_DEFINITIONS OPENSSL_CERT_OVERRIDE) >> CMake/curl-config.cmake.in)
endif () endif ()
prusaslicer_add_cmake_project(CURL prusaslicer_add_cmake_project(CURL
@ -62,10 +64,10 @@ prusaslicer_add_cmake_project(CURL
DEPENDS ${ZLIB_PKG} DEPENDS ${ZLIB_PKG}
# PATCH_COMMAND ${GIT_EXECUTABLE} checkout -f -- . && git clean -df && # PATCH_COMMAND ${GIT_EXECUTABLE} checkout -f -- . && git clean -df &&
# ${GIT_EXECUTABLE} apply --whitespace=fix ${CMAKE_CURRENT_LIST_DIR}/curl-mods.patch # ${GIT_EXECUTABLE} apply --whitespace=fix ${CMAKE_CURRENT_LIST_DIR}/curl-mods.patch
PATCH_COMMAND "${_patch_command}"
CMAKE_ARGS CMAKE_ARGS
-DBUILD_TESTING:BOOL=OFF -DBUILD_TESTING:BOOL=OFF
-DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DCURL_STATICLIB=${_curl_static}
${_curl_platform_flags} ${_curl_platform_flags}
) )

View File

@ -15,6 +15,11 @@ set(DEP_CMAKE_OPTS
include("deps-unix-common.cmake") include("deps-unix-common.cmake")
find_package(CURL QUIET)
if (NOT CURL_FOUND)
message(WARNING "No CURL dev package found in system, building static library. Mac SDK should include CURL from at least version 10.12. Check your SDK installation.")
endif ()
# ExternalProject_Add(dep_boost # ExternalProject_Add(dep_boost
# EXCLUDE_FROM_ALL 1 # EXCLUDE_FROM_ALL 1

View File

@ -970,10 +970,7 @@ renamed_from = "Creality ENDER-3 BLTouch"
printer_model = ENDER3BLTOUCH printer_model = ENDER3BLTOUCH
[printer:Creality Ender-3 Pro] [printer:Creality Ender-3 Pro]
inherits = *common*; *pauseprint* inherits = Creality Ender-3; *pauseprint*
renamed_from = "Creality Ender-3 Pro"
bed_shape = 5x0,215x0,215x220,5x220
max_print_height = 250
printer_model = ENDER3PRO printer_model = ENDER3PRO
printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_CREALITY\nPRINTER_MODEL_ENDER3PRO\nPRINTER_HAS_BOWDEN printer_notes = Don't remove the following keywords! These keywords are used in the "compatible printer" condition of the print and filament profiles to link the particular print and filament profiles to this printer profile.\nPRINTER_VENDOR_CREALITY\nPRINTER_MODEL_ENDER3PRO\nPRINTER_HAS_BOWDEN

View File

@ -92,7 +92,7 @@ if (SLIC3R_GUI)
string(REGEX MATCH "wxexpat" WX_EXPAT_BUILTIN ${wxWidgets_LIBRARIES}) string(REGEX MATCH "wxexpat" WX_EXPAT_BUILTIN ${wxWidgets_LIBRARIES})
if (EXPAT_FOUND AND NOT WX_EXPAT_BUILTIN) if (EXPAT_FOUND AND NOT WX_EXPAT_BUILTIN)
list(FILTER wxWidgets_LIBRARIES EXCLUDE REGEX expat) list(FILTER wxWidgets_LIBRARIES EXCLUDE REGEX expat)
list(APPEND wxWidgets_LIBRARIES EXPAT::EXPAT) list(APPEND wxWidgets_LIBRARIES libexpat)
endif () endif ()
# This is an issue in the new wxWidgets cmake build, doesn't deal with librt # This is an issue in the new wxWidgets cmake build, doesn't deal with librt

View File

@ -372,7 +372,7 @@ target_link_libraries(libslic3r
boost_libs boost_libs
clipper clipper
nowide nowide
EXPAT::EXPAT libexpat
glu-libtess glu-libtess
qhull qhull
semver semver

View File

@ -129,9 +129,10 @@ GroundingLocation Layer::getBestGroundingLocation
if (contour.size() > 2) { if (contour.size() > 2) {
Point prev = contour.points.back(); Point prev = contour.points.back();
for (const Point &p2 : contour.points) { for (const Point &p2 : contour.points) {
if (double d = Line::distance_to_squared(unsupported_location, prev, p2); d < d2) { Point closest_point;
if (double d = line_alg::distance_to_squared(Line{prev, p2}, unsupported_location, &closest_point); d < d2) {
d2 = d; d2 = d;
node_location = Geometry::foot_pt({ prev, p2 }, unsupported_location).cast<coord_t>(); node_location = closest_point;
} }
prev = p2; prev = p2;
} }

View File

@ -3,6 +3,9 @@
#include <assert.h> #include <assert.h>
#include <type_traits> #include <type_traits>
#include <vector>
#include <limits>
#include <cstdlib> // adds size_t (without std::)
template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false> template<typename T, typename IndexSetter, typename LessPredicate, const bool ResetIndexWhenRemoved = false>
class MutablePriorityQueue class MutablePriorityQueue
@ -21,7 +24,7 @@ public:
MutablePriorityQueue& operator=(MutablePriorityQueue &&) = default; MutablePriorityQueue& operator=(MutablePriorityQueue &&) = default;
// This class modifies the outside data through the m_index_setter // This class modifies the outside data through the m_index_setter
// and thus it should not be copied. The semantics are similar to std::unique_ptr // and thus it should not be copied. The semantics is similar to std::unique_ptr
MutablePriorityQueue(const MutablePriorityQueue &) = delete; MutablePriorityQueue(const MutablePriorityQueue &) = delete;
MutablePriorityQueue& operator=(const MutablePriorityQueue &) = delete; MutablePriorityQueue& operator=(const MutablePriorityQueue &) = delete;
@ -38,6 +41,7 @@ public:
bool empty() const { return m_heap.empty(); } bool empty() const { return m_heap.empty(); }
T& operator[](std::size_t idx) noexcept { return m_heap[idx]; } T& operator[](std::size_t idx) noexcept { return m_heap[idx]; }
const T& operator[](std::size_t idx) const 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<size_t>::max(); }
using iterator = typename std::vector<T>::iterator; using iterator = typename std::vector<T>::iterator;
using const_iterator = typename std::vector<T>::const_iterator; using const_iterator = typename std::vector<T>::const_iterator;
@ -66,14 +70,10 @@ MutablePriorityQueue<T, IndexSetter, LessPredicate, ResetIndexWhenRemoved> make_
template<class T, class LessPredicate, class IndexSetter, const bool ResetIndexWhenRemoved> template<class T, class LessPredicate, class IndexSetter, const bool ResetIndexWhenRemoved>
inline void MutablePriorityQueue<T, LessPredicate, IndexSetter, ResetIndexWhenRemoved>::clear() inline void MutablePriorityQueue<T, LessPredicate, IndexSetter, ResetIndexWhenRemoved>::clear()
{ {
#ifdef NDEBUG if constexpr (ResetIndexWhenRemoved) {
// Only mark as removed from the queue in release mode, if configured so.
if (ResetIndexWhenRemoved)
#endif /* NDEBUG */
{
for (size_t idx = 0; idx < m_heap.size(); ++ idx) for (size_t idx = 0; idx < m_heap.size(); ++ idx)
// Mark as removed from the queue. // Mark as removed from the queue.
m_index_setter(m_heap[idx], std::numeric_limits<size_t>::max()); m_index_setter(m_heap[idx], this->invalid_id());
} }
m_heap.clear(); m_heap.clear();
} }
@ -100,13 +100,9 @@ template<class T, class LessPredicate, class IndexSetter, const bool ResetIndexW
inline void MutablePriorityQueue<T, LessPredicate, IndexSetter, ResetIndexWhenRemoved>::pop() inline void MutablePriorityQueue<T, LessPredicate, IndexSetter, ResetIndexWhenRemoved>::pop()
{ {
assert(! m_heap.empty()); assert(! m_heap.empty());
#ifdef NDEBUG if constexpr (ResetIndexWhenRemoved) {
// Only mark as removed from the queue in release mode, if configured so.
if (ResetIndexWhenRemoved)
#endif /* NDEBUG */
{
// Mark as removed from the queue. // Mark as removed from the queue.
m_index_setter(m_heap.front(), std::numeric_limits<size_t>::max()); m_index_setter(m_heap.front(), this->invalid_id());
} }
if (m_heap.size() > 1) { if (m_heap.size() > 1) {
m_heap.front() = m_heap.back(); m_heap.front() = m_heap.back();
@ -121,13 +117,10 @@ template<class T, class LessPredicate, class IndexSetter, const bool ResetIndexW
inline void MutablePriorityQueue<T, LessPredicate, IndexSetter, ResetIndexWhenRemoved>::remove(size_t idx) inline void MutablePriorityQueue<T, LessPredicate, IndexSetter, ResetIndexWhenRemoved>::remove(size_t idx)
{ {
assert(idx < m_heap.size()); assert(idx < m_heap.size());
#ifdef NDEBUG
// Only mark as removed from the queue in release mode, if configured so. // Only mark as removed from the queue in release mode, if configured so.
if (ResetIndexWhenRemoved) if constexpr (ResetIndexWhenRemoved) {
#endif /* NDEBUG */
{
// Mark as removed from the queue. // Mark as removed from the queue.
m_index_setter(m_heap[idx], std::numeric_limits<size_t>::max()); m_index_setter(m_heap[idx], this->invalid_id());
} }
if (idx + 1 == m_heap.size()) { if (idx + 1 == m_heap.size()) {
m_heap.pop_back(); m_heap.pop_back();
@ -274,6 +267,14 @@ public:
{} {}
~MutableSkipHeapPriorityQueue() { clear(); } ~MutableSkipHeapPriorityQueue() { clear(); }
MutableSkipHeapPriorityQueue(MutableSkipHeapPriorityQueue &&) = default;
MutableSkipHeapPriorityQueue &operator=(MutableSkipHeapPriorityQueue &&) = default;
// This class modifies the outside data through the m_index_setter
// and thus it should not be copied. The semantics is similar to std::unique_ptr
MutableSkipHeapPriorityQueue(const MutableSkipHeapPriorityQueue &) = delete;
MutableSkipHeapPriorityQueue &operator=(const MutableSkipHeapPriorityQueue &) = delete;
void clear(); void clear();
// Reserve one unused element per miniheap. // Reserve one unused element per miniheap.
void reserve(size_t cnt) { m_heap.reserve(cnt + ((cnt + (address::block_size - 1)) / (address::block_size - 1))); } void reserve(size_t cnt) { m_heap.reserve(cnt + ((cnt + (address::block_size - 1)) / (address::block_size - 1))); }
@ -285,9 +286,12 @@ public:
void update(size_t idx) { assert(! address::is_padding(idx)); T item = m_heap[idx]; remove(idx); push(item); } void update(size_t idx) { assert(! address::is_padding(idx)); T item = m_heap[idx]; remove(idx); push(item); }
// There is one padding element storead at each miniheap, thus lower the number of elements by the number of miniheaps. // There is one padding element storead at each miniheap, thus lower the number of elements by the number of miniheaps.
size_t size() const noexcept { return m_heap.size() - (m_heap.size() + address::block_size - 1) / address::block_size; } size_t size() const noexcept { return m_heap.size() - (m_heap.size() + address::block_size - 1) / address::block_size; }
// Number of heap elements including padding. heap_size() >= size().
size_t heap_size() const noexcept { return m_heap.size(); }
bool empty() const { return m_heap.empty(); } bool empty() const { return m_heap.empty(); }
T& operator[](std::size_t idx) noexcept { assert(! address::is_padding(idx)); return m_heap[idx]; } 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]; } 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<size_t>::max(); }
protected: protected:
void update_heap_up(size_t top, size_t bottom); void update_heap_up(size_t top, size_t bottom);
@ -317,15 +321,11 @@ MutableSkipHeapPriorityQueue<T, IndexSetter, LessPredicate, BlockSize, ResetInde
template<class T, class LessPredicate, class IndexSetter, std::size_t blocking, const bool ResetIndexWhenRemoved> template<class T, class LessPredicate, class IndexSetter, std::size_t blocking, const bool ResetIndexWhenRemoved>
inline void MutableSkipHeapPriorityQueue<T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved>::clear() inline void MutableSkipHeapPriorityQueue<T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved>::clear()
{ {
#ifdef NDEBUG if constexpr (ResetIndexWhenRemoved) {
// Only mark as removed from the queue in release mode, if configured so.
if (ResetIndexWhenRemoved)
#endif /* NDEBUG */
{
for (size_t idx = 0; idx < m_heap.size(); ++ idx) for (size_t idx = 0; idx < m_heap.size(); ++ idx)
// Mark as removed from the queue. // Mark as removed from the queue.
if (! address::is_padding(idx)) if (! address::is_padding(idx))
m_index_setter(m_heap[idx], std::numeric_limits<size_t>::max()); m_index_setter(m_heap[idx], this->invalid_id());
} }
m_heap.clear(); m_heap.clear();
} }
@ -356,13 +356,9 @@ template<class T, class LessPredicate, class IndexSetter, std::size_t blocking,
inline void MutableSkipHeapPriorityQueue<T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved>::pop() inline void MutableSkipHeapPriorityQueue<T, LessPredicate, IndexSetter, blocking, ResetIndexWhenRemoved>::pop()
{ {
assert(! m_heap.empty()); assert(! m_heap.empty());
#ifdef NDEBUG if constexpr (ResetIndexWhenRemoved) {
// Only mark as removed from the queue in release mode, if configured so.
if (ResetIndexWhenRemoved)
#endif /* NDEBUG */
{
// Mark as removed from the queue. // Mark as removed from the queue.
m_index_setter(m_heap[1], std::numeric_limits<size_t>::max()); m_index_setter(m_heap[1], this->invalid_id());
} }
// Zero'th element is padding, thus non-empty queue must have at least two elements. // Zero'th element is padding, thus non-empty queue must have at least two elements.
if (m_heap.size() > 2) { if (m_heap.size() > 2) {
@ -379,13 +375,9 @@ inline void MutableSkipHeapPriorityQueue<T, LessPredicate, IndexSetter, blocking
{ {
assert(idx < m_heap.size()); assert(idx < m_heap.size());
assert(! address::is_padding(idx)); assert(! address::is_padding(idx));
#ifdef NDEBUG if constexpr (ResetIndexWhenRemoved) {
// Only mark as removed from the queue in release mode, if configured so.
if (ResetIndexWhenRemoved)
#endif /* NDEBUG */
{
// Mark as removed from the queue. // Mark as removed from the queue.
m_index_setter(m_heap[idx], std::numeric_limits<size_t>::max()); m_index_setter(m_heap[idx], this->invalid_id());
} }
if (idx + 1 == m_heap.size()) { if (idx + 1 == m_heap.size()) {
this->pop_back(); this->pop_back();

View File

@ -13,6 +13,7 @@
#include "GCode.hpp" #include "GCode.hpp"
#include "GCode/WipeTower.hpp" #include "GCode/WipeTower.hpp"
#include "Utils.hpp" #include "Utils.hpp"
#include "BuildVolume.hpp"
#include <float.h> #include <float.h>
@ -387,7 +388,7 @@ bool Print::sequential_print_horizontal_clearance_valid(const Print& print, Poly
Geometry::assemble_transform({ 0.0, 0.0, model_instance0->get_offset().z() }, model_instance0->get_rotation(), model_instance0->get_scaling_factor(), model_instance0->get_mirror())), Geometry::assemble_transform({ 0.0, 0.0, model_instance0->get_offset().z() }, model_instance0->get_rotation(), model_instance0->get_scaling_factor(), model_instance0->get_mirror())),
// Shrink the extruder_clearance_radius a tiny bit, so that if the object arrangement algorithm placed the objects // Shrink the extruder_clearance_radius a tiny bit, so that if the object arrangement algorithm placed the objects
// exactly by satisfying the extruder_clearance_radius, this test will not trigger collision. // exactly by satisfying the extruder_clearance_radius, this test will not trigger collision.
float(scale_(0.5 * print.config().extruder_clearance_radius.value - EPSILON)), float(scale_(0.5 * print.config().extruder_clearance_radius.value - BuildVolume::BedEpsilon)),
jtRound, scale_(0.1)).front()); jtRound, scale_(0.1)).front());
} }
// Make a copy, so it may be rotated for instances. // Make a copy, so it may be rotated for instances.

View File

@ -195,7 +195,15 @@ std::vector<std::pair<size_t, bool>> chain_segments_greedy_constrained_reversals
} }
// Initialize a heap of end points sorted by the lowest distance to the next valid point of a path. // Initialize a heap of end points sorted by the lowest distance to the next valid point of a path.
auto queue = make_mutable_priority_queue<EndPoint*, false>( auto queue = make_mutable_priority_queue<EndPoint*,
#ifndef NDEBUG
// In debug mode, reset indices when removing an item from the queue for debugging purposes.
true
#else // NDEBUG
// In release mode, don't reset indices when removing an item from the queue.
false
#endif // NDEBUG
>(
[](EndPoint *ep, size_t idx){ ep->heap_idx = idx; }, [](EndPoint *ep, size_t idx){ ep->heap_idx = idx; },
[](EndPoint *l, EndPoint *r){ return l->distance_out < r->distance_out; }); [](EndPoint *l, EndPoint *r){ return l->distance_out < r->distance_out; });
queue.reserve(end_points.size() * 2 - 1); queue.reserve(end_points.size() * 2 - 1);
@ -213,7 +221,7 @@ std::vector<std::pair<size_t, bool>> chain_segments_greedy_constrained_reversals
assert(ep.chain_id == 0); assert(ep.chain_id == 0);
} else { } else {
// End point is NOT on the heap, therefore it is part of the output path. // End point is NOT on the heap, therefore it is part of the output path.
assert(ep.heap_idx == std::numeric_limits<size_t>::max()); assert(ep.heap_idx == queue.invalid_id());
assert(ep.chain_id != 0); assert(ep.chain_id != 0);
if (&ep == first_point) { if (&ep == first_point) {
assert(ep.edge_out == nullptr); assert(ep.edge_out == nullptr);
@ -222,7 +230,7 @@ std::vector<std::pair<size_t, bool>> chain_segments_greedy_constrained_reversals
// Detect loops. // Detect loops.
for (EndPoint *pt = &ep; pt != nullptr;) { for (EndPoint *pt = &ep; pt != nullptr;) {
// Out of queue. It is a final point. // Out of queue. It is a final point.
assert(pt->heap_idx == std::numeric_limits<size_t>::max()); assert(pt->heap_idx == queue.invalid_id());
EndPoint *pt_other = &end_points[(pt - &end_points.front()) ^ 1]; EndPoint *pt_other = &end_points[(pt - &end_points.front()) ^ 1];
if (pt_other->heap_idx < queue.size()) if (pt_other->heap_idx < queue.size())
// The other side of this segment is undecided yet. // The other side of this segment is undecided yet.

View File

@ -87,6 +87,8 @@
#define ENABLE_USED_FILAMENT_POST_PROCESS (1 && ENABLE_2_5_0_ALPHA1) #define ENABLE_USED_FILAMENT_POST_PROCESS (1 && ENABLE_2_5_0_ALPHA1)
// Enable gizmo grabbers to share common models // Enable gizmo grabbers to share common models
#define ENABLE_GIZMO_GRABBER_REFACTOR (1 && ENABLE_2_5_0_ALPHA1) #define ENABLE_GIZMO_GRABBER_REFACTOR (1 && ENABLE_2_5_0_ALPHA1)
// Disable association to 3mf and stl files if the application is run on Windows 8 or later
#define ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER (1 && ENABLE_2_5_0_ALPHA1)
#endif // _prusaslicer_technologies_h_ #endif // _prusaslicer_technologies_h_

View File

@ -292,10 +292,6 @@ if (SLIC3R_STATIC)
target_compile_definitions(libslic3r_gui PUBLIC -DwxDEBUG_LEVEL=0) target_compile_definitions(libslic3r_gui PUBLIC -DwxDEBUG_LEVEL=0)
endif() endif()
if (SLIC3R_STATIC AND NOT SLIC3R_STATIC_EXCLUDE_CURL AND UNIX AND NOT APPLE)
target_compile_definitions(libslic3r_gui PRIVATE OPENSSL_CERT_OVERRIDE)
endif ()
if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY) if (SLIC3R_PCH AND NOT SLIC3R_SYNTAXONLY)
add_precompiled_header(libslic3r_gui pchheader.hpp FORCEINCLUDE) add_precompiled_header(libslic3r_gui pchheader.hpp FORCEINCLUDE)
endif () endif ()

View File

@ -1934,6 +1934,9 @@ void ConfigWizard::priv::load_pages()
index->add_page(page_update); index->add_page(page_update);
index->add_page(page_reload_from_disk); index->add_page(page_reload_from_disk);
#ifdef _WIN32 #ifdef _WIN32
#if ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
if (page_files_association != nullptr)
#endif // ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
index->add_page(page_files_association); index->add_page(page_files_association);
#endif // _WIN32 #endif // _WIN32
index->add_page(page_mode); index->add_page(page_mode);
@ -2747,6 +2750,9 @@ bool ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
app_config->set("export_sources_full_pathnames", page_reload_from_disk->full_pathnames ? "1" : "0"); app_config->set("export_sources_full_pathnames", page_reload_from_disk->full_pathnames ? "1" : "0");
#ifdef _WIN32 #ifdef _WIN32
#if ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
if (page_files_association != nullptr) {
#endif // ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
app_config->set("associate_3mf", page_files_association->associate_3mf() ? "1" : "0"); app_config->set("associate_3mf", page_files_association->associate_3mf() ? "1" : "0");
app_config->set("associate_stl", page_files_association->associate_stl() ? "1" : "0"); app_config->set("associate_stl", page_files_association->associate_stl() ? "1" : "0");
// app_config->set("associate_gcode", page_files_association->associate_gcode() ? "1" : "0"); // app_config->set("associate_gcode", page_files_association->associate_gcode() ? "1" : "0");
@ -2761,6 +2767,14 @@ bool ConfigWizard::priv::apply_config(AppConfig *app_config, PresetBundle *prese
// if (page_files_association->associate_gcode()) // if (page_files_association->associate_gcode())
// wxGetApp().associate_gcode_files(); // wxGetApp().associate_gcode_files();
// } // }
#if ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
}
else {
app_config->set("associate_3mf", "0");
app_config->set("associate_stl", "0");
// app_config->set("associate_gcode", "0");
}
#endif // ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
#endif // _WIN32 #endif // _WIN32
@ -2921,6 +2935,10 @@ ConfigWizard::ConfigWizard(wxWindow *parent)
p->add_page(p->page_update = new PageUpdate(this)); p->add_page(p->page_update = new PageUpdate(this));
p->add_page(p->page_reload_from_disk = new PageReloadFromDisk(this)); p->add_page(p->page_reload_from_disk = new PageReloadFromDisk(this));
#ifdef _WIN32 #ifdef _WIN32
#if ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
// file association is not possible anymore starting with Win 8
if (wxPlatformInfo::Get().GetOSMajorVersion() < 8)
#endif // ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
p->add_page(p->page_files_association = new PageFilesAssociation(this)); p->add_page(p->page_files_association = new PageFilesAssociation(this));
#endif // _WIN32 #endif // _WIN32
p->add_page(p->page_mode = new PageMode(this)); p->add_page(p->page_mode = new PageMode(this));

View File

@ -386,14 +386,14 @@ void GCodeViewer::SequentialView::Marker::render()
ImGui::PopStyleVar(); ImGui::PopStyleVar();
} }
void GCodeViewer::SequentialView::GCodeWindow::load_gcode(const std::string& filename, std::vector<size_t> &&lines_ends) void GCodeViewer::SequentialView::GCodeWindow::load_gcode(const std::string& filename, const std::vector<size_t>& lines_ends)
{ {
assert(! m_file.is_open()); assert(! m_file.is_open());
if (m_file.is_open()) if (m_file.is_open())
return; return;
m_filename = filename; m_filename = filename;
m_lines_ends = std::move(lines_ends); m_lines_ends = lines_ends;
m_selected_line_id = 0; m_selected_line_id = 0;
m_last_lines_size = 0; m_last_lines_size = 0;
@ -771,9 +771,7 @@ void GCodeViewer::load(const GCodeProcessorResult& gcode_result, const Print& pr
// release gpu memory, if used // release gpu memory, if used
reset(); reset();
m_sequential_view.gcode_window.load_gcode(gcode_result.filename, m_sequential_view.gcode_window.load_gcode(gcode_result.filename, gcode_result.lines_ends);
// Stealing out lines_ends should be safe because this gcode_result is processed only once (see the 1st if in this function).
std::move(const_cast<std::vector<size_t>&>(gcode_result.lines_ends)));
if (wxGetApp().is_gcode_viewer()) if (wxGetApp().is_gcode_viewer())
m_custom_gcode_per_print_z = gcode_result.custom_gcode_per_print_z; m_custom_gcode_per_print_z = gcode_result.custom_gcode_per_print_z;

View File

@ -703,7 +703,7 @@ public:
public: public:
GCodeWindow() = default; GCodeWindow() = default;
~GCodeWindow() { stop_mapping_file(); } ~GCodeWindow() { stop_mapping_file(); }
void load_gcode(const std::string& filename, std::vector<size_t> &&lines_ends); void load_gcode(const std::string& filename, const std::vector<size_t>& lines_ends);
void reset() { void reset() {
stop_mapping_file(); stop_mapping_file();
m_lines_ends.clear(); m_lines_ends.clear();

View File

@ -7434,12 +7434,13 @@ bool GLCanvas3D::_is_any_volume_outside() const
void GLCanvas3D::_update_selection_from_hover() void GLCanvas3D::_update_selection_from_hover()
{ {
bool ctrl_pressed = wxGetKeyState(WXK_CONTROL); bool ctrl_pressed = wxGetKeyState(WXK_CONTROL);
bool selection_changed = false;
if (m_hover_volume_idxs.empty()) { if (m_hover_volume_idxs.empty()) {
if (!ctrl_pressed && m_rectangle_selection.get_state() == GLSelectionRectangle::EState::Select) if (!ctrl_pressed && m_rectangle_selection.get_state() == GLSelectionRectangle::EState::Select) {
selection_changed = ! m_selection.is_empty();
m_selection.remove_all(); m_selection.remove_all();
}
return;
} }
GLSelectionRectangle::EState state = m_rectangle_selection.get_state(); GLSelectionRectangle::EState state = m_rectangle_selection.get_state();
@ -7452,7 +7453,6 @@ void GLCanvas3D::_update_selection_from_hover()
} }
} }
bool selection_changed = false;
#if ENABLE_NEW_RECTANGLE_SELECTION #if ENABLE_NEW_RECTANGLE_SELECTION
if (!m_rectangle_selection.is_empty()) { if (!m_rectangle_selection.is_empty()) {
#endif // ENABLE_NEW_RECTANGLE_SELECTION #endif // ENABLE_NEW_RECTANGLE_SELECTION

View File

@ -1203,10 +1203,17 @@ bool GUI_App::on_init_inner()
if (is_editor()) { if (is_editor()) {
#ifdef __WXMSW__ #ifdef __WXMSW__
#if ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
// file association is not possible anymore starting with Win 8
if (wxPlatformInfo::Get().GetOSMajorVersion() < 8) {
#endif // ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
if (app_config->get("associate_3mf") == "1") if (app_config->get("associate_3mf") == "1")
associate_3mf_files(); associate_3mf_files();
if (app_config->get("associate_stl") == "1") if (app_config->get("associate_stl") == "1")
associate_stl_files(); associate_stl_files();
#if ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
}
#endif // ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
#endif // __WXMSW__ #endif // __WXMSW__
preset_updater = new PresetUpdater(); preset_updater = new PresetUpdater();
@ -1244,8 +1251,15 @@ bool GUI_App::on_init_inner()
} }
else { else {
#ifdef __WXMSW__ #ifdef __WXMSW__
#if ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
// file association is not possible anymore starting with Win 8
if (wxPlatformInfo::Get().GetOSMajorVersion() < 8) {
#endif // ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
if (app_config->get("associate_gcode") == "1") if (app_config->get("associate_gcode") == "1")
associate_gcode_files(); associate_gcode_files();
#if ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
}
#endif // ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
#endif // __WXMSW__ #endif // __WXMSW__
} }
@ -2418,6 +2432,10 @@ void GUI_App::open_preferences(const std::string& highlight_option /*= std::stri
this->plater_->refresh_print(); this->plater_->refresh_print();
#ifdef _WIN32 #ifdef _WIN32
#if ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
// file association is not possible anymore starting with Win 8
if (wxPlatformInfo::Get().GetOSMajorVersion() < 8) {
#endif // ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
if (is_editor()) { if (is_editor()) {
if (app_config->get("associate_3mf") == "1") if (app_config->get("associate_3mf") == "1")
associate_3mf_files(); associate_3mf_files();
@ -2428,6 +2446,9 @@ void GUI_App::open_preferences(const std::string& highlight_option /*= std::stri
if (app_config->get("associate_gcode") == "1") if (app_config->get("associate_gcode") == "1")
associate_gcode_files(); associate_gcode_files();
} }
#if ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
}
#endif // ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
#endif // _WIN32 #endif // _WIN32
if (mainframe->preferences_dialog->settings_layout_changed()) { if (mainframe->preferences_dialog->settings_layout_changed()) {

View File

@ -147,7 +147,7 @@ void GLGizmoSimplify::add_simplify_suggestion_notification(
for (size_t object_id : big_ids) { for (size_t object_id : big_ids) {
std::string t = GUI::format(_L( std::string t = GUI::format(_L(
"Processing model '%1%' with more than 1M triangles " "Processing model '%1%' with more than 1M triangles "
"could be slow. It is highly recommend to reduce " "could be slow. It is highly recommended to reduce "
"amount of triangles."), objects[object_id]->name); "amount of triangles."), objects[object_id]->name);
std::string hypertext = _u8L("Simplify model"); std::string hypertext = _u8L("Simplify model");

View File

@ -230,6 +230,10 @@ void PreferencesDialog::build()
app_config->get("export_sources_full_pathnames") == "1"); app_config->get("export_sources_full_pathnames") == "1");
#ifdef _WIN32 #ifdef _WIN32
#if ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
// file association is not possible anymore starting with Win 8
if (wxPlatformInfo::Get().GetOSMajorVersion() < 8) {
#endif // ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
// Please keep in sync with ConfigWizard // Please keep in sync with ConfigWizard
append_bool_option(m_optgroup_general, "associate_3mf", append_bool_option(m_optgroup_general, "associate_3mf",
L("Associate .3mf files to PrusaSlicer"), L("Associate .3mf files to PrusaSlicer"),
@ -240,6 +244,9 @@ void PreferencesDialog::build()
L("Associate .stl files to PrusaSlicer"), L("Associate .stl files to PrusaSlicer"),
L("If enabled, sets PrusaSlicer as default application to open .stl files."), L("If enabled, sets PrusaSlicer as default application to open .stl files."),
app_config->get("associate_stl") == "1"); app_config->get("associate_stl") == "1");
#if ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
}
#endif // ENABLE_REMOVE_ASSOCIATION_TO_FILE_FOR_WINDOWS_8_AND_LATER
#endif // _WIN32 #endif // _WIN32
m_optgroup_general->append_separator(); m_optgroup_general->append_separator();

View File

@ -141,7 +141,7 @@ static bool check_internet_connection_win()
{ {
bool internet = true; // return true if COM object creation fails. bool internet = true; // return true if COM object creation fails.
if (CoInitializeEx(NULL, COINIT_APARTMENTTHREADED) == S_OK) { if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) {
{ {
CComPtr<INetworkListManager> pNLM; CComPtr<INetworkListManager> pNLM;
if (pNLM.CoCreateInstance(CLSID_NetworkListManager) == S_OK) { if (pNLM.CoCreateInstance(CLSID_NetworkListManager) == S_OK) {

View File

@ -181,7 +181,7 @@ Http::priv::~priv()
bool Http::priv::ca_file_supported(::CURL *curl) bool Http::priv::ca_file_supported(::CURL *curl)
{ {
#ifdef _WIN32 #if defined(_WIN32) || defined(__APPLE__)
bool res = false; bool res = false;
#else #else
bool res = true; bool res = true;
@ -194,6 +194,7 @@ bool Http::priv::ca_file_supported(::CURL *curl)
if (::curl_easy_getinfo(curl, CURLINFO_TLS_SSL_PTR, &tls) == CURLE_OK) { if (::curl_easy_getinfo(curl, CURLINFO_TLS_SSL_PTR, &tls) == CURLE_OK) {
if (tls->backend == CURLSSLBACKEND_SCHANNEL || tls->backend == CURLSSLBACKEND_DARWINSSL) { if (tls->backend == CURLSSLBACKEND_SCHANNEL || tls->backend == CURLSSLBACKEND_DARWINSSL) {
// With Windows and OS X native SSL support, cert files cannot be set // With Windows and OS X native SSL support, cert files cannot be set
// DK: OSX is now not building CURL and links system one, thus we do not know which backend is installed. Still, false will be returned since the ifdef at the begining if this function.
res = false; res = false;
} }
} }

View File

@ -54,18 +54,9 @@ TEST_CASE("astar algorithm test over 3D point grid", "[AStar]") {
auto pgrid = point_grid(ex_seq, vol, {0.1f, 0.1f, 0.1f}); auto pgrid = point_grid(ex_seq, vol, {0.1f, 0.1f, 0.1f});
size_t target = pgrid.point_count() - 1;
std::cout << "Tracing route to " << pgrid.get_coord(target).transpose() << std::endl;
PointGridTracer pgt{pgrid, pgrid.point_count() - 1}; PointGridTracer pgt{pgrid, pgrid.point_count() - 1};
std::vector<size_t> out; std::vector<size_t> out;
bool found = astar::search_route(pgt, size_t(0), std::back_inserter(out)); bool found = astar::search_route(pgt, size_t(0), std::back_inserter(out));
std::cout << "Route taken: ";
for (size_t i : out) {
std::cout << "(" << pgrid.get_coord(i).transpose() << ") ";
}
std::cout << std::endl;
REQUIRE(found); REQUIRE(found);
} }

View File

@ -325,9 +325,9 @@ static void recreate_object_from_rasters(const std::string &objname, float lh) {
double disp_w = 120.96; double disp_w = 120.96;
double disp_h = 68.04; double disp_h = 68.04;
#ifndef NDEBUG //#ifndef NDEBUG
size_t cntr = 0; // size_t cntr = 0;
#endif //#endif
for (ExPolygons &layer : layers) { for (ExPolygons &layer : layers) {
auto rst = create_raster(res, disp_w, disp_h); auto rst = create_raster(res, disp_w, disp_h);
@ -335,11 +335,11 @@ static void recreate_object_from_rasters(const std::string &objname, float lh) {
rst.draw(island); rst.draw(island);
} }
#ifndef NDEBUG //#ifndef NDEBUG
std::fstream out(objname + std::to_string(cntr) + ".png", std::ios::out); // std::fstream out(objname + std::to_string(cntr) + ".png", std::ios::out);
out << rst.encode(sla::PNGRasterEncoder{}); // out << rst.encode(sla::PNGRasterEncoder{});
out.close(); // out.close();
#endif //#endif
ExPolygons layer_ = sla::raster_to_polygons(rst); ExPolygons layer_ = sla::raster_to_polygons(rst);
// float delta = scaled(std::min(rst.pixel_dimensions().h_mm, // float delta = scaled(std::min(rst.pixel_dimensions().h_mm,
@ -347,19 +347,19 @@ static void recreate_object_from_rasters(const std::string &objname, float lh) {
// layer_ = expolygons_simplify(layer_, delta); // layer_ = expolygons_simplify(layer_, delta);
#ifndef NDEBUG //#ifndef NDEBUG
SVG svg(objname + std::to_string(cntr) + ".svg", BoundingBox(Point{0, 0}, Point{scaled(disp_w), scaled(disp_h)})); // SVG svg(objname + std::to_string(cntr) + ".svg", BoundingBox(Point{0, 0}, Point{scaled(disp_w), scaled(disp_h)}));
svg.draw(layer_); // svg.draw(layer_);
svg.draw(layer, "green"); // svg.draw(layer, "green");
svg.Close(); // svg.Close();
#endif //#endif
double layera = 0., layera_ = 0.; double layera = 0., layera_ = 0.;
for (auto &p : layer) layera += p.area(); for (auto &p : layer) layera += p.area();
for (auto &p : layer_) layera_ += p.area(); for (auto &p : layer_) layera_ += p.area();
#ifndef NDEBUG //#ifndef NDEBUG
std::cout << cntr++ << std::endl; // std::cout << cntr++ << std::endl;
#endif //#endif
double diff = std::abs(layera_ - layera); double diff = std::abs(layera_ - layera);
REQUIRE((diff <= 0.1 * layera || diff < scaled<double>(1.) * scaled<double>(1.))); REQUIRE((diff <= 0.1 * layera || diff < scaled<double>(1.) * scaled<double>(1.)));

View File

@ -346,25 +346,36 @@ TEST_CASE("Mutable priority queue - first pop", "[MutableSkipHeapPriorityQueue]"
size_t id; size_t id;
float val; float val;
}; };
size_t count = 50000; static constexpr const size_t count = 50000;
std::vector<size_t> idxs(count, {0}); std::vector<size_t> idxs(count, {0});
std::vector<bool> dels(count, false);
auto q = make_miniheap_mutable_priority_queue<MyValue, 16, true>( auto q = make_miniheap_mutable_priority_queue<MyValue, 16, true>(
[&](MyValue &v, size_t idx) { [&idxs](MyValue &v, size_t idx) { idxs[v.id] = idx; },
idxs[v.id] = idx;
},
[](MyValue &l, MyValue &r) { return l.val < r.val; }); [](MyValue &l, MyValue &r) { return l.val < r.val; });
q.reserve(count); using QueueType = decltype(q);
for (size_t id = 0; id < count; id++) { THEN("Skip queue has 0th element unused, 1st element is the top of the queue.") {
MyValue mv{ id, rand() / 100.f }; CHECK(QueueType::address::is_padding(0));
q.push(mv); CHECK(!QueueType::address::is_padding(1));
}
q.reserve(count);
for (size_t id = 0; id < count; ++ id)
q.push({ id, rand() / 100.f });
MyValue v = q.top(); // copy
THEN("Element at the top of the queue has a valid ID.") {
CHECK(v.id >= 0);
CHECK(v.id < count);
}
THEN("Element at the top of the queue has its position stored in idxs.") {
CHECK(idxs[v.id] == 1);
} }
MyValue it = q.top(); // copy
q.pop(); q.pop();
// is valid id (no initial value default value) THEN("Element removed from the queue has its position in idxs reset to invalid.") {
CHECK(it.id != 0); CHECK(idxs[v.id] == q.invalid_id());
// is first item in queue valid value }
CHECK(idxs[0] != std::numeric_limits<size_t>::max()); THEN("Element was removed from the queue, new top of the queue has its index set correctly.") {
CHECK(q.top().id >= 0);
CHECK(q.top().id < count);
CHECK(idxs[q.top().id] == 1);
}
} }
TEST_CASE("Mutable priority queue complex", "[MutableSkipHeapPriorityQueue]") TEST_CASE("Mutable priority queue complex", "[MutableSkipHeapPriorityQueue]")
@ -382,30 +393,31 @@ TEST_CASE("Mutable priority queue complex", "[MutableSkipHeapPriorityQueue]")
q.reserve(count); q.reserve(count);
auto rand_val = [&]()->float { return (rand() % 53) / 10.f; }; auto rand_val = [&]()->float { return (rand() % 53) / 10.f; };
size_t ord = 0; for (size_t id = 0; id < count; ++ id)
for (size_t id = 0; id < count; id++) { q.push({ id, rand_val() });
MyValue mv;
mv.id = ord++;
mv.val = rand_val();
q.push(mv);
}
auto check = [&]()->bool{ auto check = [&]()->bool{
for (size_t i = 0; i < idxs.size(); ++i) { for (size_t i = 0; i < idxs.size(); ++i) {
if (dels[i]) continue; if (dels[i]) {
if (idxs[i] != q.invalid_id())
return false; // ERROR
} else {
size_t qid = idxs[i]; size_t qid = idxs[i];
if (qid > 3*count) { if (qid >= q.heap_size()) {
return false; return false; // ERROR
} }
MyValue &mv = q[qid]; MyValue &mv = q[qid];
if (mv.id != i) { if (mv.id != i) {
return false; // ERROR return false; // ERROR
} }
} }
}
return true; return true;
}; };
CHECK(check()); // initial check CHECK(check()); // initial check
// Generate an element ID of an elmenet, which was not yet deleted, thus it is still valid.
auto get_valid_id = [&]()->int { auto get_valid_id = [&]()->int {
int id = 0; int id = 0;
do { do {
@ -413,23 +425,28 @@ TEST_CASE("Mutable priority queue complex", "[MutableSkipHeapPriorityQueue]")
} while (dels[id]); } while (dels[id]);
return id; return id;
}; };
// Remove first 100 elements from the queue of 5000 elements, cross-validate indices.
// Re-enter every 20th element back to the queue.
for (size_t i = 0; i < 100; i++) { for (size_t i = 0; i < 100; i++) {
MyValue it = q.top(); // copy MyValue v = q.top(); // copy
q.pop(); q.pop();
dels[it.id] = true; dels[v.id] = true;
CHECK(check()); CHECK(check());
if (i % 20 == 0) { if (i % 20 == 0) {
it.val = rand_val(); v.val = rand_val();
q.push(it); q.push(v);
dels[it.id] = false; dels[v.id] = false;
CHECK(check()); CHECK(check());
continue; continue;
} }
// Remove some valid element from the queue.
int id = get_valid_id(); int id = get_valid_id();
CHECK(idxs[id] != q.invalid_id());
q.remove(idxs[id]); q.remove(idxs[id]);
dels[id] = true; dels[id] = true;
CHECK(check()); CHECK(check());
// and change 5 random elements and reorder them in the queue.
for (size_t j = 0; j < 5; j++) { for (size_t j = 0; j < 5; j++) {
int id = get_valid_id(); int id = get_valid_id();
size_t qid = idxs[id]; size_t qid = idxs[id];