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

@ -8,6 +8,7 @@ use properties::animated_properties::{Animatable, RepeatableListAnimatable};
use properties::longhands::background_size::computed_value::T as BackgroundSizeList;
use values::animated::{ToAnimatedValue, ToAnimatedZero};
use values::computed::length::LengthOrPercentageOrAuto;
use values::distance::{ComputeSquaredDistance, SquaredDistance};
use values::generics::background::BackgroundSize as GenericBackgroundSize;
/// A computed value for the `background-size` property.
@ -30,14 +31,11 @@ impl Animatable for BackgroundSize {
_ => Err(()),
}
}
}
impl ComputeSquaredDistance for BackgroundSize {
#[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
self.compute_squared_distance(other).map(|sd| sd.sqrt())
}
#[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
match (self, other) {
(
&GenericBackgroundSize::Explicit { width: self_width, height: self_height },