svg.rs (1613B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ 4 5 //! Animation implementations for various SVG-related types. 6 7 use super::{Animate, Procedure}; 8 use crate::values::distance::{ComputeSquaredDistance, SquaredDistance}; 9 use crate::values::generics::svg::SVGStrokeDashArray; 10 11 /// <https://www.w3.org/TR/SVG11/painting.html#StrokeDasharrayProperty> 12 impl<L> Animate for SVGStrokeDashArray<L> 13 where 14 L: Clone + Animate, 15 { 16 #[inline] 17 fn animate(&self, other: &Self, procedure: Procedure) -> Result<Self, ()> { 18 if matches!(procedure, Procedure::Add | Procedure::Accumulate { .. }) { 19 // Non-additive. 20 return Err(()); 21 } 22 match (self, other) { 23 (&SVGStrokeDashArray::Values(ref this), &SVGStrokeDashArray::Values(ref other)) => { 24 Ok(SVGStrokeDashArray::Values( 25 super::lists::repeatable_list::animate(this, other, procedure)?, 26 )) 27 }, 28 _ => Err(()), 29 } 30 } 31 } 32 33 impl<L> ComputeSquaredDistance for SVGStrokeDashArray<L> 34 where 35 L: ComputeSquaredDistance, 36 { 37 #[inline] 38 fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> { 39 match (self, other) { 40 (&SVGStrokeDashArray::Values(ref this), &SVGStrokeDashArray::Values(ref other)) => { 41 super::lists::repeatable_list::squared_distance(this, other) 42 }, 43 _ => Err(()), 44 } 45 } 46 }