Skip to content

Commit

Permalink
Preserve the unit when interpolating/adding angles with matching units.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mantaroh committed Jun 19, 2017
1 parent 8c58736 commit ccf08bc
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions components/style/properties/helpers/animated_properties.mako.rs
Expand Up @@ -936,9 +936,20 @@ impl Animatable for i32 {
impl Animatable for Angle {
#[inline]
fn add_weighted(&self, other: &Angle, self_portion: f64, other_portion: f64) -> Result<Self, ()> {
self.radians()
.add_weighted(&other.radians(), self_portion, other_portion)
.map(Angle::from_radians)
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()
.add_weighted(&other.radians(), self_portion, other_portion)
.map(Angle::from_radians)
}
}
}
}

Expand Down

0 comments on commit ccf08bc

Please sign in to comment.