From 20e3508ca3adae77a2e8dd8ae0f44190d776f713 Mon Sep 17 00:00:00 2001 From: Boris Chiou Date: Wed, 26 Jul 2017 17:07:39 +0800 Subject: [PATCH] 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. --- .../style/properties/helpers/animated_properties.mako.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 4b734167c7a2..b580e84f9918 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -925,6 +925,13 @@ impl Animatable for Angle { } } } + + #[inline] + fn compute_distance(&self, other: &Self) -> Result { + // 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