mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
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:
parent
8366b4d4f9
commit
2f07b29296
7 changed files with 261 additions and 200 deletions
|
@ -113,8 +113,9 @@
|
|||
% if delegate_animate:
|
||||
use properties::animated_properties::Animatable;
|
||||
impl Animatable for T {
|
||||
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
||||
self.0.interpolate(&other.0, progress).map(T)
|
||||
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64)
|
||||
-> Result<Self, ()> {
|
||||
self.0.add_weighted(&other.0, self_portion, other_portion).map(T)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -976,16 +977,17 @@
|
|||
<%def name="impl_animatable_for_option_tuple(value_for_none)">
|
||||
impl Animatable for T {
|
||||
#[inline]
|
||||
fn interpolate(&self, other: &Self, progress: f64) -> Result<Self, ()> {
|
||||
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64)
|
||||
-> Result<Self, ()> {
|
||||
match (self, other) {
|
||||
(&T(Some(ref this)), &T(Some(ref other))) => {
|
||||
Ok(T(this.interpolate(other, progress).ok()))
|
||||
Ok(T(this.add_weighted(other, self_portion, other_portion).ok()))
|
||||
},
|
||||
(&T(Some(ref this)), &T(None)) => {
|
||||
Ok(T(this.interpolate(&${value_for_none}, progress).ok()))
|
||||
Ok(T(this.add_weighted(&${value_for_none}, self_portion, other_portion).ok()))
|
||||
},
|
||||
(&T(None), &T(Some(ref other))) => {
|
||||
Ok(T(${value_for_none}.interpolate(other, progress).ok()))
|
||||
Ok(T(${value_for_none}.add_weighted(other, self_portion, other_portion).ok()))
|
||||
},
|
||||
(&T(None), &T(None)) => {
|
||||
Ok(T(None))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue