Skip to content

Commit

Permalink
Rewrite compute_squared_distance for AnimatedFilterList.
Browse files Browse the repository at this point in the history
  • Loading branch information
BorisChiou committed Jul 28, 2017
1 parent 20e3508 commit 9028195
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 29 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions components/style/Cargo.toml
Expand Up @@ -44,6 +44,7 @@ euclid = "0.15"
fnv = "1.0"
heapsize = {version = "0.4", optional = true}
heapsize_derive = {version = "0.1", optional = true}
itertools = "0.5"
itoa = "0.3"
html5ever = {version = "0.18", optional = true}
lazy_static = "0.2"
Expand Down
1 change: 1 addition & 0 deletions components/style/lib.rs
Expand Up @@ -51,6 +51,7 @@ extern crate fnv;
#[cfg(feature = "gecko")] #[macro_use] pub mod gecko_string_cache;
#[cfg(feature = "servo")] extern crate heapsize;
#[cfg(feature = "servo")] #[macro_use] extern crate heapsize_derive;
extern crate itertools;
extern crate itoa;
#[cfg(feature = "servo")] #[macro_use] extern crate html5ever;
#[macro_use]
Expand Down
42 changes: 13 additions & 29 deletions components/style/properties/helpers/animated_properties.mako.rs
Expand Up @@ -3179,37 +3179,21 @@ impl Animatable for AnimatedFilterList {

#[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
let mut square_distance: f64 = 0.0;
let mut from_iter = self.0.iter();
let mut to_iter = other.0.iter();

let mut from = from_iter.next();
let mut to = to_iter.next();
while from.is_some() || to.is_some() {
let current_square_distance: f64 ;
if from.is_none() {
let none = try!(add_weighted_filter_function(to, to, 0.0, 0.0));
current_square_distance =
compute_filter_square_distance(&none, &(to.unwrap())).unwrap();

to = to_iter.next();
} else if to.is_none() {
let none = try!(add_weighted_filter_function(from, from, 0.0, 0.0));
current_square_distance =
compute_filter_square_distance(&none, &(from.unwrap())).unwrap();
use itertools::{EitherOrBoth, Itertools};

from = from_iter.next();
} else {
current_square_distance =
compute_filter_square_distance(&(from.unwrap()),
&(to.unwrap())).unwrap();

from = from_iter.next();
to = to_iter.next();
}
square_distance += current_square_distance;
let mut square_distance: f64 = 0.0;
for it in self.0.iter().zip_longest(other.0.iter()) {
square_distance += match it {
EitherOrBoth::Both(from, to) => {
compute_filter_square_distance(&from, &to)?
},
EitherOrBoth::Left(list) | EitherOrBoth::Right(list)=> {
let none = add_weighted_filter_function(Some(list), Some(list), 0.0, 0.0)?;
compute_filter_square_distance(&none, &list)?
},
};
}
Ok(square_distance.sqrt())
Ok(square_distance)
}
}

Expand Down

0 comments on commit 9028195

Please sign in to comment.