Struct anima_engine::math::BezierPath
[−]
[src]
pub struct BezierPath { pub curves: Vec<Bezier>, pub lengths: Vec<f32>, }
A struct
useful for creating a path of Bézier curves.
Fields
curves |
|
lengths |
|
Methods
impl BezierPath
fn new(curves: Vec<Bezier>) -> BezierPath
Creates a Bézier path using Bezier
curves. Curves must be connected.
Examples
let p = BezierPath::new(vec!(Bezier::new_sqr( Vector::new(0.0, 0.0, 0.0), Vector::new(1.0, 0.0, 0.0), Vector::new(2.0, 0.0, 0.0) ))); assert_eq!(p, BezierPath { curves: vec!(Bezier::new_sqr( Vector::new(0.0, 0.0, 0.0), Vector::new(1.0, 0.0, 0.0), Vector::new(2.0, 0.0, 0.0) )), lengths: vec!(1.0) });
fn interpolate(&self, ratio: f32) -> Vector
Computes the vector on a Bézier path correspoding to a ratio
(between 0.0
and 1.0
).
Examples
let b1 = Bezier::new_sqr( Vector::new(0.0, 0.0, 0.0), Vector::new(1.0, 1.0, 0.0), Vector::new(2.0, 2.0, 0.0) ); let b2 = Bezier::new_sqr( Vector::new(2.0, 2.0, 0.0), Vector::new(6.0, 6.0, 0.0), Vector::new(10.0, 10.0, 0.0) ); let p = BezierPath::new(vec![b1, b2]); assert_eq!(p.interpolate(0.5), Vector::new(5.0, 5.0, 0.0)); assert_eq!(p.interpolate(1.2), Vector::new(12.0, 12.0, 0.0));
fn len(&self, steps: i32) -> f32
Computes the approximated length of a Bézier path by summing the distances between steps
uniformly distrubuted, consecutive points per curve.
Examples
let b1 = Bezier::new_sqr( Vector::new(0.0, 0.0, 0.0), Vector::new(1.0, 1.0, 0.0), Vector::new(2.0, 2.0, 0.0) ); let b2 = Bezier::new_sqr( Vector::new(2.0, 2.0, 0.0), Vector::new(6.0, 6.0, 0.0), Vector::new(10.0, 10.0, 0.0) ); let p = BezierPath::new(vec![b1, b2]); const EPSILON: f32 = 0.001; assert!((p.len(20) - 14.142137).abs() < EPSILON);