Skip to main content

NurbsSurface

Struct NurbsSurface 

Source
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

Source

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

Source

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.

Source

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

Source

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

Source

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.

Source

pub fn new( degree_u: usize, degree_v: usize, knots_u: Vec<f64>, knots_v: Vec<f64>, control_points: Vec<Vec<Vec4>>, ) -> Result<Self, String>

Source

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.

Source

pub fn domain_u(&self) -> Result<[f64; 2], String>

Source

pub fn domain_v(&self) -> Result<[f64; 2], String>

Source

pub fn linear_extrusion(&self) -> Option<&ExtrusionStructure>

Exact affine translation structure in this surface’s own chart.

Source

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.

Source

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.

Source

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.

Source

pub fn exchange_caches(&mut self, names: &[&str], from: Option<&Self>)

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.

Source

pub fn evaluate_homogeneous(&self, u: f64, v: f64) -> Result<Vec4, String>

Source

pub fn evaluate(&self, u: f64, v: f64) -> Result<Vec3, String>

Source

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.

Source

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.

Source

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).

Source

pub fn derivatives( &self, u: f64, v: f64, derivative_count: usize, ) -> Result<Vec<Vec<Vec3>>, String>

Source

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.

Source

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.

Source

pub fn deriv1_tensor_each<F>( &self, us: &[f64], vs: &[f64], f: F, ) -> Result<(), String>
where F: FnMut(usize, usize, Vec3, Vec3, Vec3) -> 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.

Source

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].

Source

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.

Source

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].

Source

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.

Source

pub fn normal(&self, u: f64, v: f64) -> Result<Vec3, String>

Source

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.

Source

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.

Source

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.

Source

pub fn iso_curve_u(&self, u: f64) -> Result<NurbsCurve, String>

Source

pub fn iso_curve_v(&self, v: f64) -> Result<NurbsCurve, String>

Trait Implementations§

Source§

impl Clone for NurbsSurface

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for NurbsSurface

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for NurbsSurface

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for NurbsSurface

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more