tycho_nurbs

    Tycho NURBS — zero-dependency pure-MoonBit B-spline/NURBS kernel (math-only core, exact/approx split, batch evaluation)

    nurbs
    bspline
    cad
    curve
    surface
    tycho
    Download zip
    Version
    0.1.0
    License
    Apache-2.0
    Last updated
    yesterday
    Downloads
    13

    #Tycho NURBS (laplaceliu/tycho_nurbs)

    Zero-dependency, pure-MoonBit B-spline / NURBS kernel. Built on the unconstrained design (see roadmap/nurbs-design-comparison.md in the meta-repo), not the ADR-004 organization-constrained variant.

    #Architecture

    PrincipleWhat it means here
    D1 — math-only coreThis module depends only on tycho_math (root + f64). It outputs parametric data (points, derivatives). A separate, optional mesh adapter (tycho_nurbs_mesh, future) will convert tessellation to tycho_geometry::MeshData; the kernel never knows about meshes.
    D2 — generic B-spline + rational projectionEvery evaluation/derivative algorithm is written once against VecSpace[V] (vecspace.mbt) and instantiated for DVec2/3/4. A NURBS curve is the perspective projection of a homogeneous DVec4 B-spline; the rational division happens only at the projection boundary (curve.mbt).
    D3 — exact / approximate splitknot.mbt, bspline.mbt, curve.mbt, operations.mbt are the exact layer: polynomial/rational identities with no tolerance parameter. removal.mbt (knot removal) is the first approximate operation: tolerance-driven, tested by residuals. Future fit/intersect/closest join this layer.
    D4 — batch hot pathBSpline::evaluate_many / NurbsCurve3::evaluate_many walk sorted parameters with a monotonically advancing knot span, amortizing span search for tessellation and arc-length sweeps.

    #Current status — M0 + M1 + M2 + M3 complete

    Implemented and tested (90 tests, green on native / wasm / js):

    • KnotVector — validated non-decreasing knot vector; find_span (A2.1), basis_funs (A2.2), ders_basis_funs (A2.3), multiplicity.
    • BSpline[V] — generic affine kernel: evaluate, evaluate_many (batch), evaluate_derivatives.
    • NurbsCurve3 — homogeneous storage, from_points / from_points_weights, point_at, evaluate_many, rational derivatives (A4.2), point/weight views.
    • Exact knot/degree operations (operations.mbt): insert_knot (A5.1), split, decompose_bezier, degree_elevate (Eq 5.36 + knot removal).
    • Approximate knot removal (removal.mbt): remove_knot (A5.8), tolerance-driven.
    • Arc length (arclength.mbt): arc_length (self-contained Gauss–Legendre quadrature, span-by-span) and arc_length_parameter (monotone bisection inversion).
    • Global interpolation (interpolation.mbt): interpolate (A9.1) with uniform / chord-length / centripetal parameterization.
    • Degree reduction (reduction.mbt): degree_reduce (Eqs 5.41/5.42), approximate.
    • Internal linalg (linalg.mbt, private): dense DMat + LU (partial pivoting) and Householder QR least-squares — not a public general-purpose library.
    • NurbsSurface3 (surface.mbt): tensor-product homogeneous grid, point_at (A4.3) and analytic normal_at (A4.4 first partials).
    • Surface constructors (construct.mbt): extrude, loft, revolve (rational arcs), sweep (parallel-transport frames).
    • Least-squares fitting (fitting.mbt): NurbsCurve3::fit (Eq 9.63/9.67 via QR) and NurbsSurface3::fit (separable u/v curve fits).
    • Tessellation (tessellate.mbt): neutral Double-precision Tessellation output, uniform (tessellate) and crack-free curvature-adaptive (tessellate_adaptive) modes, CCW winding, analytic normals. The optional tycho_nurbs_mesh adapter converts it to MeshData.
    • BFGS minimizer (minimize.mbt, private): verb Minimizer.hx port (Armijo line search + inverse-Hessian update) with a numerical-gradient fallback.
    • Closest-point projection (closest.mbt): curve / surface closest_parameter / closest_point (coarse sampling + BFGS, analytic gradients).
    • Intersection (intersect.mbt): intersect_curves, intersect_curve_surface, intersect_surfaces via multi-start BFGS distance minimization + dedup.
    • Curve BVH (bvh.mbt): build_bvh (recursive split, control-point boxes) and CurveBvh::closest_point with box-distance pruning.
    • M3 — NurbsCurve2 (curve2.mbt): 2D curves as homogeneous DVec3(x*w,y*w,w), reusing the generic kernel; fitting2.mbt (2D QR fit), offset.mbt (sample + left-normal displacement + re-fit), trim.mbt (TrimmedCurve2 intervals/flatten).
    • M3 — fillet (fillet.mbt): fillet_corner tangent arc (exact rational NURBS).
    • M3 — boolean (boolean.mbt): point_in_polygon, clip_convex (Sutherland–Hodgman), boolean_polygons (Greiner–Hormann union/intersection/difference).
    • M3 — CDT (cdt.mbt): cdt constrained Delaunay triangulation (Bowyer–Watson
      • constraint-edge flip recovery).

    Verified invariants: basis partition of unity & non-negativity, span correctness, the exact rational quarter circle, batch == single-point equivalence, weight-scale invariance, tangent direction, out-of-domain rejection; insert/split/decompose/degree-elevate preserve the curve pointwise; insert→remove and elevate→reduce round-trips; Bézier segment structure; arc length closed forms (quarter circle = π/2, line = endpoint distance) and additivity; interpolation passes through every input point; surface closed forms (bilinear plane, rational cylinder patch x²+y²=1) and radial normals; tessellation grid counts, CCW winding consistent with the normal; constructors (extrude/revolve/sweep circle→cylinder, loft lines→plane); fitting (collinear→exact line, circle approximation residual, plane grid reproduction); adaptive tessellation (flat stays coarse, curved refines, tighter tol → more vertices); BFGS on quadratics; projection onto circle/cylinder; intersection (crossing lines, line piercing plane, two planes); BVH closest point matches direct projection and root bounds contain the curve; 2D quarter-circle evaluation, circular offset, trimmed-domain restriction; right-angle fillet tangent arc; polygon boolean union/intersection/difference areas; CDT area coverage, constraint recovery and interior points.

    #Not yet implemented (refinements)

    All planned milestones (M0–M3) are complete. Possible future refinements: surface-surface intersection curve tracing (marching), surface BVH, rational fitting/interpolation, trimmed-surface tessellation wiring CDT to the mesh adapter.

    #Examples

    • examples/nurbs/cad — headless end-to-end CAD validation of the kernel and mesh adapter (moon run --target native examples/nurbs/cad).
    • examples/nurbs/surfaces — a rendered NURBS CAD gallery (extrude / revolve / sweep / loft) with an interactive OrbitCamera (moon run --target native examples/nurbs/surfaces -- --window).

    #Performance & D2 validation

    The generic VecSpace[V] kernel (design D2) was benchmarked against a hand-written concrete DVec4 sweep (bench_wbtest.mbt, moon bench -p nurbs --target native--release). With scratch buffers reused, generic and concrete are equal (~138 µs for a 10k-point sweep): MoonBit monomorphizes the generics — trait dispatch is zero-cost, so the D2 architectural bet is validated.

    The benchmark also exposed that the batch evaluator's original per-point allocation in basis_funs (not generics) cost ~2.4x; BSpline::evaluate_many now reuses basis scratch buffers and is ~2.2x faster.

    #Layout

    nurbs/ ├── vecspace.mbt # VecSpace trait (+ norm) + DVec2/3/4 impls + vlerp/vcombine/vdistance (D2) ├── knot.mbt # EXACT: KnotVector, span, basis, derivative basis ├── bspline.mbt # EXACT: generic BSpline[V], evaluate / evaluate_many / derivatives ├── curve.mbt # EXACT: NurbsCurve3 rational projection ├── operations.mbt # EXACT: insert_knot / split / decompose_bezier / degree_elevate ├── removal.mbt # APPROX: remove_knot (A5.8, tolerance-driven) ├── arclength.mbt # EXACT: arc_length (Gauss–Legendre) / arc_length_parameter ├── interpolation.mbt # EXACT: global interpolation (A9.1, 3 parameterizations) ├── reduction.mbt # APPROX: degree_reduce (Eqs 5.41/5.42) ├── linalg.mbt # INTERNAL (private): DMat + LU + QR least-squares, not public API ├── surface.mbt # EXACT: NurbsSurface3 tensor product, point_at / normal_at ├── construct.mbt # EXACT: extrude / loft / revolve / sweep ├── fitting.mbt # APPROX: least-squares curve / surface fit (QR) ├── tessellate.mbt # EXACT: neutral Tessellation, uniform + adaptive (math-only) ├── minimize.mbt # INTERNAL (private): BFGS + numerical gradient (verb port) ├── closest.mbt # APPROX: curve / surface closest-point projection ├── intersect.mbt # APPROX: curve / curve-surface / surface-surface intersection ├── bvh.mbt # APPROX: curve BVH (split + control-point boxes) + pruning query ├── curve2.mbt # EXACT: NurbsCurve2 (homogeneous DVec3), reuses generic kernel ├── fitting2.mbt # APPROX: 2D least-squares fit (QR) ├── offset.mbt # APPROX: 2D curve offset (sample + normal + re-fit) ├── trim.mbt # EXACT: TrimmedCurve2 (intervals / contains / flatten) ├── fillet.mbt # EXACT: fillet_corner tangent arc (rational NURBS) ├── boolean.mbt # CG: point-in-polygon / convex clip / Greiner–Hormann boolean ├── cdt.mbt # CG: constrained Delaunay triangulation (Bowyer–Watson + flips) ├── *_wbtest.mbt # invariant + closed-form tests └── moon.mod # deps: tycho_math only

    #Build & test

    moon check -p nurbs moon test -p nurbs --target wasm # pure MoonBit, no C toolchain needed moon test -p nurbs --target js moon test -p nurbs --target native # needs a C99 cc (see ../setup-linux.sh / .toolchain)

    #License

    Apache-2.0. Algorithmic references (curvo / verb / geomdl) are MIT; see NOTICE.

    BSpline

    pub(all) struct BSpline[V] {
    degree : Int
    knots : KnotVector
    ctrlpts : FixedArray[V]
    }

    A B-spline in an arbitrary vector space V. For NURBS, V is a homogeneous vector (e.g. DVec4) and the wrapper projects by dividing through the weight.

    BSpline::decompose_bezier

    fn[V : VecSpace] BSpline::decompose_bezier(self : BSpline[V]) -> Array[BSpline[V]]

    Decompose into Bézier segments of the same degree (repeated splitting at the interior knots). Exact. A single Bézier curve yields one segment.

    BSpline::degree_elevate

    fn[V : VecSpace] BSpline::degree_elevate(self : BSpline[V]) -> BSpline[V]?

    Degree-elevate the whole B-spline by 1. Exact — the curve is unchanged. Decompose into Bézier segments, elevate each (Eq 5.36), link them into a degree-(p+1) B-spline with C^0 joins (multiplicity p+1), then remove knots (A5.8) at each join to restore the original continuity (multiplicity s+1).

    BSpline::degree_reduce

    fn[V : VecSpace] BSpline::degree_reduce(self : BSpline[V], tol? : Double) -> BSpline[V]?

    Degree-reduce the whole B-spline by 1 (approximate). Decompose into Bézier segments, reduce each, link into a degree-(p-1) B-spline, then remove knots to restore the original join multiplicities. None if degree < 2 or a join cannot be restored within tolerance.

    BSpline::evaluate

    fn[V : VecSpace] BSpline::evaluate(self : BSpline[V], u : Double) -> V?

    Evaluate the (affine) B-spline at u. Returns None outside the domain.

    BSpline::evaluate_derivatives

    fn[V : VecSpace] BSpline::evaluate_derivatives(self : BSpline[V], u : Double, d : Int) -> Array[V]?

    Homogeneous derivatives 0..d at u (row k is the k-th derivative). Returns None outside the domain or if d > degree. The projection wrapper applies the rational quotient rule to these homogeneous derivatives.

    BSpline::evaluate_many

    fn[V : VecSpace] BSpline::evaluate_many(self : BSpline[V], us : FixedArray[Double]) -> FixedArray[V]?

    Batch evaluation (design D4). us MUST be sorted ascending and within the domain; otherwise returns None. The span advances monotonically across the sweep, amortizing span search. Result order matches us.

    BSpline::insert_knot

    fn[V : VecSpace] BSpline::insert_knot(self : BSpline[V], u : Double, r? : Int) -> BSpline[V]?

    Algorithm A5.1: insert knot u r times (r >= 1). Exact — the curve is unchanged. Returns None if u is outside the domain, r < 1, or the resulting multiplicity would exceed the degree (s + r > degree).

    BSpline::new

    fn[V] BSpline::new(degree : Int, knots : KnotVector, ctrlpts : FixedArray[V]) -> BSpline[V]?

    Construct a B-spline, enforcing degree >= 1, at least degree+1 control points, and the knot-count relation len(knots) == degree + num_ctrlpts + 1.

    BSpline::num_ctrlpts

    fn[V] BSpline::num_ctrlpts(self : BSpline[V]) -> Int

    BSpline::remove_knot

    fn[V : VecSpace] BSpline::remove_knot(self : BSpline[V], u : Double, tol? : Double, r? : Int) -> BSpline[V]?

    Algorithm A5.8: remove knot u up to r times, each removal accepted only if the induced control-point change is within tol. Returns the (possibly partially) reduced B-spline, or None if u is absent / r exceeds multiplicity. The returned curve has knot u with multiplicity reduced by the number of successful removals.

    BSpline::split

    fn[V : VecSpace] BSpline::split(self : BSpline[V], u : Double) -> (BSpline[V], BSpline[V])?

    Split the curve at a strictly interior parameter u into two clamped B-splines whose domains are [start, u] and [u, end]. Exact. Returns None at the domain edges or outside the domain.

    BoolOp

    pub(all) enum BoolOp {
    Intersection
    Union
    Difference
    }

    BvhNode

    type BvhNode

    CurveBvh

    pub(all) struct CurveBvh {
    curve : NurbsCurve3
    nodes : Array[BvhNode]
    root : Int
    }

    A curve bounding-volume hierarchy (binary tree over parameter splits).

    CurveBvh::closest_point

    Accelerated closest point via BVH traversal with box-distance pruning.

    KnotVector

    pub(all) struct KnotVector {
    knots : FixedArray[Double]
    }

    A non-decreasing knot vector. Validated at construction; the consistency relation len == degree + num_ctrlpts + 1 is enforced by BSpline::new.

    KnotVector::basis_funs

    fn KnotVector::basis_funs(self : KnotVector, span : Int, degree : Int, u : Double) -> FixedArray[Double]

    Algorithm A2.2: the degree + 1 nonzero basis functions N_{span-degree..span} at parameter u. They are non-negative and sum to 1 (partition of unity).

    KnotVector::basis_one

    fn KnotVector::basis_one(self : KnotVector, degree : Int, n : Int, j : Int, u : Double) -> Double

    Evaluate a single basis function N_{j,degree}(u). n is the last control point index. Returns 0 outside the support or domain.

    KnotVector::ders_basis_funs

    fn KnotVector::ders_basis_funs(self : KnotVector, span : Int, degree : Int, u : Double, d : Int) -> FixedArray[FixedArray[Double]]

    Algorithm A2.3: derivatives of the nonzero basis functions up to order d (d <= degree). Returns a (d+1) x (degree+1) row-major table: ders[k][j] is the k-th derivative of N_{span-degree+j}. Row 0 equals basis_funs.

    KnotVector::domain_end

    fn KnotVector::domain_end(self : KnotVector, n : Int) -> Double

    Last parameter of the valid domain: U[num_ctrlpts]. n is the last control point index (num_ctrlpts - 1).

    KnotVector::domain_start

    fn KnotVector::domain_start(self : KnotVector, degree : Int) -> Double

    First parameter of the valid domain: U[degree].

    KnotVector::find_span

    fn KnotVector::find_span(self : KnotVector, degree : Int, n : Int, u : Double) -> Int

    Algorithm A2.1: find the knot span index i with U[i] <= u < U[i+1]. n is the last control point index. The right end u == U[n+1] maps to n. Assumes u is within the domain (callers validate).

    KnotVector::multiplicity

    fn KnotVector::multiplicity(self : KnotVector, u : Double) -> Int

    Exact multiplicity of the knot value u in the vector.

    KnotVector::new

    fn KnotVector::new(knots : FixedArray[Double]) -> KnotVector?

    Build a knot vector, rejecting empty or strictly-decreasing sequences.

    NurbsCurve2

    pub(all) struct NurbsCurve2 {
    bspline : BSpline[
    DVec3
    ]
    }

    NurbsCurve2::control_points

    fn NurbsCurve2::control_points(self : NurbsCurve2) -> FixedArray[
    DVec2
    ]

    NurbsCurve2::degree

    fn NurbsCurve2::degree(self : NurbsCurve2) -> Int

    NurbsCurve2::derivatives

    fn NurbsCurve2::derivatives(self : NurbsCurve2, u : Double, d : Int) -> Array[
    DVec2
    ]?

    Rational derivatives 0..d (quotient rule, weight = z component).

    NurbsCurve2::fit

    fn NurbsCurve2::fit(points : FixedArray[
    DVec2
    ], degree : Int, num_cpts? : Int) -> NurbsCurve2?

    NurbsCurve2::from_points

    fn NurbsCurve2::from_points(degree : Int, knots : KnotVector, points : FixedArray[
    DVec2
    ]) -> NurbsCurve2?

    NurbsCurve2::from_points_weights

    fn NurbsCurve2::from_points_weights(degree : Int, knots : KnotVector, points : FixedArray[
    DVec2
    ], weights : FixedArray[Double]) -> NurbsCurve2?

    NurbsCurve2::insert_knot

    fn NurbsCurve2::insert_knot(self : NurbsCurve2, u : Double, r? : Int) -> NurbsCurve2?

    NurbsCurve2::new_homogeneous

    fn NurbsCurve2::new_homogeneous(degree : Int, knots : KnotVector, ctrlpts : FixedArray[
    DVec3
    ]) -> NurbsCurve2?

    NurbsCurve2::num_ctrlpts

    fn NurbsCurve2::num_ctrlpts(self : NurbsCurve2) -> Int

    NurbsCurve2::offset

    fn NurbsCurve2::offset(self : NurbsCurve2, distance : Double, samples? : Int, degree? : Int, num_cpts? : Int) -> NurbsCurve2?

    Offset a 2D curve by distance (positive = left of the travel direction). Samples samples points, displaces along the left normal, and fits a degree- degree NURBS curve with num_cpts control points. None on evaluation failure.

    NurbsCurve2::point_at

    NurbsCurve2::split

    fn NurbsCurve2::split(self : NurbsCurve2, u : Double) -> (NurbsCurve2, NurbsCurve2)?

    NurbsCurve2::weights

    fn NurbsCurve2::weights(self : NurbsCurve2) -> FixedArray[Double]

    NurbsCurve3

    pub(all) struct NurbsCurve3 {
    bspline : BSpline[
    DVec4
    ]
    }

    A 3D NURBS curve, stored as a homogeneous (DVec4) B-spline. Control points are kept in homogeneous form (xw, yw, z*w, w) so knot/degree algorithms stay affine; friendly point/weight views are provided at the boundary.

    NurbsCurve3::arc_length

    fn NurbsCurve3::arc_length(self : NurbsCurve3, u0? : Double, u1? : Double) -> Double?

    Arc length over [u0, u1] (defaults to the full domain). Integrates span by span with a 16-point Gauss–Legendre rule. None if the interval is invalid.

    NurbsCurve3::arc_length_parameter

    fn NurbsCurve3::arc_length_parameter(self : NurbsCurve3, s : Double, tol? : Double) -> Double?

    Invert arc length: find the parameter u whose arc length from the domain start equals s, via monotone bisection. None if s is outside [0, total].

    NurbsCurve3::build_bvh

    fn NurbsCurve3::build_bvh(self : NurbsCurve3, max_depth? : Int) -> CurveBvh

    Build a curve BVH by recursive splitting to max_depth (default 6).

    NurbsCurve3::closest_parameter

    fn NurbsCurve3::closest_parameter(self : NurbsCurve3, point :
    DVec3
    , tol? : Double) -> Double?

    Closest parameter on the curve to point: coarse domain sampling then 1D BFGS with the analytic gradient 2 (C(u)-P) . C'(u). Returns the better of the refined and coarse candidates. None if evaluation fails.

    NurbsCurve3::closest_point

    Closest point on the curve to point.

    NurbsCurve3::control_points

    fn NurbsCurve3::control_points(self : NurbsCurve3) -> FixedArray[
    DVec3
    ]

    Cartesian control points (homogeneous xyz divided by w).

    NurbsCurve3::decompose_bezier

    fn NurbsCurve3::decompose_bezier(self : NurbsCurve3) -> Array[NurbsCurve3]

    NurbsCurve3::degree

    fn NurbsCurve3::degree(self : NurbsCurve3) -> Int

    NurbsCurve3::degree_elevate

    fn NurbsCurve3::degree_elevate(self : NurbsCurve3) -> NurbsCurve3?

    NurbsCurve3::degree_reduce

    fn NurbsCurve3::degree_reduce(self : NurbsCurve3, tol? : Double) -> NurbsCurve3?

    NurbsCurve3::derivatives

    fn NurbsCurve3::derivatives(self : NurbsCurve3, u : Double, d : Int) -> Array[
    DVec3
    ]?

    Rational derivatives 0..d at u (The NURBS Book A4.2). Row 0 is the point, row 1 the tangent, etc. None outside the domain, if d > degree, or w == 0.

    NurbsCurve3::evaluate_many

    fn NurbsCurve3::evaluate_many(self : NurbsCurve3, us : FixedArray[Double]) -> FixedArray[
    DVec3
    ]?

    Batch projection (design D4). us must be sorted ascending and in-domain.

    NurbsCurve3::fit

    fn NurbsCurve3::fit(points : FixedArray[
    DVec3
    ], degree : Int, num_cpts? : Int, param? : ParamMethod) -> NurbsCurve3?

    Least-squares fit of a curve to data points with a fixed number of control points num_cpts (default num_points-1, which interpolates). Endpoints are fixed to the first/last data points; interior control points solve the overdetermined collocation system via QR. None on invalid sizes.

    NurbsCurve3::from_points

    fn NurbsCurve3::from_points(degree : Int, knots : KnotVector, points : FixedArray[
    DVec3
    ]) -> NurbsCurve3?

    Build a non-rational B-spline curve (all weights 1).

    NurbsCurve3::from_points_weights

    fn NurbsCurve3::from_points_weights(degree : Int, knots : KnotVector, points : FixedArray[
    DVec3
    ], weights : FixedArray[Double]) -> NurbsCurve3?

    Build from Cartesian points + positive weights. Rejects mismatched lengths or non-positive weights (negative-weight conic representations are a later, explicitly-opt-in feature).

    NurbsCurve3::insert_knot

    fn NurbsCurve3::insert_knot(self : NurbsCurve3, u : Double, r? : Int) -> NurbsCurve3?

    NurbsCurve3::interpolate

    fn NurbsCurve3::interpolate(points : FixedArray[
    DVec3
    ], degree : Int, param? : ParamMethod) -> NurbsCurve3?

    Global interpolation of points with the given degree and parameterization (default chord-length). Returns a non-rational curve passing through every point. None if there are fewer than degree+1 points or coincident points.

    NurbsCurve3::new_homogeneous

    fn NurbsCurve3::new_homogeneous(degree : Int, knots : KnotVector, ctrlpts : FixedArray[
    DVec4
    ]) -> NurbsCurve3?

    Build directly from homogeneous (DVec4) control points (xw, yw, z*w, w). Used by constructors that transform control points in homogeneous space.

    NurbsCurve3::num_ctrlpts

    fn NurbsCurve3::num_ctrlpts(self : NurbsCurve3) -> Int

    NurbsCurve3::point_at

    Evaluate the curve at u. None outside the domain or at a zero-weight point.

    NurbsCurve3::remove_knot

    fn NurbsCurve3::remove_knot(self : NurbsCurve3, u : Double, tol? : Double, r? : Int) -> NurbsCurve3?

    NurbsCurve3::split

    fn NurbsCurve3::split(self : NurbsCurve3, u : Double) -> (NurbsCurve3, NurbsCurve3)?

    NurbsCurve3::weights

    fn NurbsCurve3::weights(self : NurbsCurve3) -> FixedArray[Double]

    NurbsSurface3

    pub(all) struct NurbsSurface3 {
    degree_u : Int
    degree_v : Int
    knots_u : KnotVector
    knots_v : KnotVector
    ctrlpts : FixedArray[
    DVec4
    ]
    }

    A 3D NURBS surface. Control points are stored row-major in homogeneous form (xw, yw, z*w, w): index = i * num_v + j, with i the u-row and j the v-column.

    NurbsSurface3::closest_parameter

    fn NurbsSurface3::closest_parameter(self : NurbsSurface3, point :
    DVec3
    , tol? : Double) -> (Double, Double)?

    Closest parameters on the surface to point: coarse grid sampling then 2D BFGS with analytic gradient (2 (S-P).S_u, 2 (S-P).S_v). None on failure.

    NurbsSurface3::closest_point

    Closest point on the surface to point.

    NurbsSurface3::extrude

    Extrude a profile curve along a Cartesian direction vector. The profile is the u direction; the extrusion is a degree-1 v direction (v=0 profile, v=1 profile+direction). Exact.

    NurbsSurface3::fit

    fn NurbsSurface3::fit(points : FixedArray[
    DVec3
    ], size_u : Int, size_v : Int, degree_u : Int, degree_v : Int, num_cpts_u? : Int, num_cpts_v? : Int) -> NurbsSurface3?

    Least-squares fit of a non-rational surface to a row-major grid of data points (size_u columns x size_v rows), by separable u- then v-direction curve fits with uniform parameters (so knot vectors stay consistent across rows/columns).

    NurbsSurface3::from_points

    fn NurbsSurface3::from_points(degree_u : Int, degree_v : Int, knots_u : KnotVector, knots_v : KnotVector, points : FixedArray[
    DVec3
    ]) -> NurbsSurface3?

    Construct a non-rational surface (all weights 1).

    NurbsSurface3::from_points_weights

    fn NurbsSurface3::from_points_weights(degree_u : Int, degree_v : Int, knots_u : KnotVector, knots_v : KnotVector, points : FixedArray[
    DVec3
    ], weights : FixedArray[Double]) -> NurbsSurface3?

    Construct from Cartesian points + positive weights (row-major grids).

    NurbsSurface3::loft

    fn NurbsSurface3::loft(curves : Array[NurbsCurve3], degree_v? : Int) -> NurbsSurface3?

    Loft through a sequence of compatible curves (same degree, knot vector and control-point count). Each control-point column is interpolated in the v direction. degree_v defaults to min(degree_u, num_curves-1). Exact.

    NurbsSurface3::new

    fn NurbsSurface3::new(degree_u : Int, degree_v : Int, knots_u : KnotVector, knots_v : KnotVector, ctrlpts : FixedArray[
    DVec4
    ]) -> NurbsSurface3?

    Construct from a homogeneous control-point grid (row-major, num_u * num_v).

    NurbsSurface3::normal_at

    fn NurbsSurface3::normal_at(self : NurbsSurface3, u : Double, v : Double) ->
    DVec3
    ?

    Unit surface normal at (u, v) from the rational first partials: S_u = (A_u - w_u S) / w, S_v = (A_v - w_v S) / w, normal = normalize(S_u x S_v). None outside the domain, at zero weight, or at a degenerate (zero-area) point.

    NurbsSurface3::num_u

    fn NurbsSurface3::num_u(self : NurbsSurface3) -> Int

    NurbsSurface3::num_v

    fn NurbsSurface3::num_v(self : NurbsSurface3) -> Int

    NurbsSurface3::point_at

    fn NurbsSurface3::point_at(self : NurbsSurface3, u : Double, v : Double) ->
    DVec3
    ?

    Evaluate the surface at (u, v). None outside the domain or at zero weight.

    NurbsSurface3::revolve

    Revolve a profile curve around an axis (point center, direction axis) by angle theta (radians, |theta| <= 2pi). The profile is the u direction; the revolution is a rational quadratic-arc v direction split into 1..4 segments (each <= pi/2). The middle control point of each arc sits at radius r / cos(dtheta/2) at the mid-angle (analytic tangent intersection). Reference: curvo try_revolve_by_start_end (start = 0).

    NurbsSurface3::sweep

    fn NurbsSurface3::sweep(profile : NurbsCurve3, path : NurbsCurve3, samples? : Int) -> NurbsSurface3?

    Sweep a profile curve along a path (spine) using rotation-minimizing (parallel-transport) frames. The profile is rigidly carried along the path: its coordinates relative to the start frame are re-expressed in each sampled frame, and the transformed profiles are lofted. Exact for a straight path; a sampled approximation for curved paths (increase samples for accuracy).

    NurbsSurface3::tessellate

    fn NurbsSurface3::tessellate(self : NurbsSurface3, segs_u : Int, segs_v : Int) -> Tessellation?

    Tessellate on a uniform (segs_u x segs_v) parameter grid. None if segs < 1.

    NurbsSurface3::tessellate_adaptive

    fn NurbsSurface3::tessellate_adaptive(self : NurbsSurface3, chord_tol? : Double, max_depth? : Int) -> Tessellation?

    Curvature-adaptive tessellation: recursively subdivide each parameter direction where the chord deviation exceeds chord_tol (up to max_depth), then mesh the tensor product of the break sets. Flat regions stay coarse; curved regions refine. Crack-free. None on invalid tolerance/depth.

    ParamMethod

    pub enum ParamMethod {
    Uniform
    ChordLength
    Centripetal
    }

    Parameterization method for global interpolation.

    Tessellation

    pub(all) struct Tessellation {
    positions : FixedArray[
    DVec3
    ]
    normals : FixedArray[
    DVec3
    ]
    uvs : FixedArray[
    DVec2
    ]
    indices : FixedArray[UInt]
    }

    A neutral triangle mesh in Double precision. Core output; the mesh adapter down-casts to Float MeshData at the boundary.

    TrimmedCurve2

    pub(all) struct TrimmedCurve2 {
    curve : NurbsCurve2
    intervals : Array[(Double, Double)]
    }

    TrimmedCurve2::contains

    fn TrimmedCurve2::contains(self : TrimmedCurve2, u : Double) -> Bool

    TrimmedCurve2::flatten

    Flatten each kept interval into a polyline of samples segments. Returns one polyline per interval (the input to 2D boolean / CDT pipelines).

    TrimmedCurve2::new

    fn TrimmedCurve2::new(curve : NurbsCurve2, intervals : Array[(Double, Double)]) -> TrimmedCurve2?

    Build a trimmed curve from sorted, disjoint intervals within the curve domain. Intervals are validated (u0 < u1, in domain, non-overlapping) and sorted.

    TrimmedCurve2::point_at

    Evaluate at u only if it lies in a kept interval; otherwise None.

    boolean_polygons

    Greiner–Hormann boolean of two simple polygons (implicitly closed, general position: no shared edges/vertices). Returns the result region polygons.

    cdt

    fn cdt(points : Array[
    DVec2
    ], constraints : Array[(Int, Int)]) -> Array[(Int, Int, Int)]

    Constrained Delaunay triangulation. constraints are index pairs that must appear as edges. Returns CCW triangle index triples (no super-triangle verts).

    clip_convex

    Sutherland–Hodgman clipping of a subject polygon against a convex clip polygon (both CCW, implicitly closed). Returns the intersection polygon.

    fillet_corner

    Fillet the corner between segments (prev -> corner) and (corner -> next) with a tangent arc of the given radius. Returns the arc curve (from the tangent point on the first segment to that on the second). None if degenerate (collinear or zero radius).

    intersect_curve_surface

    fn intersect_curve_surface(c : NurbsCurve3, s : NurbsSurface3, tol? : Double) -> Array[(Double, Double, Double)]

    Curve-surface intersection parameters (curve u, surface u, surface v) where the curve meets the surface within tol.

    intersect_curves

    fn intersect_curves(c1 : NurbsCurve3, c2 : NurbsCurve3, tol? : Double) -> Array[(Double, Double)]

    Curve-curve intersection parameters (u on c1, v on c2) where the curves meet within tol. Multi-start BFGS over the product domain.

    intersect_surfaces

    fn intersect_surfaces(s1 : NurbsSurface3, s2 : NurbsSurface3, tol? : Double) -> Array[(Double, Double, Double, Double)]

    Surface-surface intersection parameters (u1, v1, u2, v2) where the surfaces meet within tol. Returns discrete intersection points; full curve tracing (marching) is a later refinement.

    point_in_polygon

    Ray-casting point-in-polygon test (polygon implicitly closed).

    vcombine

    fn[V : VecSpace] vcombine(points : FixedArray[V], weights : FixedArray[Double]) -> V

    Generic affine combination of a slice with weights (de Boor's inner loop shape). Validates that generic code can fold over a FixedArray of V.

    vdistance

    fn[V : VecSpace] vdistance(a : V, b : V) -> Double

    Distance induced by the vector-space norm (used by tolerance-driven knot removal in the approximate layer).

    vlerp

    fn[V : VecSpace] vlerp(a : V, b : V, t : Double) -> V

    Generic linear interpolation — the simplest algorithm that exercises the trait. Used as the D2 feasibility probe before building the full kernel.