Use Horner's method to evaluate cubics

This commit is contained in:
Patrick Walton 2018-12-29 18:29:26 -08:00
parent 1a6b5bd27d
commit 28d948a36e
1 changed files with 5 additions and 9 deletions

View File

@ -1736,15 +1736,11 @@ impl CubicAxis {
} }
impl SolveT for CubicAxis { impl SolveT for CubicAxis {
fn sample(&self, t: f32) -> f32 { fn sample(&self, t: f32) -> f32 {
let t2 = t * t; let b3 = self.to + 3.0 * (self.ctrl0 - self.ctrl1) - self.from;
let t3 = t2 * t; let b2 = 3.0 * (self.from - 2.0 * self.ctrl0 + self.ctrl1) + b3 * t;
let b1 = 3.0 * (self.ctrl0 - self.from) + b2 * t;
let c3 = self.to + 3.0 * (self.ctrl0 - self.ctrl1) - self.from; let b0 = self.from + b1 * t;
let c2 = 3.0 * (self.from - 2.0 * self.ctrl0 + self.ctrl1); b0
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 { fn sample_deriv(&self, t: f32) -> f32 {
let inv_t = 1.0 - t; let inv_t = 1.0 - t;