servo: Merge #18102 - Implement distance for shadow list (from hiikezoe:compute-distance-for-shadow-list); r=boris

<!-- Please describe your changes on the following line: -->
https://bugzilla.mozilla.org/show_bug.cgi?id=1387973
---
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors

Source-Repo: https://github.com/servo/servo
Source-Revision: 846b6dcb0710e9343575621a1ddad97c0cd1952d

--HG--
extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear
extra : subtree_revision : d251b1226c17171274235271de50bb69adcfb92b
This commit is contained in:
Hiroyuki Ikezoe 2017-08-16 18:17:18 -05:00
Родитель 95c51b495b
Коммит 4ee6b9f9ef
1 изменённых файлов: 17 добавлений и 4 удалений

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

@ -104,11 +104,24 @@ where
}
}
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()
}
}