Introduce values::animated::Animate

This replaces the Animatable trait and merges its three former methods into a single one.
This commit is contained in:
Anthony Ramine 2017-08-17 16:38:08 +02:00
parent 0cceeb9d5c
commit aea0cd7ec7
23 changed files with 876 additions and 937 deletions

View file

@ -4,12 +4,11 @@
//! Computed angles.
use properties::animated_properties::Animatable;
use std::{f32, f64, fmt};
use std::f64::consts::PI;
use style_traits::ToCss;
use values::CSSFloat;
use values::animated::ToAnimatedZero;
use values::animated::{Animate, Procedure, ToAnimatedZero};
use values::distance::{ComputeSquaredDistance, SquaredDistance};
/// A computed angle.
@ -66,36 +65,34 @@ impl Angle {
}
/// https://drafts.csswg.org/css-transitions/#animtype-number
impl Animatable for Angle {
impl Animate for Angle {
#[inline]
fn add_weighted(&self, other: &Self, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
match (self, other) {
(&Angle::Degree(ref this), &Angle::Degree(ref other)) => {
Ok(Angle::Degree(this.add_weighted(other, self_portion, other_portion)?))
Ok(Angle::Degree(this.animate(other, procedure)?))
},
(&Angle::Gradian(ref this), &Angle::Gradian(ref other)) => {
Ok(Angle::Gradian(this.add_weighted(other, self_portion, other_portion)?))
Ok(Angle::Gradian(this.animate(other, procedure)?))
},
(&Angle::Turn(ref this), &Angle::Turn(ref other)) => {
Ok(Angle::Turn(this.add_weighted(other, self_portion, other_portion)?))
Ok(Angle::Turn(this.animate(other, procedure)?))
},
_ => {
self.radians()
.add_weighted(&other.radians(), self_portion, other_portion)
.map(Angle::from_radians)
}
Ok(Angle::from_radians(self.radians().animate(&other.radians(), procedure)?))
},
}
}
}
impl ToAnimatedZero for Angle {
#[inline]
fn to_animated_zero(&self) -> Result<Self, ()> {
fn to_animated_zero(&self) -> Result<Angle, ()> {
match *self {
Angle::Degree(value) => Ok(Angle::Degree(value.to_animated_zero()?)),
Angle::Gradian(value) => Ok(Angle::Gradian(value.to_animated_zero()?)),
Angle::Radian(value) => Ok(Angle::Radian(value.to_animated_zero()?)),
Angle::Turn(value) => Ok(Angle::Turn(value.to_animated_zero()?)),
Angle::Degree(ref this) => Ok(Angle::Degree(this.to_animated_zero()?)),
Angle::Gradian(ref this) => Ok(Angle::Gradian(this.to_animated_zero()?)),
Angle::Radian(ref this) => Ok(Angle::Radian(this.to_animated_zero()?)),
Angle::Turn(ref this) => Ok(Angle::Turn(this.to_animated_zero()?)),
}
}
}