mirror of
https://github.com/servo/servo.git
synced 2025-08-13 09:25:32 +01:00
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:
parent
b14e68f915
commit
51b740033b
21 changed files with 641 additions and 551 deletions
|
@ -10,6 +10,7 @@ use parser::ParserContext;
|
|||
use properties::animated_properties::Animatable;
|
||||
use style_traits::ParseError;
|
||||
use values::animated::ToAnimatedZero;
|
||||
use values::distance::{ComputeSquaredDistance, SquaredDistance};
|
||||
|
||||
/// A generic value for the `initial-letter` property.
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
|
@ -84,13 +85,18 @@ impl<Value> Animatable for Spacing<Value>
|
|||
let other = other.value().unwrap_or(&zero);
|
||||
this.add_weighted(other, self_portion, other_portion).map(Spacing::Value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<V> ComputeSquaredDistance for Spacing<V>
|
||||
where
|
||||
V: ComputeSquaredDistance + From<Au>,
|
||||
{
|
||||
#[inline]
|
||||
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
|
||||
let zero = Value::from(Au(0));
|
||||
fn compute_squared_distance(&self, other: &Self) -> Result<SquaredDistance, ()> {
|
||||
let zero = V::from(Au(0));
|
||||
let this = self.value().unwrap_or(&zero);
|
||||
let other = other.value().unwrap_or(&zero);
|
||||
this.compute_distance(other)
|
||||
this.compute_squared_distance(other)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue