Tycho NURBS — zero-dependency pure-MoonBit B-spline/NURBS kernel (math-only core, exact/approx split, batch evaluation)
| Principle | What it means here |
|---|---|
| D1 — math-only core | This 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 projection | Every 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 split | knot.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 path | BSpline::evaluate_many / NurbsCurve3::evaluate_many walk sorted parameters with a monotonically advancing knot span, amortizing span search for tessellation and arc-length sweeps. |
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 onlymoon 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)pub trait VecSpace {
fn vzero() -> Self
fn vadd(Self, Self) -> Self
fn vscale(Self, Double) -> Self
fn vlength(Self) -> Double
}pub(all) struct KnotVector {
knots : FixedArray[Double]
}fn KnotVector::basis_funs(self : KnotVector, span : Int, degree : Int, u : Double) -> FixedArray[Double]fn KnotVector::ders_basis_funs(self : KnotVector, span : Int, degree : Int, u : Double, d : Int) -> FixedArray[FixedArray[Double]]fn NurbsCurve2::from_points(degree : Int, knots : KnotVector, points : FixedArray[DVec2]) -> NurbsCurve2?fn NurbsCurve2::from_points_weights(degree : Int, knots : KnotVector, points : FixedArray[DVec2], weights : FixedArray[Double]) -> NurbsCurve2?fn NurbsCurve2::new_homogeneous(degree : Int, knots : KnotVector, ctrlpts : FixedArray[DVec3]) -> NurbsCurve2?fn NurbsCurve2::offset(self : NurbsCurve2, distance : Double, samples? : Int, degree? : Int, num_cpts? : Int) -> NurbsCurve2?fn NurbsCurve3::fit(points : FixedArray[DVec3], degree : Int, num_cpts? : Int, param? : ParamMethod) -> NurbsCurve3?fn NurbsCurve3::from_points(degree : Int, knots : KnotVector, points : FixedArray[DVec3]) -> NurbsCurve3?fn NurbsCurve3::from_points_weights(degree : Int, knots : KnotVector, points : FixedArray[DVec3], weights : FixedArray[Double]) -> NurbsCurve3?fn NurbsCurve3::interpolate(points : FixedArray[DVec3], degree : Int, param? : ParamMethod) -> NurbsCurve3?fn NurbsCurve3::new_homogeneous(degree : Int, knots : KnotVector, ctrlpts : FixedArray[DVec4]) -> NurbsCurve3?fn NurbsCurve3::remove_knot(self : NurbsCurve3, u : Double, tol? : Double, r? : Int) -> NurbsCurve3?pub(all) struct NurbsSurface3 {
degree_u : Int
degree_v : Int
knots_u : KnotVector
knots_v : KnotVector
ctrlpts : FixedArray[DVec4]
}fn NurbsSurface3::closest_parameter(self : NurbsSurface3, point : DVec3, tol? : Double) -> (Double, Double)?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?fn NurbsSurface3::from_points(degree_u : Int, degree_v : Int, knots_u : KnotVector, knots_v : KnotVector, points : FixedArray[DVec3]) -> NurbsSurface3?fn NurbsSurface3::from_points_weights(degree_u : Int, degree_v : Int, knots_u : KnotVector, knots_v : KnotVector, points : FixedArray[DVec3], weights : FixedArray[Double]) -> NurbsSurface3?fn NurbsSurface3::new(degree_u : Int, degree_v : Int, knots_u : KnotVector, knots_v : KnotVector, ctrlpts : FixedArray[DVec4]) -> NurbsSurface3?fn NurbsSurface3::revolve(profile : NurbsCurve3, center : DVec3, axis : DVec3, theta : Double) -> NurbsSurface3?fn NurbsSurface3::sweep(profile : NurbsCurve3, path : NurbsCurve3, samples? : Int) -> NurbsSurface3?fn NurbsSurface3::tessellate_adaptive(self : NurbsSurface3, chord_tol? : Double, max_depth? : Int) -> Tessellation?pub enum ParamMethod {
Uniform
ChordLength
Centripetal
}fn intersect_curve_surface(c : NurbsCurve3, s : NurbsSurface3, tol? : Double) -> Array[(Double, Double, Double)]fn intersect_surfaces(s1 : NurbsSurface3, s2 : NurbsSurface3, tol? : Double) -> Array[(Double, Double, Double, Double)]Install
Download zipTycho NURBS — zero-dependency pure-MoonBit B-spline/NURBS kernel (math-only core, exact/approx split, batch evaluation)