forked from 1b-agent/opencadstudio-upstream
refactor(curve): draw a fit spline and an offset preview from the curve
Two places were left describing geometry for themselves. A fit-point SPLINE was drawn from a C² cubic solved in spline.rs while TRIM and snap cut a separate interpolation from the kernel. Near enough to look right, far enough apart that a trim landed beside the line it was aimed at. It now draws the curve those commands work on, and falls back to the local solve only where the kernel declines — a fit spline through points in space is not a planar curve, so there is nothing for it to say. Closed fit splines were worse than that: the kernel's interpolation is a clamped solve with no wrap in it, so the curve TRIM used never returned to its start and the seam cut nothing. Repeating the first fit point closes it. The seam is C¹ where the rest of the curve is C², which is the honest limit of a clamped solve — the alternative was a curve with a gap in it. OFFSET's preview sampling had drifted the same way TRIM's had: an arc and a circle read `center.x/.y` as world coordinates when the entity stores them in its OCS, so an extruded one previewed on the wrong side; every curved kind was cut at a fixed twenty segments per radian whatever its size; and an ellipse rebuilt its axis frame from the major axis' X and Y alone, dropping the Z the entity stores. A hundred lines of that become one tessellation. A RAY now previews as far as an XLINE does rather than as a stub the length of its direction vector. Co-Authored-By: Claude Opus 5 <[email protected]>
This commit is contained in:
1 parent
90abfc21a9
commit
ece440bcab
4 files changed
+122
-184
No files matched your search
@@ -685,6 +685,31 @@ mod tests {
|
||||
assert_eq!(hints(&snap, SnapHint::Quadrant).len(), 4);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_closed_fit_point_spline_comes_back_closed() {
|
||||
// The interpolation behind a fit-point spline is a clamped solve and
|
||||
// does not model a wrap, so without closing the point list the curve
|
||||
// ended somewhere else entirely — and a TRIM against it cut nothing
|
||||
// along the seam.
|
||||
let mut spline = SplineEnt::default();
|
||||
spline.degree = 3;
|
||||
spline.flags.closed = true;
|
||||
spline.fit_points = vec![
|
||||
v3(0.0, 0.0, 0.0),
|
||||
v3(10.0, 0.0, 0.0),
|
||||
v3(10.0, 10.0, 0.0),
|
||||
v3(0.0, 10.0, 0.0),
|
||||
];
|
||||
spline.normal = v3(0.0, 0.0, 1.0);
|
||||
let curve = entity_curve(&EntityType::Spline(spline)).unwrap();
|
||||
let (start, end) = (curve.point_at(0.0), curve.point_at(1.0));
|
||||
assert!(
|
||||
(start[0] - end[0]).abs() < 1e-9 && (start[1] - end[1]).abs() < 1e-9,
|
||||
"{start:?} vs {end:?}"
|
||||
);
|
||||
assert!(curve.is_closed());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn entities_that_are_not_curves_say_so() {
|
||||
assert!(entity_curve(&EntityType::Point(Default::default())).is_none());
|
||||
|
||||
+37
-12
@@ -19,23 +19,48 @@ fn to_truck(spl: &Spline) -> TruckEntity {
|
||||
// smooth Catmull-Rom curve through them and hand it back as a dense
|
||||
// polyline so it still draws.
|
||||
if spl.fit_points.len() >= 2 {
|
||||
let closed = spl.flags.closed || spl.flags.periodic;
|
||||
// A fit spline is a C² cubic through its fit points honouring the
|
||||
// stored end tangents. Catmull-Rom ignores those tangents (its ends
|
||||
// use local slopes), so an open curve peels away from the true shape
|
||||
// at the ends; interpolate properly instead. Closed splines wrap,
|
||||
// which the clamped solve doesn't model, so they keep Catmull-Rom.
|
||||
let pts = if closed {
|
||||
catmull_rom_polyline(&spl.fit_points, true)
|
||||
// Drawn from the same interpolation TRIM and snap use, so that
|
||||
// what is on screen is the curve those commands cut. The two had
|
||||
// parted: this drew a C² cubic solved here (or a Catmull-Rom for a
|
||||
// closed spline), while the kernel interpolated its own — near
|
||||
// enough to look right and far enough apart that a trim landed
|
||||
// beside the line it was aimed at.
|
||||
let planar = crate::entities::curve::spline_curve(spl);
|
||||
let pts = match &planar {
|
||||
Some(curve) => crate::entities::curve::curve_points(curve),
|
||||
// A fit spline through points in space is not a planar curve,
|
||||
// so the kernel has nothing to say about it and the solve
|
||||
// here remains the only description of its shape.
|
||||
None if spl.flags.closed || spl.flags.periodic => {
|
||||
catmull_rom_polyline(&spl.fit_points, true)
|
||||
}
|
||||
None => fit_spline_polyline(spl),
|
||||
};
|
||||
let snap = planar
|
||||
.as_ref()
|
||||
.map(crate::entities::curve::snap_from)
|
||||
.unwrap_or_default();
|
||||
// Fit points are on the curve, so they stay on offer as ends in
|
||||
// their own right — but never through `key_vertices`, whose
|
||||
// consecutive entries the snap engine joins and offers the middle
|
||||
// of. The chord between two fit points of a curvy spline does not
|
||||
// run along it.
|
||||
let mut snap_pts = snap.snap_pts;
|
||||
snap_pts.extend(spl.fit_points.iter().map(|p| {
|
||||
(
|
||||
glam::DVec3::new(p.x, p.y, p.z),
|
||||
crate::scene::model::wire_model::SnapHint::Endpoint,
|
||||
)
|
||||
}));
|
||||
let key_vertices = if planar.is_some() {
|
||||
Vec::new()
|
||||
} else {
|
||||
fit_spline_polyline(spl)
|
||||
spl.fit_points.iter().map(|p| [p.x, p.y, p.z]).collect()
|
||||
};
|
||||
let key_vertices: Vec<[f64; 3]> =
|
||||
spl.fit_points.iter().map(|p| [p.x, p.y, p.z]).collect();
|
||||
return TruckEntity {
|
||||
pick_tris: Vec::new(),
|
||||
object: TruckObject::Lines(pts),
|
||||
snap_pts: vec![],
|
||||
snap_pts,
|
||||
tangent_geoms: vec![],
|
||||
key_vertices,
|
||||
fill_tris: vec![],
|
||||
|
||||
Reference in new issue
Block a user