mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-27 02:41:17 +00:00
The viewport and the kernel now answer "is this joint closed?" with one number
Tommaso asked the question that names the real defect: if the sketch was open, why was the same sketch shaded closed and offered for extrude? Because the two halves used different tolerances. region_loops shades a region closed at 1e-3 mm; connected_loop chained at 1e-3; the kernel welded at 1e-4 and OCCT matched vertices at 1e-7. The 2.28e-5 mm gap in the reported sketch did not cause that disagreement, it only made it visible — and fixing the gap alone would have left the contradiction in place, ready to reappear anywhere in (1e-4, 1e-3]. kSketchJoinTol now lives in SketchEngine.hpp and is the only place the number exists. region_loops, loop_report, connected_loop and entities_to_wires all read it through sketch_join_tol(). The viewport cannot promise a region the kernel refuses to build. The welding is optional, because a kernel that silently closes loops should let you say no: "Auto-close sketch loops" in Preferences, default ON, no restart. OFF means only exactly coincident endpoints join — and since both halves read the same value, the viewport simply stops shading the region closed, so an open loop is visible rather than welded behind your back. No separate UI needed for that; it falls out of sharing one number. Details that matter. The kernel defaults to auto-close ON independently of the GUI, so headless and MCP callers behave like the viewport instead of inheriting an unset preference. With the tolerance at 0 the comparisons become <=, because OFF must mean exact, not broken. OCCT never receives a zero vertex tolerance — it is clamped to Precision::Confusion. The preference is pushed from EVERY entry that starts a sketch session, not just begin(): a Constrain session enters through begin_constrain / begin_constrain_entities and uses region_loops and connected_loop, so a single push site would have left those sessions running on whatever the previous one set. begin_imported_transform is excluded deliberately — it works on imported regions, not chained entities. Tests: a loop with one joint open by 9e-4 mm, given out of traversal order, builds a closed four-edge wire; with auto-close off the same loop yields no wire; and an exactly closed loop still builds with auto-close off, proving OFF means exact. Kernel 66104 assertions / 606 cases green. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011FbJKJAJxxkhDTs9XdZzKA
This commit is contained in:
co-authored by
Claude Opus 5
parent
faf4406f89
commit
8b568b7b9d
@@ -62,8 +62,19 @@ static double ray_segment_dist3(const Vec3d& ro, const Vec3d& rd, const Vec3d& a
|
||||
return wxPoint(int(sx + 0.5), int(sy + 0.5));
|
||||
}
|
||||
|
||||
// The kernel's weld tolerance follows the app preference, and it must be pushed at EVERY
|
||||
// point that starts a sketch session: a Constrain session never passes through begin(), and
|
||||
// it uses region_loops()/connected_loop(), which read the same tolerance. Pushing in one
|
||||
// place only would leave those sessions on whatever the previous session set.
|
||||
static void push_auto_close_pref()
|
||||
{
|
||||
Slic3r::set_sketch_auto_close(wxGetApp().is_auto_close_sketch_loops());
|
||||
}
|
||||
|
||||
void DesignSketchTool::begin(const SketchPlane& plane, Mode mode)
|
||||
{
|
||||
push_auto_close_pref();
|
||||
|
||||
m_plane = plane;
|
||||
m_mode = mode;
|
||||
m_step_mode_last = -1; // a new session re-announces its step, even if it repeats the last
|
||||
@@ -2221,6 +2232,7 @@ void DesignSketchTool::finish()
|
||||
|
||||
void DesignSketchTool::begin_constrain(const SketchProfile& prof, const SketchPlane& plane)
|
||||
{
|
||||
push_auto_close_pref();
|
||||
m_plane = plane;
|
||||
m_mode = Mode::Constrain;
|
||||
m_points = prof.points;
|
||||
@@ -2235,6 +2247,7 @@ void DesignSketchTool::begin_constrain(const SketchProfile& prof, const SketchPl
|
||||
void DesignSketchTool::begin_constrain_entities(const std::vector<SketchEntity>& ents,
|
||||
const SketchPlane& plane)
|
||||
{
|
||||
push_auto_close_pref();
|
||||
m_plane = plane;
|
||||
m_mode = Mode::Constrain;
|
||||
m_constrain_entities = true;
|
||||
@@ -6333,7 +6346,7 @@ std::vector<DesignSketchTool::RegionLoop>
|
||||
DesignSketchTool::region_loops(const std::vector<SketchEntity>& ents) const
|
||||
{
|
||||
std::vector<RegionLoop> regions;
|
||||
const double eps2 = 1e-3 * 1e-3;
|
||||
const double eps2 = sketch_join_tol() * sketch_join_tol();
|
||||
auto is_near = [&](const Vec2d& a, const Vec2d& b) { return (a - b).squaredNorm() < eps2; };
|
||||
|
||||
// Circles are self-closed regions; lines/arcs are open segments to be chained. Each
|
||||
@@ -9420,7 +9433,7 @@ DesignSketchTool::LoopReport DesignSketchTool::loop_report() const
|
||||
ends.push_back({ e.p1 });
|
||||
}
|
||||
}
|
||||
const double eps = 1e-3;
|
||||
const double eps = sketch_join_tol();
|
||||
for (size_t i = 0; i < ends.size(); ++i) {
|
||||
int met = 0;
|
||||
for (size_t j = 0; j < ends.size(); ++j) {
|
||||
@@ -9553,7 +9566,7 @@ std::vector<int> DesignSketchTool::connected_loop(int seed) const
|
||||
{
|
||||
std::vector<int> out;
|
||||
if (seed < 0 || seed >= int(m_entities.size())) return out;
|
||||
const double eps2 = 1e-6;
|
||||
const double eps2 = sketch_join_tol() * sketch_join_tol();
|
||||
std::vector<bool> vis(m_entities.size(), false);
|
||||
std::vector<int> stack = { seed };
|
||||
vis[seed] = true;
|
||||
|
||||
Reference in New Issue
Block a user