* feat(geom): surfaces through curve networks, and spline spaces to build them Adds spline_space (clamped B-spline spaces, Hermite interpolation, exact embedding by Bézier degree elevation and knot insertion, a monotone cubic for reparameterising) and network (loft, Coons and Gordon surfaces through curves in one or two directions, with G1/G2 cross-boundary conditions against a neighbouring face). Part of #763. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat(kernel): boundary surfaces from sketch curves, 3D curves and edges kernel::boundary_network turns sketch chains, 3D sketch polylines and edge chains into network curves, gives G1 frames of the faces along open edges (EdgeFaces), builds the B-spline face (sides split at chain vertices so a join shares the body's edges) and joins it into a surface body by stitching. G2 is refused for now (not supported yet). Part of #763. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix(kernel): second derivatives of B-spline surfaces in the vendored truck-geometry BSplineSurface::uuder and vvder multiplied the second differences by p instead of p·(p − 1), as BSplineCurve::der2 does, so every surface of degree p ≥ 3 (NURBS too, through its homogeneous surface) reported 1/(p − 1) of its second derivative: a cubic surface's curvature read as half. This is why a G2 boundary surface on a cylinder measured half the curvature it carries (#763). New tests hold both to finite differences for degrees 2 to 5. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LGeCa5jWWdroMWvXxN3LLM * feat(kernel): G2 boundary surfaces against a body's face The network always carried the face's curvature across a G2 edge; the refusal came from measuring it with truck's halved surface second derivatives (fixed in the previous commit). EdgeFaces now reads the face's second fundamental form from the exact second derivatives instead of differencing the normal. A new test holds the curvature across a cylinder's edge to the cylinder's within 0.1%, also with a sheared far curve; G3 is refused (a network holds up to G2). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LGeCa5jWWdroMWvXxN3LLM * test(kernel): a boundary patch with straight corners measures its own area A stadium's arcs meet its lines at 180°, so the Coons patch is singular at its corners. From such a corner the reference mesher's boundary walk ran onto the B-spline's extrapolation past its domain (a planar spline passes through every point of its plane there), and the face measured 289 mm² for its 158.5 (#763). The vendored mesher's bounded projection (nearest_projection, #2043) keeps the walk on the domain; this holds it there, by the faces, the measuring mesh and the display mesh. The display path (#1653) was never affected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LGeCa5jWWdroMWvXxN3LLM * feat(geom,kernel): three-sided boundary surfaces (one side collapsed to a point) A network curve may be a PointCurve: the apex where the two sides beside it meet. The curves through it cross it at the point itself, its row of the net collapses there, and the kernel's face leaves that side out of its loop (three edges, one vertex at the apex). One point per patch, as a side; refused elsewhere, when it moves, or with a continuity condition. Tests: a triangle and a quarter disc filled flat with their analytic areas (40 mm², 25π), by geom and by the kernel's faces and meshes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LGeCa5jWWdroMWvXxN3LLM * feat(doc): boundary surfaces through curve networks and loops of three or four FeatureKind::SurfaceNetwork saves a network as `u` and `v` curves, each a sketch chain (planar or 3D), a chain of a body's edges with an optional G1/G2 continuity, or a point (the apex of a three-sided patch), and an `operation` that can join the surface into the body of its edges. A SurfaceBoundary of three or four sketch curves, refused until now, builds as the flat Coons patch of its loop (three collapse the side opposite the first curve). The format change is one pending file; feature-walk goldens record the new variant's sketches, bodies and points. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LGeCa5jWWdroMWvXxN3LLM * feat(engine): surface.boundary through loops of three or four and curve networks The command keeps its loop form (two to four curves of one sketch; three and four now build the flat patch of the loop, crown refused there) and gains a network form: `u` and `v`, each curve a sketch curve id, a {sketch?, curves} chain (planar or 3D), a {body, edges, continuity?} edge chain (g1/g2 with the face beside it) or a {point} for a three-sided patch, with `operation` new or join. Edits may move between the two forms (timeline.redefine accepts the command now that it has a dialog). Tests: analytic areas of loop patches and of a hyperbolic paraboloid bounded by four 3D lines (every mesh vertex on z = xy/10), a loft across two sketches, G1 and G2 measured across a cylinder's edge with inspect.continuity (angle < 0.1°; curvature jump 1e-16 with G2 against 0.027 with G1), 26 hostile networks refused without panicking, and u/v added to hostile_params_never_panic. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LGeCa5jWWdroMWvXxN3LLM * feat(ui): Boundary Surface dialog Curves and Cross curves take sketch curves and edges (picks that meet end to end in one sketch or body are one chain); Continuity and Operation (New Body or Join). Two to four sketch curves of one sketch with nothing across are the loop patch; anything else is a network. Edit Feature brings either back (per-side orders, crown and stations the dialog does not show are kept). Strings in en, ja and zh. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LGeCa5jWWdroMWvXxN3LLM * docs: ROADMAP M8 and the bridge patch's notes for boundary networks (#763) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LGeCa5jWWdroMWvXxN3LLM * test(oracle): a boundary surface through a loop, thickened (#763) Case 83: four sketch curves (a square's three sides and a half circle for its top) make one boundary surface, thickened 2 mm; analytic values from tools/oracle-analytic/cases_surfaces.py (V = 2A, area 2A + 2P, centroid by moments). Recipes gain boundary_surface, thicken and remove. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LGeCa5jWWdroMWvXxN3LLM * refactor: boundary surfaces, review cleanups Project onto the face once per derivative evaluation (the frame is passed to natural() and reused by scale()), keep each track's finite-difference step instead of rescanning its table, export the kernel's edge-pick and chain caps and the default station count for the engine, doc and dialog to share, map TooLarge spline errors to KernelError::TooLarge, reuse the engine's operation parser, and skip the dialog's sketch lookup when the picks are no loop. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01LGeCa5jWWdroMWvXxN3LLM --------- Co-authored-by: jyviko <2501648+jyviko@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: bherbruck <brennen.herbruck@gmail.com>
127 lines
6.1 KiB
Rust
127 lines
6.1 KiB
Rust
//! Boundary patches: one face through the boundary curves of a sketch, each side meeting the
|
|
//! surface it was taken from at a requested continuity (G0 up to G3).
|
|
//!
|
|
//! Two boundaries are the two sides of a [`crate::bridge`]: the patch is the Hermite surface that
|
|
//! leaves each boundary along the direction its frames state and repeats as much of that support
|
|
//! surface — its tangent plane, its curvature, the change of that curvature — as the side's order
|
|
//! asks for, with `crown` shaping the middle without touching a boundary condition.
|
|
//!
|
|
//! A patch through *three or four* boundaries is refused here rather than built approximately. At
|
|
//! a corner two sides prescribe the same entries of the control net from two different surfaces,
|
|
//! and a tensor-product patch can hold both only where those two prescriptions already agree (one
|
|
//! wall carrying every side, say). Where they do not — the general case — the requested order would
|
|
//! silently drop near the corner, or the boundary curve would visibly leave its stations, and a
|
|
//! Gregory-type corner (a rational blend of the sides' own data) is needed to hold them instead
|
|
//! (issue #763). A loop of one sketch's curves is the case where they agree: it lies in the
|
|
//! sketch's plane, and its flat Coons patch ([`crate::boundary_network`]) holds every order
|
|
//! exactly; the network there refuses G1/G2 on two sides that meet at a corner for the same
|
|
//! reason. Everything this module refuses is an error, never a quietly worse surface.
|
|
|
|
use solidcraft_geom::Vec3;
|
|
|
|
use crate::body::Body;
|
|
use crate::bridge::{Continuity, Frame, bridge};
|
|
use crate::{KernelError, Result};
|
|
|
|
/// The most stations a boundary of a patch may carry.
|
|
const MAX_SAMPLES: usize = 512;
|
|
|
|
/// One boundary of a patch: the stations along it, and how much of the surface it was taken from
|
|
/// the patch repeats there.
|
|
#[derive(Clone, Debug)]
|
|
pub struct Boundary {
|
|
/// The stations along the boundary, in the order they run: the end of one boundary meets the
|
|
/// start of the next, and the last meets the first.
|
|
pub frames: Vec<Frame>,
|
|
/// How much of the neighbouring surface the patch repeats at this boundary.
|
|
pub order: Continuity,
|
|
}
|
|
|
|
/// A two-sided patch: one face that meets boundary `i` at the continuity its `order` asks for (G0 up
|
|
/// to G3), with `samples` stations every boundary must carry and `crown` shaping the middle of the
|
|
/// patch without touching any boundary condition (0 the plain blend, up to 3 fuller, down to -0.9
|
|
/// flatter). Three or four boundaries are refused: see the module docs.
|
|
pub fn boundary_patch(boundaries: &[Boundary], crown: f64, samples: usize) -> Result<Body> {
|
|
check_input(boundaries, crown, samples)?;
|
|
if boundaries.len() > 2 {
|
|
return Err(KernelError::Invalid(format!(
|
|
"not supported yet: a patch through {} boundaries — a three- or four-sided patch needs a Gregory-type corner (issue #763); \
|
|
give two boundaries, which is the bridge this builds exactly",
|
|
boundaries.len()
|
|
)));
|
|
}
|
|
let (Some(a), Some(b)) = (boundaries.first(), boundaries.get(1)) else {
|
|
return Err(KernelError::Invalid("a boundary patch joins 2 boundaries: one of them is missing".into()));
|
|
};
|
|
bridge(&a.frames, &b.frames, [a.order, b.order], [crown, crown])
|
|
}
|
|
|
|
/// Everything a patch refuses, before any geometry is built.
|
|
fn check_input(boundaries: &[Boundary], crown: f64, samples: usize) -> Result<()> {
|
|
let n = boundaries.len();
|
|
if !(2..=4).contains(&n) {
|
|
return Err(KernelError::Invalid(format!("a boundary patch joins 2 to 4 boundaries, {n} given")));
|
|
}
|
|
if !(2..=MAX_SAMPLES).contains(&samples) {
|
|
return Err(KernelError::Invalid(format!("a boundary patch needs 2 to {MAX_SAMPLES} stations per boundary, {samples} given")));
|
|
}
|
|
if !crown.is_finite() || !(-0.9..=3.0).contains(&crown) {
|
|
return Err(KernelError::Invalid("a boundary patch's crown must be between -0.9 and 3".into()));
|
|
}
|
|
for (i, b) in boundaries.iter().enumerate() {
|
|
if b.frames.len() != samples {
|
|
return Err(KernelError::Invalid(format!(
|
|
"boundary {i} carries {} stations, not the {samples} every boundary of a patch needs",
|
|
b.frames.len()
|
|
)));
|
|
}
|
|
for f in &b.frames {
|
|
if ![f.p, f.leave, f.bend, f.bend_change].into_iter().all(Vec3::is_finite) {
|
|
return Err(KernelError::Invalid(format!("boundary {i} has a station that is not finite")));
|
|
}
|
|
if f.leave.normalized().is_none() {
|
|
return Err(KernelError::Invalid(format!("boundary {i} has a station with no leave direction")));
|
|
}
|
|
}
|
|
if boundary_length(&b.frames) <= 1e-9 {
|
|
return Err(KernelError::Invalid(format!("boundary {i} has no length: a patch needs a curve, not a single point")));
|
|
}
|
|
}
|
|
// Two boundaries are the two sides of a bridge, which do not meet; three or four would run round
|
|
// a loop, so each one would have to end where the next one begins.
|
|
if n >= 3 {
|
|
let mut scale: f64 = 1.0;
|
|
for b in boundaries {
|
|
scale = scale.max(boundary_length(&b.frames));
|
|
}
|
|
let tol = scale * 1e-4 + 1e-9;
|
|
for i in 0..n {
|
|
let (Some(a), Some(b)) = (boundaries.get(i), boundaries.get((i + 1) % n)) else { continue };
|
|
let (Some(end), Some(start)) = (a.frames.last(), b.frames.first()) else { continue };
|
|
let gap = end.p.dist(start.p);
|
|
if gap > tol {
|
|
return Err(KernelError::Invalid(format!(
|
|
"boundary {i} ends and boundary {} starts {gap:.6} mm apart: the boundaries of a loop must run on into one another",
|
|
(i + 1) % n
|
|
)));
|
|
}
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|
|
|
|
/// The length of a run of stations.
|
|
fn boundary_length(frames: &[Frame]) -> f64 {
|
|
let mut length: f64 = 0.0;
|
|
for w in frames.windows(2) {
|
|
if let (Some(a), Some(b)) = (w.first(), w.get(1)) {
|
|
length += a.p.dist(b.p);
|
|
}
|
|
}
|
|
length
|
|
}
|
|
|
|
#[cfg(test)]
|
|
#[path = "boundary_tests.rs"]
|
|
mod tests;
|