Expand description
Composable traits for working with parametric curves and geometric queries.
This crate provides a unified interface for sampling paths by arc-length, querying differential properties (tangents, curvature, heading), projecting points onto curves, and composing paths through reversal, concatenation, and offsetting. The trait design is inspired by Tower’s layered approach, but the focus here is on making geometric queries ergonomic and reusable across any curve representation.
§Quick example
use path_traits::{Path, Scalar};
fn print_length<P: Path>(path: &P) {
println!("length = {:?}", path.length());
}§Crate features
std- enablesstd-specific integrations. The core traits work withoutstd;core::error::Erroris available via Rust edition 2024. When combined withnum-traits, forwardsstdto that crate for the fullFloattrait (instead ofFloatCore).num-traits- usesnum-traitsas theScalarbackend. Withoutstd,Scalaris bounded byFloatCore; withstd, it is bounded byFloat.
The default build is no_std with zero external dependencies, providing
manual Scalar implementations for f32 and f64 using only core.
§What’s available
Scalar,Point,Vector- numeric and geometric primitivesPath,ParametricPath- sample curves by arc-length or normalized parameterPathSegment,SegmentedPath- work with multi-segment paths like polylinesTangent,Heading,Curved,FrenetFrame- differential geometry queriesProject- closest-point projection onto a pathPathExt- chainable adapters:Reverse,Concat,Offset
Structs§
- Concat
- Two paths joined end-to-end into a single continuous path.
- Offset
- A path displaced by a constant distance from the original.
- Reverse
- A path traversed in the opposite direction.
Enums§
- Path
Error - Errors that can occur during path sampling or geometric queries.
Traits§
- Curved
- Query the curvature at any point along a path.
- Frenet
Frame - Query the full Frenet frame (T, N[, B]) at any point along a path.
- Heading
- Query the planar heading angle at any point along a path.
- Parametric
Path - A curve that also supports sampling by a normalized parameter
t ∈ [0, 1]. - Path
- A curve that can be sampled by arc-length
s. - PathExt
- Ergonomic methods for path composition and transformation.
- Path
Segment - Marker for a primitive curve that cannot be further subdivided.
- Point
- A position in an affine space, parameterized by its scalar and vector types.
- Project
- Project a query point onto a path to find the nearest position.
- Scalar
- A scalar type suitable for arc-length, parameter, and distance computations.
- Segmented
Path - A path made up of multiple
PathSegments. - Tangent
- Query the unit tangent vector at any point along a path.
- Vector
- A displacement or derivative in Euclidean space.
Functions§
- equidistant
- Sample a path at equidistant arc-length intervals.
- n_
samples - Sample a path at
nevenly-spaced arc-length positions. - uniform_
t - Sample a parametric path at
nevenly-spacedtvalues in[0, 1].