diff --git a/components/style/values/computed/mod.rs b/components/style/values/computed/mod.rs index 8695a99ae45..664fdcbbe86 100644 --- a/components/style/values/computed/mod.rs +++ b/components/style/values/computed/mod.rs @@ -369,7 +369,7 @@ impl From for CSSFloat { #[allow(missing_docs)] #[cfg_attr(feature = "servo", derive(HeapSizeOf))] -#[derive(Clone, Copy, Debug, PartialEq, ToCss)] +#[derive(Clone, ComputeSquaredDistance, Copy, Debug, PartialEq, ToCss)] pub enum NumberOrPercentage { Percentage(Percentage), Number(Number), diff --git a/components/style/values/generics/svg.rs b/components/style/values/generics/svg.rs index 631e6374e2d..c393f70dd70 100644 --- a/components/style/values/generics/svg.rs +++ b/components/style/values/generics/svg.rs @@ -8,8 +8,9 @@ use cssparser::Parser; use parser::{Parse, ParserContext}; use std::fmt; use style_traits::{ParseError, StyleParseError, ToCss}; +use values::computed::NumberOrPercentage; use values::computed::length::LengthOrPercentage; - +use values::distance::{ComputeSquaredDistance, SquaredDistance}; /// An SVG paint value /// @@ -100,8 +101,8 @@ impl Parse for SVGPaint | | for svg which allow unitless length. /// https://www.w3.org/TR/SVG11/painting.html#StrokeProperties #[cfg_attr(feature = "servo", derive(HeapSizeOf))] -#[derive(Clone, Copy, Debug, PartialEq, ToCss, HasViewportPercentage)] -#[derive(ToComputedValue, ToAnimatedValue, ComputeSquaredDistance)] +#[derive(Clone, Copy, Debug, HasViewportPercentage, PartialEq, ToAnimatedValue)] +#[derive(ToCss, ToComputedValue)] pub enum SvgLengthOrPercentageOrNumber { /// | LengthOrPercentage(LengthOrPercentageType), @@ -109,6 +110,42 @@ pub enum SvgLengthOrPercentageOrNumber { Number(NumberType), } +impl ComputeSquaredDistance for SvgLengthOrPercentageOrNumber + where + L: ComputeSquaredDistance + Copy + Into, + N: ComputeSquaredDistance + Copy + Into +{ + #[inline] + fn compute_squared_distance(&self, other: &Self) -> Result { + match (self, other) { + ( + &SvgLengthOrPercentageOrNumber::LengthOrPercentage(ref from), + &SvgLengthOrPercentageOrNumber::LengthOrPercentage(ref to) + ) => { + from.compute_squared_distance(to) + }, + ( + &SvgLengthOrPercentageOrNumber::Number(ref from), + &SvgLengthOrPercentageOrNumber::Number(ref to) + ) => { + from.compute_squared_distance(to) + }, + ( + &SvgLengthOrPercentageOrNumber::LengthOrPercentage(from), + &SvgLengthOrPercentageOrNumber::Number(to) + ) => { + from.into().compute_squared_distance(&to.into()) + }, + ( + &SvgLengthOrPercentageOrNumber::Number(from), + &SvgLengthOrPercentageOrNumber::LengthOrPercentage(to) + ) => { + from.into().compute_squared_distance(&to.into()) + }, + } + } +} + impl SvgLengthOrPercentageOrNumber where LengthOrPercentage: From, LengthOrPercentageType: Copy