mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Preserve the unit when interpolating/adding angles with matching units.
If the units of two angles being interpolated/added matches, we should preserve the original unit; otherwise, we fall back to radians. This matches the behavior of Gecko.
This commit is contained in:
parent
8c58736989
commit
ccf08bcead
1 changed files with 14 additions and 3 deletions
|
@ -936,11 +936,22 @@ impl Animatable for i32 {
|
||||||
impl Animatable for Angle {
|
impl Animatable for Angle {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add_weighted(&self, other: &Angle, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
|
fn add_weighted(&self, other: &Angle, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
|
||||||
|
match (*self, *other) {
|
||||||
|
% for angle_type in [ 'Degree', 'Gradian', 'Turn' ]:
|
||||||
|
(Angle::${angle_type}(val1), Angle::${angle_type}(val2)) => {
|
||||||
|
Ok(Angle::${angle_type}(
|
||||||
|
try!(val1.add_weighted(&val2, self_portion, other_portion))
|
||||||
|
))
|
||||||
|
}
|
||||||
|
% endfor
|
||||||
|
_ => {
|
||||||
self.radians()
|
self.radians()
|
||||||
.add_weighted(&other.radians(), self_portion, other_portion)
|
.add_weighted(&other.radians(), self_portion, other_portion)
|
||||||
.map(Angle::from_radians)
|
.map(Angle::from_radians)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// https://drafts.csswg.org/css-transitions/#animtype-percentage
|
/// https://drafts.csswg.org/css-transitions/#animtype-percentage
|
||||||
impl Animatable for Percentage {
|
impl Animatable for Percentage {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue