Bug 1387973 - Implement distance for shadow list. r?boris
MozReview-Commit-ID: D0jd6Lm4fek
--- 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![]))
}