Skip to main content

Crate path_traits

Crate path_traits 

Source
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 - enables std-specific integrations. The core traits work without std; core::error::Error is available via Rust edition 2024. When combined with num-traits, forwards std to that crate for the full Float trait (instead of FloatCore).
  • num-traits - uses num-traits as the Scalar backend. Without std, Scalar is bounded by FloatCore; with std, it is bounded by Float.

The default build is no_std with zero external dependencies, providing manual Scalar implementations for f32 and f64 using only core.

§What’s available

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§

PathError
Errors that can occur during path sampling or geometric queries.

Traits§

Curved
Query the curvature at any point along a path.
FrenetFrame
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.
ParametricPath
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.
PathSegment
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.
SegmentedPath
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 n evenly-spaced arc-length positions.
uniform_t
Sample a parametric path at n evenly-spaced t values in [0, 1].