refactor(snap): take an entity's snap points from its curve

Each entity built its own, and what they offered had drifted apart from
what the geometry actually has:

- An arc offered no quadrants at all. It now offers the ones its sweep
  covers, and no more.
- A spline offered its control points as endpoints. For a control-point
  spline those are not on the curve, so the cursor landed in empty space
  beside the geometry. It now offers its two real ends and its midpoint,
  with the fit points — which are on the curve — still on offer.
- An elliptical arc had no midpoint and no ends.

A new SnapHint::Endpoint carries an end that cannot go in key_vertices.
Consecutive entries there are taken to be joined by a straight segment
and their midpoint offered, which is right for a line or a polyline and
wrong for anything curved: an arc's two ends would also produce a snap
out on the chord. Splines lose their key_vertices for the same reason —
the chord between two fit points of a curvy spline does not run along
it.

A polyline's midpoints and arc-segment centres stay out of snap_pts
deliberately. The engine already derives a chain's midpoints from its
vertices, and a wire carrying a centre is treated as round elsewhere,
which a polyline with one bulge in it is not.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Hakan SevenandClaude Opus 5 committed 2026-08-09 00:43:44 +03:00
1 parent 57661c5754
commit b36e85e46e
6 files changed
+66 -51

No files matched your search

+36 -6
View File
@@ -87,12 +87,42 @@ fn to_truck(spl: &Spline) -> TruckEntity {
)
};
let snap_source = if !spl.fit_points.is_empty() {
&spl.fit_points
} else {
&spl.control_points
// Snap sources from the spline's own curve. A spline is not a chain of
// straight segments, so nothing goes in `key_vertices`: consecutive
// entries there are joined and their midpoints offered, and the chord
// between two fit points of a curvy spline does not run along it.
//
// Fit points are on the curve and stay on offer, as ends in their own
// right. Control points are not on the curve and are dropped — snapping
// to one put the cursor in empty space beside the geometry.
let curve_snap = crate::entities::curve::spline_curve(spl)
.map(|curve| crate::entities::curve::snap_from(&curve));
let (snap_pts, key_vertices) = match curve_snap {
Some(snap) => {
let mut points = snap.snap_pts;
points.extend(spl.fit_points.iter().map(|p| {
(
glam::DVec3::new(p.x, p.y, p.z),
crate::scene::model::wire_model::SnapHint::Endpoint,
)
}));
(points, Vec::new())
}
// A spline through points in space is not a planar curve, so the
// kernel has nothing to say about it. Its stored points remain the
// only thing to offer.
None => {
let source = if spl.fit_points.is_empty() {
&spl.control_points
} else {
&spl.fit_points
};
(
Vec::new(),
source.iter().map(|p| [p.x, p.y, p.z]).collect::<Vec<_>>(),
)
}
};
let key_vertices: Vec<[f64; 3]> = snap_source.iter().map(|p| [p.x, p.y, p.z]).collect();
let is_closed = spl.flags.closed || spl.flags.periodic;
let gap = {
@@ -120,7 +150,7 @@ fn to_truck(spl: &Spline) -> TruckEntity {
TruckEntity {
pick_tris: Vec::new(),
object,
snap_pts: vec![],
snap_pts,
tangent_geoms: vec![],
key_vertices,
fill_tris: vec![],