Transfer Copy constructor of KDTreeIndirect into copy function

Reason: During Linux testing "fff_print_tests" it Fails from time to time.
ASAN version cause issue inside SeamPerimeters.hpp but I am not sure why.
This commit is contained in:
Filip Sykala - NTB T15p 2024-11-28 10:01:13 +01:00 committed by Lukas Matena
parent 7c2132bdc8
commit fc6b8a4b65
2 changed files with 11 additions and 3 deletions

View File

@ -38,10 +38,12 @@ public:
KDTreeIndirect(CoordinateFn coordinate, std::vector<size_t> indices) : coordinate(coordinate) { this->build(indices); }
KDTreeIndirect(CoordinateFn coordinate, size_t num_indices) : coordinate(coordinate) { this->build(num_indices); }
KDTreeIndirect(KDTreeIndirect &&rhs) : m_nodes(std::move(rhs.m_nodes)), coordinate(std::move(rhs.coordinate)) {}
KDTreeIndirect(const KDTreeIndirect &rhs) : m_nodes(rhs.m_nodes), coordinate(rhs.coordinate) {}
KDTreeIndirect& operator=(KDTreeIndirect &&rhs) { m_nodes = std::move(rhs.m_nodes); coordinate = std::move(rhs.coordinate); return *this; }
void clear() { m_nodes.clear(); }
const std::vector<size_t> &get_nodes() const { return m_nodes; }
// NOTE: Copy constructor cause failing FDM tests but not each run only from time to time.
// KDTreeIndirect(const KDTreeIndirect &rhs) : m_nodes(rhs.m_nodes), coordinate(rhs.coordinate) {}
KDTreeIndirect get_copy() const { KDTreeIndirect copy(coordinate); copy.m_nodes = m_nodes; return copy; }
void build(size_t num_indices)
{
std::vector<size_t> indices;

View File

@ -47,6 +47,12 @@ public:
explicit NearPoints(LayerSupportPoints* supports_ptr)
: m_points(supports_ptr), m_tree(m_points) {}
NearPoints get_copy(){
NearPoints copy(m_points.m_supports_ptr);
copy.m_tree = m_tree.get_copy(); // copy tree
return copy;
}
/// <summary>
/// Remove support points from KD-Tree which lay out of expolygons
/// </summary>
@ -199,7 +205,7 @@ NearPoints create_near_points(
NearPoints near_points = (prev_part_it->next_parts.size() == 1)?
std::move(prev_grids[index_of_prev_part]) :
// Need a copy there are multiple parts above previus one
prev_grids[index_of_prev_part]; // copy
prev_grids[index_of_prev_part].get_copy(); // copy
// merge other grid in case of multiple previous parts
for (size_t i = 1; i < part.prev_parts.size(); ++i) {
@ -208,7 +214,7 @@ NearPoints create_near_points(
if (prev_part_it->next_parts.size() == 1) {
near_points.merge(std::move(prev_grids[index_of_prev_part]));
} else { // Need a copy there are multiple parts above previus one
NearPoints grid_ = prev_grids[index_of_prev_part]; // copy
NearPoints grid_ = prev_grids[index_of_prev_part].get_copy(); // copy
near_points.merge(std::move(grid_));
}
}