Bug 1387973 - Implement distance for shadow list. r?boris draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Wed, 16 Aug 2017 11:33:06 +0900
changeset 647245 2da8926e91a3f504d6167451c91e57c975883101
parent 647201 33c2573359b3aaf4ae93c133fda908fbb406aa51
child 647246 faba4924e39029fd1c6837a2651d98e469587981
push id74338
push userhikezoe@mozilla.com
push dateWed, 16 Aug 2017 04:49:02 +0000
reviewersboris
bugs1387973
milestone57.0a1
Bug 1387973 - Implement distance for shadow list. r?boris MozReview-Commit-ID: D0jd6Lm4fek
servo/components/style/values/animated/effects.rs
--- a/servo/components/style/values/animated/effects.rs
+++ b/servo/components/style/values/animated/effects.rs
@@ -99,21 +99,34 @@ where
     #[inline]
     fn add(&self, other: &Self) -> Result<Self, ()> {
         Ok(ShadowList(
             self.0.iter().cloned().chain(other.0.iter().cloned()).collect(),
         ))
     }
 }
 
-impl<S> ComputeSquaredDistance for ShadowList<S> {
+impl<S> ComputeSquaredDistance for ShadowList<S>
+where
+    S: ComputeSquaredDistance + ToAnimatedZero,
+{
     #[inline]
-    fn compute_squared_distance(&self, _other: &Self) -> Result<SquaredDistance, ()> {
-        // FIXME: This should be implemented.
-        Err(())
+    fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
+        use itertools::{EitherOrBoth, Itertools};
+
+        self.0.iter().zip_longest(other.0.iter()).map(|it| {
+            match it {
+                EitherOrBoth::Both(from, to) => {
+                    from.compute_squared_distance(to)
+                },
+                EitherOrBoth::Left(list) | EitherOrBoth::Right(list)=> {
+                    list.compute_squared_distance(&list.to_animated_zero()?)
+                },
+            }
+        }).sum()
     }
 }
 
 impl<S> ToAnimatedZero for ShadowList<S> {
     #[inline]
     fn to_animated_zero(&self) -> Result<Self, ()> {
         Ok(ShadowList(vec![]))
     }