Expand description
Checked cubic Bezier authoring with allocation-free, bounded tessellation.
CubicBezier3 stores four finite f32 control points. Sampling uses f64
intermediates; positions round to Vec3, while tangents retain f64 derivative
components (not unit directions). A constant curve has zero tangent; a zero
computed derivative at a cusp stays zero, without a fallback direction.
Samples use ordinary floating-point arithmetic, not exact polynomial values.
Tessellation emits an ordered prefix, beginning at control point zero.
Only accepted chords are written. TessellationStatus::Complete certifies
the whole curve; a limit leaves an incomplete prefix, never an unchecked
coarse chord to the final endpoint. Reuse caller storage on the next call;
there is no retained state, append mode, resume cursor, clock or reset.
The error test uses outward-rounded f64 intervals for dyadic de Casteljau subdivision. It bounds the L1 norm of the difference between each subcurve’s four control points and the degree-elevated control points of its rounded output chord. Convexity then bounds Euclidean distance at paired local parameters, in either direction, by that value. This includes subdivision arithmetic and f32 endpoint rounding. It is conservative: a curved or even collinear, nonuniformly parameterized curve can need extra subdivisions. Tiny tolerances can saturate because output quantization/interval width cannot be resolved. Tolerance is in control-point world units, not pixels, angle, arc length or error in route-progress parameterization.
§Runnable native authoring recipe
This uses only math. A route owner can pass &points[..result.written] to
the existing ferravex_play::navigation::Route3::set after checking
Complete; Route3 continues to own arc-length sampling and progression.
use ferravex_math::{Vec3, vec3};
use ferravex_math::curves::{
CubicBezier3, CurveError, TessellationOptions, TessellationStatus,
};
fn main() -> Result<(), CurveError> {
let curve = CubicBezier3::new([
Vec3::ZERO, vec3(0., 2., 0.), vec3(4., 2., 0.), vec3(4., 0., 0.),
])?;
assert_eq!(curve.position(0.)?, curve.control_points()[0]);
assert_eq!(curve.position(1.)?, curve.control_points()[3]);
assert_eq!(curve.tangent(0.)?, [0., 6., 0.]);
let mut points = [Vec3::ZERO; 128];
let result = curve.tessellate_into(&mut points, TessellationOptions {
tolerance: 0.01, max_depth: 16, max_work: 1023,
})?;
assert_eq!(result.status, TessellationStatus::Complete);
assert_eq!(result.covered_until, 1.);
assert!(result.max_error_bound <= 0.01);
assert_eq!(points[result.written - 1], curve.position(1.)?);
Ok(())
}Structs§
- Cubic
Bezier3 - One cubic Bezier in three dimensions, with checked finite control points. Construction and all operations use fixed storage and allocate nothing. See the module’s executable recipe for every operation.
- Tessellation
- Result of a valid tessellation request; see the module recipe.
- Tessellation
Options - Explicit geometric and resource budgets. See the module recipe.
Enums§
- Curve
Error - Invalid authoring input. Errors are distinct from successful partial output.
- Tessellation
Status - Why tessellation stopped. Limits return
Ok, with only certified prefix chords. If multiple limits coincide, output capacity is checked before work; subdivision depth is checked only after a node fails its error test.
Constants§
- MAX_
TESSELLATION_ DEPTH - Largest permitted subdivision depth; bounds the internal DFS stack to 33 nodes. The independently supplied work limit bounds the number examined.