fix: slice the same model to the same lightning infill every time (#15311)

This commit is contained in:
Kris Austin
2026-08-21 20:24:39 -05:00
committed by GitHub
parent 90f76fa28c
commit 4b397fc2cc
3 changed files with 45 additions and 6 deletions

View File

@@ -351,19 +351,23 @@ void Node::convertToPolylines(Polylines &output, const coord_t line_overlap) con
{
Polylines result;
result.emplace_back();
convertToPolylines(0, result);
// Orca: the layers are filled in parallel, so they would consume a shared generator in a
// different order every run, and a model would not slice the same way twice. Each tree seeds
// its own from where it is rooted; one constant seed would start them all on the same pick.
std::mt19937_64 rng { uint64_t(PointHash{}(m_p)) };
convertToPolylines(0, result, rng);
removeJunctionOverlap(result, line_overlap);
append(output, std::move(result));
}
void Node::convertToPolylines(size_t long_line_idx, Polylines &output) const
void Node::convertToPolylines(size_t long_line_idx, Polylines &output, std::mt19937_64 &rng) const
{
if (m_children.empty()) {
output[long_line_idx].points.push_back(m_p);
return;
}
size_t first_child_idx = rand() % m_children.size();
m_children[first_child_idx]->convertToPolylines(long_line_idx, output);
const size_t first_child_idx = rng() % m_children.size();
m_children[first_child_idx]->convertToPolylines(long_line_idx, output, rng);
output[long_line_idx].points.push_back(m_p);
for (size_t idx_offset = 1; idx_offset < m_children.size(); idx_offset++) {
@@ -371,7 +375,7 @@ void Node::convertToPolylines(size_t long_line_idx, Polylines &output) const
const Node& child = *m_children[child_idx];
output.emplace_back();
size_t child_line_idx = output.size() - 1;
child.convertToPolylines(child_line_idx, output);
child.convertToPolylines(child_line_idx, output, rng);
output[child_line_idx].points.emplace_back(m_p);
}
}

View File

@@ -7,6 +7,7 @@
#include <functional>
#include <memory>
#include <optional>
#include <random>
#include <vector>
#include "../../EdgeGrid.hpp"
@@ -259,8 +260,9 @@ protected:
*
* \param long_line a reference to a polyline in \p output which to continue building on in the recursion
* \param output all branches in this tree connected into polylines
* \param rng the generator the junctions draw from, carried through the recursion
*/
void convertToPolylines(size_t long_line_idx, Polylines &output) const;
void convertToPolylines(size_t long_line_idx, Polylines &output, std::mt19937_64 &rng) const;
void removeJunctionOverlap(Polylines &polylines, coord_t line_overlap) const;