mirror of
https://github.com/servo/servo.git
synced 2025-08-12 08:55:32 +01:00
Derive ComputeSquaredDistance
This commit is contained in:
parent
51b740033b
commit
277351da35
22 changed files with 162 additions and 391 deletions
|
@ -8,7 +8,6 @@ use euclid::Size2D;
|
|||
use properties::animated_properties::Animatable;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||
use values::generics::rect::Rect;
|
||||
|
||||
/// A generic value for a single side of a `border-image-width` property.
|
||||
|
@ -37,7 +36,7 @@ pub struct BorderImageSlice<NumberOrPercentage> {
|
|||
///
|
||||
/// https://drafts.csswg.org/css-backgrounds-3/#border-radius
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
|
||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
|
||||
pub struct BorderRadius<LengthOrPercentage> {
|
||||
/// The top left radius.
|
||||
pub top_left: BorderCornerRadius<LengthOrPercentage>,
|
||||
|
@ -49,9 +48,9 @@ pub struct BorderRadius<LengthOrPercentage> {
|
|||
pub bottom_left: BorderCornerRadius<LengthOrPercentage>,
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
|
||||
/// A generic value for `border-*-radius` longhand properties.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
#[derive(Clone, ComputeSquaredDistance, Copy, Debug, HasViewportPercentage, PartialEq, ToComputedValue)]
|
||||
pub struct BorderCornerRadius<L>(pub Size2D<L>);
|
||||
|
||||
impl<N> From<N> for BorderImageSlice<N>
|
||||
|
@ -132,20 +131,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<L> ComputeSquaredDistance for BorderRadius<L>
|
||||
where
|
||||
L: ComputeSquaredDistance + Copy,
|
||||
{
|
||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||
Ok(
|
||||
self.top_left.compute_squared_distance(&other.top_left)? +
|
||||
self.top_right.compute_squared_distance(&other.top_right)? +
|
||||
self.bottom_right.compute_squared_distance(&other.bottom_right)? +
|
||||
self.bottom_left.compute_squared_distance(&other.bottom_left)?,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl<L> ToCss for BorderRadius<L>
|
||||
where L: PartialEq + ToCss
|
||||
{
|
||||
|
@ -193,16 +178,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
impl<L> ComputeSquaredDistance for BorderCornerRadius<L>
|
||||
where
|
||||
L: ComputeSquaredDistance + Copy,
|
||||
{
|
||||
#[inline]
|
||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||
self.0.compute_squared_distance(&other.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl<L> ToCss for BorderCornerRadius<L>
|
||||
where L: ToCss,
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue