pub fn from_bezier<V: Animatable>(b0: &V, b1: &V, b2: &V, b3: &V, rectify: bool) -> SplineMap {
        let mut steps = Vec::new();
        let mut length: f64 = 0.0;
        let zero = b0.map(|_| V::Component::zero());

        // Integrate arc length between t = a..b
        let integrate = |a, b| {
            // Get tangents at start, middle and end
            let dt0 = dt_cubic_bezier(b0, b1, b2, b3, a);
            let dt1 = dt_cubic_bezier(b0, b1, b2, b3, (a + b) / 2.0);
            let dt2 = dt_cubic_bezier(b0, b1, b2, b3, b);

            // Get magnitude
            let ds0 = zero.distance_to(dt0);
            let ds1 = zero.distance_to(dt1);
            let ds2 = zero.distance_to(dt2);

            // Simpson's 1/3 rule
            (ds0 + 4.0 * ds1 + ds2) * (b - a) / 6.0
        };

        // Insert one negative point before
        let step = 1.0 / (SPLINE_SUBDIVISION as f64);
        steps.push((-step, -integrate(-step, 0.0)));
        steps.push((0.0, 0.0));

        // Measure arc length of each segment
        let mut last = 0.0;
        let mut t = 0.0;
        for _i in 0..=SPLINE_SUBDIVISION {
            t += step;
            let d = integrate(last, t);
            last = t;

            length += d;
            steps.push((t, length));
        }

        // Ignore one point after
        length = steps[steps.len() - 2].1;

        SplineMap {
            steps,
            length,
            rectify,
        }
    }
// Make a spline map from a cubic bezier to map "spline time" 0..1 to arc length 0..d.
// Uses analytic derivatives and simpson's rule for more accurate integration.
// (only makes a difference for strongly cusped curves)
Make a spline map from a cubic bezier to map "spline time" 0..1 to arc length 0..d.
Uses analytic derivatives and simpson's rule for more accurate integration.
(only makes a difference for strongly cusped curves)
Make a spline map from a cubic bezier to map " spline time " 0 .. 1 to arc length 0 .. d . Uses analytic derivatives and simpson ' s rule for more accurate integration . ( only makes a difference for strongly cusped curves )
pub fn from_bezier<V: Animatable>(b0: &V, b1: &V, b2: &V, b3: &V, rectify: bool) -> SplineMap {
        let mut steps = Vec::new();
        let mut length: f64 = 0.0;
        let zero = b0.map(|_| V::Component::zero());
        // Integrate arc length between t = a..b
        let integrate = |a, b| {
            // Get tangents at start, middle and end
            let dt0 = dt_cubic_bezier(b0, b1, b2, b3, a);
            let dt1 = dt_cubic_bezier(b0, b1, b2, b3, (a + b) / 2.0);
            let dt2 = dt_cubic_bezier(b0, b1, b2, b3, b);
            // Get magnitude
            let ds0 = zero.distance_to(dt0);
            let ds1 = zero.distance_to(dt1);
            let ds2 = zero.distance_to(dt2);
            // Simpson's 1/3 rule
            (ds0 + 4.0 * ds1 + ds2) * (b - a) / 6.0
        };
        // Insert one negative point before
        let step = 1.0 / (SPLINE_SUBDIVISION as f64);
        steps.push((-step, -integrate(-step, 0.0)));
        steps.push((0.0, 0.0));
        // Measure arc length of each segment
        let mut last = 0.0;
        let mut t = 0.0;
        for _i in 0..=SPLINE_SUBDIVISION {
            t += step;
            let d = integrate(last, t);
            last = t;
            length += d;
            steps.push((t, length));
        }
        // Ignore one point after
        length = steps[steps.len() - 2].1;
        SplineMap {
            steps,
            length,
            rectify,
        }
    }
pub fn from_bezier < V : Animatable > ( b0 : & V , b1 : & V , b2 : & V , b3 : & V , rectify : bool ) -> SplineMap { let mut steps = Vec :: new ( ) ; let mut length : f64 = 0.0 ; let zero = b0 . map ( | _ | V :: Component :: zero ( ) ) ; // Integrate arc length between t = a..b let integrate = | a , b | { // Get tangents at start, middle and end let dt0 = dt_cubic_bezier ( b0 , b1 , b2 , b3 , a ) ; let dt1 = dt_cubic_bezier ( b0 , b1 , b2 , b3 , ( a + b ) / 2.0 ) ; let dt2 = dt_cubic_bezier ( b0 , b1 , b2 , b3 , b ) ; // Get magnitude let ds0 = zero . distance_to ( dt0 ) ; let ds1 = zero . distance_to ( dt1 ) ; let ds2 = zero . distance_to ( dt2 ) ; // Simpson's 1/3 rule ( ds0 + 4.0 * ds1 + ds2 ) * ( b - a ) / 6.0 } ; // Insert one negative point before let step = 1.0 / ( SPLINE_SUBDIVISION as f64 ) ; steps . push ( ( - step , - integrate ( - step , 0.0 ) ) ) ; steps . push ( ( 0.0 , 0.0 ) ) ; // Measure arc length of each segment let mut last = 0.0 ; let mut t = 0.0 ; for _i in 0 ..= SPLINE_SUBDIVISION { t += step ; let d = integrate ( last , t ) ; last = t ; length += d ; steps . push ( ( t , length ) ) ; } // Ignore one point after length = steps [ steps . len ( ) - 2 ] . 1 ; SplineMap { steps , length , rectify , } }
Make a spline map from a cubic bezier to map "spline time" 0..1 to arc length 0..d.
Uses analytic derivatives and simpson's rule for more accurate integration.
Make a spline map from a cubic bezier to map " spline time " 0 .. 1 to arc length 0 .. d . Uses analytic derivatives and simpson ' s rule for more accurate integration .
b0
&V
b1
&V
b2
&V
b3
&V
rectify
bool
b0
&V
b1
&V
b2
&V
b3
&V
rectify
bool