Derive ComputeSquaredDistance

This commit is contained in:
Anthony Ramine 2017-08-13 00:50:36 +02:00
parent 51b740033b
commit 277351da35
22 changed files with 162 additions and 391 deletions

View file

@ -9,11 +9,10 @@ use parser::{Parse, ParserContext};
use properties::animated_properties::Animatable;
use std::fmt;
use style_traits::{ToCss, ParseError};
use values::distance::{ComputeSquaredDistance, SquaredDistance};
/// A CSS value made of four components, where its `ToCss` impl will try to
/// serialize as few components as possible, like for example in `border-width`.
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct Rect<T>(pub T, pub T, pub T, pub T);
@ -71,21 +70,6 @@ where
}
}
impl<L> ComputeSquaredDistance for Rect<L>
where
L: ComputeSquaredDistance,
{
#[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
Ok(
self.0.compute_squared_distance(&other.0)? +
self.1.compute_squared_distance(&other.1)? +
self.2.compute_squared_distance(&other.2)? +
self.3.compute_squared_distance(&other.3)?,
)
}
}
impl<T> From<T> for Rect<T>
where T: Clone
{