Optimize cubic Bezier sampling a bit
This commit is contained in:
parent
ad9da96336
commit
1a6b5bd27d
|
@ -1736,12 +1736,15 @@ impl CubicAxis {
|
|||
}
|
||||
impl SolveT for CubicAxis {
|
||||
fn sample(&self, t: f32) -> f32 {
|
||||
// FIXME(pcwalton): Use Horner's method or something.
|
||||
let p01 = lerp(self.from, self.ctrl0, t);
|
||||
let p12 = lerp(self.ctrl0, self.ctrl1, t);
|
||||
let p23 = lerp(self.ctrl1, self.to, t);
|
||||
let (p012, p123) = (lerp(p01, p12, t), lerp(p12, p23, t));
|
||||
lerp(p012, p123, t)
|
||||
let t2 = t * t;
|
||||
let t3 = t2 * t;
|
||||
|
||||
let c3 = self.to + 3.0 * (self.ctrl0 - self.ctrl1) - self.from;
|
||||
let c2 = 3.0 * (self.from - 2.0 * self.ctrl0 + self.ctrl1);
|
||||
let c1 = 3.0 * (self.ctrl0 - self.from);
|
||||
let c0 = self.from;
|
||||
|
||||
c3 * t3 + c2 * t2 + c1 * t + c0
|
||||
}
|
||||
fn sample_deriv(&self, t: f32) -> f32 {
|
||||
let inv_t = 1.0 - t;
|
||||
|
|
Loading…
Reference in New Issue