Trait Curve

Source
pub trait Curve<F: Float, P: CurvePoint<F>> {
Show 13 methods // Required methods fn value_at(&self, t: F) -> P; fn tangent_at(&self, t: F) -> P; fn estimate_length(&self, precision: F) -> F where P: Distance<F>; // Provided methods fn start_point(&self) -> P { ... } fn end_point(&self) -> P { ... } fn dot(p0: P) -> Bezier0<F, P> { ... } fn line(p0: P, p1: P) -> Bezier1<F, P> { ... } fn quad_bezier(p0: P, p1: P, p2: P) -> Bezier2<F, P> { ... } fn cubic_bezier(p0: P, p1: P, p2: P, p3: P) -> Bezier3<F, P> { ... } fn into_iter(self, steps_count: usize) -> CurveIterator<F, P, Self> where Self: Sized { ... } fn into_iter_inclusive( self, steps_count: usize, ) -> CurveIterator<F, P, Self> where Self: Sized { ... } fn composed_curve(start_point: P) -> ComposedCurve<F, P> { ... } fn linear_speed( self, table_size: usize, steps_count: usize, ) -> LinearSpeed<F, P, Self> where P: Distance<F>, Self: Sized { ... }
}
Expand description

A curve is a parametric function that maps a value t in range from 0 to 1 to a point in space.

Required Methods§

Source

fn value_at(&self, t: F) -> P

Get the point at a given value t in range from 0 to 1.

Source

fn tangent_at(&self, t: F) -> P

Get the derivative at a given value t in range from 0 to 1.

Source

fn estimate_length(&self, precision: F) -> F
where P: Distance<F>,

Estimate the length of the curve as an average between min and max estimation. The precision parameter is the maximum ration of min and max estimation.

Precision:

  • F::infinity() - means that estimation will be done in one step,
  • 1.0 - means that max / min should be less than 100%,
  • 0.5 - the same as above, but the difference is 50%,
  • 0.1 - the same as above, but the difference is 10%,
  • and so on…

Provided Methods§

Source

fn start_point(&self) -> P

Source

fn end_point(&self) -> P

Source

fn dot(p0: P) -> Bezier0<F, P>

Create a dot, at any t it will return the same value

Source

fn line(p0: P, p1: P) -> Bezier1<F, P>

Create a line

Source

fn quad_bezier(p0: P, p1: P, p2: P) -> Bezier2<F, P>

Create a quadratic bezier curve

Source

fn cubic_bezier(p0: P, p1: P, p2: P, p3: P) -> Bezier3<F, P>

Create a cubic bezier curve

Source

fn into_iter(self, steps_count: usize) -> CurveIterator<F, P, Self>
where Self: Sized,

Create an iterator that will generate points on the curve.

Source

fn into_iter_inclusive(self, steps_count: usize) -> CurveIterator<F, P, Self>
where Self: Sized,

Create an iterator that will generate points on the curve, including the last point.

Source

fn composed_curve(start_point: P) -> ComposedCurve<F, P>

Create a composed curve that will be a sequence of curves. Each segment of the curve will be represented by equal t range. For example, if you have 3 curves, they will take t ranges: 0 - 0.33, 0.33 - 0.66 and 0.66 - 1.0.

Source

fn linear_speed( self, table_size: usize, steps_count: usize, ) -> LinearSpeed<F, P, Self>
where P: Distance<F>, Self: Sized,

Create a linear speed curve that will allow to move with a constant speed along the curve. It’s especially useful when you want to animate the movement along a composed curve.

Arguments:

  • table_size - the size of the table that will be used to speed up the calculations, the bigger means the better the precision.
  • steps_count - the number of steps that will be used to calculate the table, so if you have 3 steps then the curve points will be calculated at 0.0, 0.5 and 1.0. Intermediate points will be interpolated.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<F: Float, P: CurvePoint<F> + Distance<F>, C: Curve<F, P>> Curve<F, P> for LinearSpeed<F, P, C>

Source§

impl<F: Float, P: CurvePoint<F>> Curve<F, P> for Bezier0<F, P>

Source§

impl<F: Float, P: CurvePoint<F>> Curve<F, P> for Bezier1<F, P>

Source§

impl<F: Float, P: CurvePoint<F>> Curve<F, P> for Bezier2<F, P>

Source§

impl<F: Float, P: CurvePoint<F>> Curve<F, P> for Bezier3<F, P>

Source§

impl<F: Float, P: CurvePoint<F>> Curve<F, P> for ComposedCurve<F, P>