pub struct NurbsSurface {
pub degree_u: usize,
pub degree_v: usize,
pub knots_u: Vec<f64>,
pub knots_v: Vec<f64>,
pub control_points: Vec<Vec<Vec4>>,
pub analytic: OnceCell<Option<AnalyticSurface>>,
pub projection_grid: OnceCell<SampleGrid>,
pub projection_dense_grid: OnceCell<SampleGrid>,
pub projection_ring_grid: OnceCell<Vec<Vec3>>,
pub projection_cells: OnceCell<Option<ProjectionCells>>,
/* private fields */
}Expand description
A rational B-spline surface.
Invariant: do not mutate the public fields after the surface has been
evaluated. The surface memoizes derived data (its analytic carrier, seam
closure, projection grids, validation) the first time it is asked, and
Clone copies those caches. Editing control_points, knots_* or a degree
in place afterwards leaves every later query answering for the OLD
geometry. Build a new value with NurbsSurface::new instead (lane K2
audit 2026-10-16: no production path does this today; a test fixture did).
Fields§
§degree_u: usize§degree_v: usize§knots_u: Vec<f64>§knots_v: Vec<f64>§control_points: Vec<Vec<Vec4>>§analytic: OnceCell<Option<AnalyticSurface>>Lazily recognized analytic carrier (plane/cylinder/cone/sphere/torus). Purely an acceleration cache: never serialized, cloned with the surface, and recomputed on demand after deserialization.
projection_grid: OnceCell<SampleGrid>Cached Newton seed grid for general point projection (see
projection.rs) — (u, v, point) samples over the knot spans.
projection_dense_grid: OnceCell<SampleGrid>Cached dense fallback grid for degenerate general projection
(projection.rs) — (u, v, point) samples at fixed per-surface
parameters, so the ~1.7M-call metre-mm fallback reuses the evals.
projection_ring_grid: OnceCell<Vec<Vec3>>Cached boundary-ring sample points for the degenerate projection
fallback (projection.rs), flattened as 4 sides × 22 exponents ×
33 indices of evaluated surface points at fixed per-surface params.
projection_cells: OnceCell<Option<ProjectionCells>>Cached convex-hull enclosure of every projection lattice cell
(projection.rs’s global stage), built on the first query the local
answer does not already settle. None when the net cannot be refined.
Implementations§
Source§impl NurbsSurface
impl NurbsSurface
Sourcepub fn extend_natural(
&self,
side: SurfaceSide,
delta_param: f64,
) -> Result<NurbsSurface, ExtendRefusal>
pub fn extend_natural( &self, side: SurfaceSide, delta_param: f64, ) -> Result<NurbsSurface, ExtendRefusal>
Continue this surface past one boundary of its parameter square by
delta_param, as the analytic continuation of its own terminal Bézier
span. See the module comment for the construction and for what survives
of the input (everything, over the original domain).
Source§impl NurbsSurface
impl NurbsSurface
Sourcepub fn insert_knot(
&self,
direction: KnotDirection,
parameter: f64,
count: usize,
) -> Result<NurbsSurface, KnotRefinementRefusal>
pub fn insert_knot( &self, direction: KnotDirection, parameter: f64, count: usize, ) -> Result<NurbsSurface, KnotRefinementRefusal>
Insert the knot parameter count times in direction. The result is
the same surface (point for point at every parameter) on a finer net:
count more rows (u) or columns (v). count == 0 returns a copy.
A parameter within KNOT_IDENTITY_TOL of an existing knot is that knot.
Sourcepub fn refine_knots(
&self,
direction: KnotDirection,
parameters: &[f64],
) -> Result<NurbsSurface, KnotRefinementRefusal>
pub fn refine_knots( &self, direction: KnotDirection, parameters: &[f64], ) -> Result<NurbsSurface, KnotRefinementRefusal>
Insert every parameter of parameters (any order, repeats allowed) in
direction. All are checked before anything is inserted: a refusal
leaves no partial result.
Source§impl NurbsSurface
impl NurbsSurface
Sourcepub fn elevate_degree(
&self,
direction: KnotDirection,
target: usize,
) -> Result<NurbsSurface, String>
pub fn elevate_degree( &self, direction: KnotDirection, target: usize, ) -> Result<NurbsSurface, String>
Raise the degree in direction to target exactly (Bezier
decomposition, binomial elevation per segment, surplus junction knots
removed: [crate::coons::compat::elevate_degree] on every column (u)
or row (v)). The same knot operations run on every line, so the lines
must come back on one knot vector; a line that does not is refused
rather than resampled. target <= degree returns a copy.
Source§impl NurbsSurface
impl NurbsSurface
Sourcepub fn content_key(&self) -> [u64; 2]
pub fn content_key(&self) -> [u64; 2]
The net’s content hash ([crate::identity_hash::hash_surface]),
computed once per value and carried by its clones.
pub fn new( degree_u: usize, degree_v: usize, knots_u: Vec<f64>, knots_v: Vec<f64>, control_points: Vec<Vec<Vec4>>, ) -> Result<NurbsSurface, String>
Sourcepub fn closed_directions(&self) -> Result<(bool, bool), String>
pub fn closed_directions(&self) -> Result<(bool, bool), String>
Whether the surface joins itself along u (first) and v (second):
opposite domain edges coincide at three sampled fractions. The 1e-6
threshold matches the historical LINEAR_TOLERANCE * 10 used by the
projection and curve×surface intersection modules.
pub fn domain_u(&self) -> Result<[f64; 2], String>
pub fn domain_v(&self) -> Result<[f64; 2], String>
Sourcepub fn linear_extrusion(&self) -> Option<&ExtrusionStructure>
pub fn linear_extrusion(&self) -> Option<&ExtrusionStructure>
Exact affine translation structure in this surface’s own chart.
Sourcepub fn analytic(&self) -> Option<&AnalyticSurface>
pub fn analytic(&self) -> Option<&AnalyticSurface>
The recognized analytic carrier, if this exact rational patch is a plane or a full revolution quadric/torus. Computed once per instance.
Sourcepub fn affine_sphere(&self) -> Option<&AffineSphere>
pub fn affine_sphere(&self) -> Option<&AffineSphere>
The recognized affine sphere (an ellipsoid), under BREP_AFFINE_SPHERE
and only when this net is not an analytic carrier; None otherwise.
Sourcepub fn warm_caches(&self) -> Vec<&'static str>
pub fn warm_caches(&self) -> Vec<&'static str>
The names of this surface’s caches that hold a value, in declaration
order. For the boolean’s operand-state instrument
(BREP_DEBUG_OPERAND_STATE), which reads which caches arrive warm.
Sourcepub fn exchange_caches(&mut self, names: &[&str], from: Option<&NurbsSurface>)
pub fn exchange_caches(&mut self, names: &[&str], from: Option<&NurbsSurface>)
Empties the named caches (warm_caches’ names; all for every one),
or, with from, sets each to from’s value. For the operand-state
instrument only: a cache that decides an answer is a defect, and this
is how the bisect finds it.
pub fn evaluate_homogeneous(&self, u: f64, v: f64) -> Result<Vec4, String>
pub fn evaluate(&self, u: f64, v: f64) -> Result<Vec3, String>
Sourcepub fn evaluate_extended(&self, u: f64, v: f64) -> Result<Vec3, String>
pub fn evaluate_extended(&self, u: f64, v: f64) -> Result<Vec3, String>
Value beyond the domain (Golovanov §3.15): closed directions wrap cyclically; open directions extend along the boundary tangent plane, with the bilinear corner form when both parameters are outside. Intersection and projection algorithms probe outside the domain, so this is a required capability of every surface.
Sourcepub fn derivatives_extended_small(
&self,
u: f64,
v: f64,
derivative_count: usize,
) -> Result<[[Vec3; 3]; 3], String>
pub fn derivatives_extended_small( &self, u: f64, v: f64, derivative_count: usize, ) -> Result<[[Vec3; 3]; 3], String>
Allocation-free twin of Self::derivatives_extended for
derivative_count <= 2 (lane O row 20): the same wrap, anchor and
bilinear extension, over Self::derivatives_small, which is the
byte-faithful stack copy of Self::derivatives. Entries outside
k + l <= derivative_count stay Vec3::default(), as the Vec form
leaves them.
Sourcepub fn derivatives_extended(
&self,
u: f64,
v: f64,
derivative_count: usize,
) -> Result<Vec<Vec<Vec3>>, String>
pub fn derivatives_extended( &self, u: f64, v: f64, derivative_count: usize, ) -> Result<Vec<Vec<Vec3>>, String>
Derivatives beyond the domain (§3.15). The extension is C¹: first derivatives follow the ruled/bilinear extension, second derivatives are taken at the boundary anchor (zero across an extended direction).
pub fn derivatives( &self, u: f64, v: f64, derivative_count: usize, ) -> Result<Vec<Vec<Vec3>>, String>
Sourcepub fn derivatives_small(
&self,
u: f64,
v: f64,
derivative_count: usize,
) -> Result<[[Vec3; 3]; 3], String>
pub fn derivatives_small( &self, u: f64, v: f64, derivative_count: usize, ) -> Result<[[Vec3; 3]; 3], String>
Allocation-free twin of Self::derivatives for the hot
derivative_count <= 2 path (point, first, and second partials).
This is a byte-for-byte faithful copy of the arithmetic in
Self::derivatives: identical basis evaluation, identical summation
order (control-point row i outer, column j inner, scale-then-add),
and the identical rational A(u,v)/w(u,v) de-homogenization recurrence.
Only the storage differs — fixed-size stack arrays ([Vec4; 9] for the
(count+1)² homogeneous grid, [[Vec3; 3]; 3] for the result) replace
the heap Vec<Vec4> / Vec<Vec<Vec3>>. Grid entries outside
k + l <= derivative_count (and outside k <= du, l <= dv) stay
Vec3::default(), exactly as the heap version leaves them, so callers may
index [k][l] for any k + l <= 2 and read the same value the Vec API
would have produced.
Sourcepub fn deriv1_tensor_supported(&self) -> bool
pub fn deriv1_tensor_supported(&self) -> bool
Whether Self::deriv1_tensor_each can drive this patch: the stack
basis tables only reach MAX_STACK_DEGREE, and a higher-degree patch
must be evaluated station by station through Self::deriv1.
Sourcepub fn deriv1_tensor_each<F>(
&self,
us: &[f64],
vs: &[f64],
f: F,
) -> Result<(), String>
pub fn deriv1_tensor_each<F>( &self, us: &[f64], vs: &[f64], f: F, ) -> Result<(), String>
(S, S_u, S_v) at every station of the TENSOR BLOCK us x vs, handed
to f as (u index, v index, S, S_u, S_v) with us outer and vs
inner.
Bit-identical to calling Self::deriv1 at each pair, and that is the
whole point of it: the block’s us.len() + vs.len() spans and basis
rows are evaluated ONCE each instead of once per station, which is
where a fixed tensor-Gauss cell spends most of its time (the basis
recurrence carries a division per knot per derivative order, and an
8x8 cell asks for the same 8 u rows and 8 v rows sixty-four times).
Nothing else changes: knot_clamp / knot_find_span /
basis_derivatives_into see the same arguments and so return the same
floats, the control-point sum runs in the same row-outer/column-inner
order from the same zero Vec4, and the rational de-homogenization is
Self::derivatives_small’s recurrence written out for
derivative_count == 1.
Two steps of that recurrence are elided because they are exact no-ops
at this order: binomial(1, 1) is exactly 1.0, and the mixed term it
scales is the zero vector, whose subtraction leaves every component
(including a negative zero) bit-unchanged.
Sourcepub fn deriv1(&self, u: f64, v: f64) -> Result<(Vec3, Vec3, Vec3), String>
pub fn deriv1(&self, u: f64, v: f64) -> Result<(Vec3, Vec3, Vec3), String>
Point and first partials (S, S_u, S_v) with zero heap allocation.
Bit-identical to derivatives(u, v, 1) at [0][0] / [1][0] / [0][1].
Sourcepub fn deriv1_extended_trim(
&self,
u: f64,
v: f64,
) -> Result<(Vec3, Vec3, Vec3), String>
pub fn deriv1_extended_trim( &self, u: f64, v: f64, ) -> Result<(Vec3, Vec3, Vec3), String>
First-order extension using only the anchor terms that it consumes.
Sourcepub fn deriv1_extended(
&self,
u: f64,
v: f64,
) -> Result<(Vec3, Vec3, Vec3), String>
pub fn deriv1_extended( &self, u: f64, v: f64, ) -> Result<(Vec3, Vec3, Vec3), String>
Allocation-free (S, S_u, S_v) twin of derivatives_extended(u, v, 1).
Mirrors the exact C¹ ruled/bilinear extension arithmetic of
Self::derivatives_extended (only the count == 1 partials), but drives
it from Self::derivatives_small so the in-domain and boundary-anchor
evaluations allocate nothing. Bit-identical to
derivatives_extended(u, v, 1) at [0][0] / [1][0] / [0][1].
Sourcepub fn partial_by_differences(
&self,
along_u: bool,
u: f64,
v: f64,
) -> Result<Vec3, String>
pub fn partial_by_differences( &self, along_u: bool, u: f64, v: f64, ) -> Result<Vec3, String>
One first partial at (u, v) (clamped into the domain), S_u when
along_u, else S_v, evaluated from the DIFFERENCES of the control net
rather than from the basis derivatives.
Self::derivatives forms S_u = (A_u − W_u·S) / W from A_u = Σ N′ᵢ·Hᵢ,
a sum of terms the size of the control points whose exact total may be
zero. Its rounding is therefore ABSOLUTE, a few ulps of the point, and
where the partial itself vanishes (an isoline on which the
parameterization is stationary, as on an extrusion of a cubic with
coincident end poles) the DIRECTION of what is left is that rounding:
measured 2.7e-15 of x on a partial of 7.7e-5 along y, a normal tilted
by 3.5e-11.
The hodograph A_u = Σ N_{i+1,p−1}·p·(H_{i+1} − H_i)/(ξ_{i+p+1} − ξ_{i+1})
(The NURBS Book eq. 3.4, per row) carries the same partial with rounding
that scales with its own terms: coincident control points difference to
an exact zero, and every other difference is weighted by a basis function
that vanishes with the partial. The rational part subtracts
W_u·S with W_u taken from the weight differences, which is an exact
zero wherever neighbouring weights are equal.
Not bit-identical to derivatives, so it is read only where the bare
partial has lost its direction (offset/point.rs). Refuses above the
stack basis tables’ degree.
pub fn normal(&self, u: f64, v: f64) -> Result<Vec3, String>
Sourcepub fn principal_curvatures(&self, u: f64, v: f64) -> Result<(f64, f64), String>
pub fn principal_curvatures(&self, u: f64, v: f64) -> Result<(f64, f64), String>
Principal curvatures (κ_min, κ_max) at (u, v), signed with respect to the parametrization normal n = Su × Sv / |Su × Sv| via the shape operator I⁻¹·II. Convention check: a cylinder of radius R whose normal points AWAY from the axis has κ = −1/R along the circular direction, so an offset’s regularity factor 1 − d·κ vanishes exactly when an inward offset (d = −R) reaches the axis.
Sourcepub fn principal_curvatures_and_tangents(
&self,
u: f64,
v: f64,
) -> Result<(f64, f64, Vec3, Vec3), String>
pub fn principal_curvatures_and_tangents( &self, u: f64, v: f64, ) -> Result<(f64, f64, Vec3, Vec3), String>
Self::principal_curvatures together with the first derivatives
Su and Sv it was read from, so a caller can judge how well
conditioned the reading is without evaluating the surface twice.
Sourcepub fn is_affine(&self) -> Result<bool, String>
pub fn is_affine(&self) -> Result<bool, String>
Whether this is a genuinely affine degree-1 by degree-1 patch.
A tapered bilinear patch is planar but not affine, so degree alone is insufficient for exact inverse-parameter and integration shortcuts.
pub fn iso_curve_u(&self, u: f64) -> Result<NurbsCurve, String>
pub fn iso_curve_v(&self, v: f64) -> Result<NurbsCurve, String>
Trait Implementations§
Source§impl Clone for NurbsSurface
impl Clone for NurbsSurface
Source§fn clone(&self) -> NurbsSurface
fn clone(&self) -> NurbsSurface
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more