Implement compute_distance for Angle.

When computing the distance between two filter functions, e.g.
HueRotate(0deg) and HueRotate(-360deg), we got an Err(()) and unwrap it
immediately in compute_filter_square_distance(), which causes a crash.
The root-cause is that we don't implement computed_distance of Angle, and we
assume we always get a valid result from compute_squared_distance() for
each filter function.
This commit is contained in:
Boris Chiou 2017-07-26 17:07:39 +08:00
parent b38d3f2976
commit 20e3508ca3

View file

@ -925,6 +925,13 @@ impl Animatable for Angle {
}
}
}
#[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
// Use the formula for calculating the distance between angles defined in SVG:
// https://www.w3.org/TR/SVG/animate.html#complexDistances
Ok((self.radians64() - other.radians64()).abs())
}
}
/// https://drafts.csswg.org/css-transitions/#animtype-percentage