mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-26 10:21:00 +00:00
M3c: 2D bridging curve — cubic-Bezier G1 connector between sketch endpoints
Adds SketchEngine::make_bridge (4-pole cubic Bezier, G1-tangent to Line/Arc endpoints, straight-line fallback for other types) emitted as the existing BSpline SketchEntity — no new geometry type, no serialized-field change, golden recipe fixture untouched. CadDocument::add_bridge appends it (non-parametric, index-validated, throws on bad refs). MCP `bridge` method mirrors action_project. 4 new [CadDocument][bridge] tests; full kernel suite green (76 cases, 1280 asserts). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BVzKmX6Y1aEteit1HTXG4Q
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
62d39fba27
commit
65caa2ea6e
@@ -800,6 +800,21 @@ int CadDocument::add_project_edges(int source_body, const std::vector<int>& edge
|
||||
return int(features.size()) - 1;
|
||||
}
|
||||
|
||||
int CadDocument::add_bridge(int sketch_ref, int ent_a, int end_a, int ent_b, int end_b,
|
||||
const std::string& name)
|
||||
{
|
||||
(void)name;
|
||||
if (sketch_ref < 0 || sketch_ref >= int(features.size())
|
||||
|| features[sketch_ref].type != CadFeatureType::Sketch)
|
||||
throw std::runtime_error("bridge: sketch_ref must refer to a Sketch feature");
|
||||
auto& ents = features[sketch_ref].entities;
|
||||
if (ent_a < 0 || ent_a >= int(ents.size()) || ent_b < 0 || ent_b >= int(ents.size()))
|
||||
throw std::runtime_error("bridge: entity index out of range in sketch");
|
||||
SketchEntity br = SketchEngine::make_bridge(ents[ent_a], end_a, ents[ent_b], end_b);
|
||||
ents.push_back(br);
|
||||
return int(ents.size()) - 1;
|
||||
}
|
||||
|
||||
int CadDocument::add_plane(int base, double offset, double angle_tilt, int axis,
|
||||
const std::string& name)
|
||||
{
|
||||
|
||||
@@ -378,6 +378,12 @@ public:
|
||||
// entities are (re)derived on every recompute.
|
||||
int add_project_edges(int source_body, const std::vector<int>& edge_ids, int face,
|
||||
const SketchPlane& plane, const std::string& name);
|
||||
// Append a bridging BSpline entity connecting endpoint `end_a` of entity `ent_a` to
|
||||
// endpoint `end_b` of entity `ent_b`, both within sketch feature `sketch_ref`. Returns
|
||||
// the new entity's index within that sketch's entities vector. Non-parametric: computed
|
||||
// once from the current endpoints (does not auto-follow later solver moves).
|
||||
int add_bridge(int sketch_ref, int ent_a, int end_a, int ent_b, int end_b,
|
||||
const std::string& name);
|
||||
// Solve features[index]'s sketch constraints, writing solved coordinates back
|
||||
// into its profile.points. No-op (returns true) if the feature has no
|
||||
// constraints. Returns false if index is invalid / not a Sketch / solve fails.
|
||||
|
||||
@@ -1372,4 +1372,57 @@ bool SketchEngine::extend_entity(SketchEntity& e, const std::vector<SketchEntity
|
||||
return true;
|
||||
}
|
||||
|
||||
// Bridge: cubic Bézier with G1 continuity at both ends.
|
||||
// Poles = {Pa, Pa + Ta*d/3, Pb - Tb*d/3, Pb}, where d = |Pb - Pa|.
|
||||
SketchEntity SketchEngine::make_bridge(const SketchEntity& a, int a_end,
|
||||
const SketchEntity& b, int b_end)
|
||||
{
|
||||
auto endpoint = [](const SketchEntity& e, int end) -> Vec2d {
|
||||
return end == 0 ? e.p0 : e.p1;
|
||||
};
|
||||
|
||||
auto tangent = [](const SketchEntity& e, int end, const Vec2d& fallback_dir) -> Vec2d {
|
||||
switch (e.type) {
|
||||
case SketchEntity::Type::Line: {
|
||||
Vec2d dir = end == 1 ? e.p1 - e.p0 : e.p0 - e.p1;
|
||||
double len = dir.norm();
|
||||
if (len < 1e-12) return fallback_dir;
|
||||
return dir / len;
|
||||
}
|
||||
case SketchEntity::Type::Arc: {
|
||||
double theta = end == 1 ? e.end_angle : e.start_angle;
|
||||
// Tangent to the circle at angle theta, CCW: (-sin θ, cos θ).
|
||||
// At end=1 (end_angle), the outward direction is along the sweep direction.
|
||||
// At end=0 (start_angle), outward is opposite the sweep direction.
|
||||
double sweep = e.end_angle - e.start_angle;
|
||||
int sign = end == 1 ? (sweep >= 0 ? 1 : -1) : (sweep >= 0 ? -1 : 1);
|
||||
Vec2d t(-std::sin(theta), std::cos(theta));
|
||||
return t * double(sign);
|
||||
}
|
||||
default:
|
||||
// ponytail: straight-ish bridge for unsupported entity types.
|
||||
return fallback_dir;
|
||||
}
|
||||
};
|
||||
|
||||
const Vec2d Pa = endpoint(a, a_end);
|
||||
const Vec2d Pb = endpoint(b, b_end);
|
||||
const double d = (Pb - Pa).norm();
|
||||
|
||||
// Fallback tangent direction: point toward the other endpoint.
|
||||
Vec2d fallback = d < 1e-9 ? Vec2d(1, 0) : (Pb - Pa) / d;
|
||||
Vec2d Ta = tangent(a, a_end, fallback);
|
||||
Vec2d Tb = tangent(b, b_end, fallback * -1.0);
|
||||
|
||||
const double k = std::max(d, 1e-9) / 3.0;
|
||||
|
||||
SketchEntity e;
|
||||
e.type = SketchEntity::Type::BSpline;
|
||||
e.construction = false;
|
||||
e.ctrl = { Pa, Pa + Ta * k, Pb - Tb * k, Pb };
|
||||
e.p0 = e.ctrl.front();
|
||||
e.p1 = e.ctrl.back();
|
||||
return e;
|
||||
}
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
@@ -250,6 +250,12 @@ public:
|
||||
|
||||
static bool extend_entity(SketchEntity& e, const std::vector<SketchEntity>& others,
|
||||
const Vec2d& pick);
|
||||
|
||||
// Build a cubic-Bezier G1 bridge (as a BSpline entity, 4 poles) connecting endpoint
|
||||
// `a_end` of `a` to endpoint `b_end` of `b` (0 = start/p0 side, 1 = end/p1 side).
|
||||
// Tangent-continuous with both entities where the endpoint tangent is defined.
|
||||
static SketchEntity make_bridge(const SketchEntity& a, int a_end,
|
||||
const SketchEntity& b, int b_end);
|
||||
};
|
||||
|
||||
} // namespace Slic3r
|
||||
|
||||
Reference in New Issue
Block a user