Introduce ComputeSquaredDistance

This allows us to merge the former Animatable methods compute_distance and
compute_squared_distance, reducing code size.
This commit is contained in:
Anthony Ramine 2017-08-12 17:36:52 +02:00
parent b14e68f915
commit 51b740033b
21 changed files with 641 additions and 551 deletions

View file

@ -16,9 +16,11 @@ use std::ascii::AsciiExt;
use std::fmt::{self, Debug};
use std::hash;
use style_traits::{ToCss, ParseError, StyleParseError};
use values::distance::{ComputeSquaredDistance, SquaredDistance};
pub mod animated;
pub mod computed;
pub mod distance;
pub mod generics;
pub mod specified;
@ -59,6 +61,25 @@ pub enum Either<A, B> {
Second(B),
}
impl<A, B> ComputeSquaredDistance for Either<A, B>
where
A: ComputeSquaredDistance,
B: ComputeSquaredDistance,
{
#[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
match (self, other) {
(&Either::First(ref this), &Either::First(ref other)) => {
this.compute_squared_distance(other)
},
(&Either::Second(ref this), &Either::Second(ref other)) => {
this.compute_squared_distance(other)
},
_ => Err(())
}
}
}
impl<A: Debug, B: Debug> Debug for Either<A, B> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {