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

Vec<Bezier> of curves forming the path

lengths

Vec<f32> containing the lengths of the Bezier curves with the same indices; (normalized so that they add up to 1.0)

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);

Trait Implementations

impl MrubyFile for BezierPath

fn require(mruby: MrubyType)

Derived Implementations

impl PartialEq for BezierPath

fn eq(&self, __arg_0: &BezierPath) -> bool

fn ne(&self, __arg_0: &BezierPath) -> bool

impl Debug for BezierPath

fn fmt(&self, __arg_0: &mut Formatter) -> Result

impl Clone for BezierPath

fn clone(&self) -> BezierPath

1.0.0fn clone_from(&mut self, source: &Self)