Rewrite interpolate() in terms of a more general add_weighted() function

Generalizing the procedure like this will allow us to re-use it for addition of
most types.
This commit is contained in:
Brian Birtles 2017-05-15 12:26:21 +09:00
parent 8366b4d4f9
commit 2f07b29296
7 changed files with 261 additions and 200 deletions

View file

@ -1073,10 +1073,12 @@ ${helpers.single_keyword_system("font-variant-caps",
}
impl Animatable for T {
fn interpolate(&self, other: &Self, time: f64) -> Result<Self, ()> {
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64)
-> Result<Self, ()> {
match (*self, *other) {
(T::Number(ref number), T::Number(ref other)) =>
Ok(T::Number(try!(number.interpolate(other, time)))),
Ok(T::Number(try!(number.add_weighted(other,
self_portion, other_portion)))),
_ => Err(()),
}
}