servo: Merge #18292 - style: Prevent Animate to generate NaN float values (from emilio:animate-nan); r=nox

This should fix the assertions in https://bugzilla.mozilla.org/show_bug.cgi?id=1394558.

Source-Repo: https://github.com/servo/servo
Source-Revision: 1c4d0d2d5d3e34e62ad3585b96632f354dbbe208

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : f2941fbe8ccc27e2c55f4e0c8cf1d1f3db2b7c21
This commit is contained in:
Emilio Cobos Álvarez 2017-08-29 05:18:33 -05:00
Родитель 30ebfb2e95
Коммит 36399f2e36
1 изменённых файлов: 9 добавлений и 2 удалений

Просмотреть файл

@ -125,7 +125,10 @@ impl Animate for i32 {
impl Animate for f32 {
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
Ok((*self as f64).animate(&(*other as f64), procedure)? as f32)
use std::f32;
let ret = (*self as f64).animate(&(*other as f64), procedure)?;
Ok(ret.min(f32::MAX as f64).max(f32::MIN as f64) as f32)
}
}
@ -133,8 +136,12 @@ impl Animate for f32 {
impl Animate for f64 {
#[inline]
fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> {
use std::f64;
let (self_weight, other_weight) = procedure.weights();
Ok(*self * self_weight + *other * other_weight)
let ret = *self * self_weight + *other * other_weight;
Ok(ret.min(f64::MAX).max(f64::MIN))
}
}