Bug 1356941 ComputedDistance for IntermediateRGBA. r?boris
MozReview-Commit-ID: 805TYcvvnMQ
--- a/servo/components/style/properties/helpers/animated_properties.mako.rs
+++ b/servo/components/style/properties/helpers/animated_properties.mako.rs
@@ -2320,16 +2320,41 @@ impl ComputeDistance for CSSParserColor
(CSSParserColor::RGBA(ref this), CSSParserColor::RGBA(ref other)) => {
this.compute_squared_distance(other)
},
_ => Ok(0.0),
}
}
}
+impl ComputeDistance for IntermediateRGBA {
+ #[inline]
+ fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
+ self.compute_squared_distance(other).map(|sq| sq.sqrt())
+ }
+
+ #[inline]
+ fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {
+ let start = [ self.alpha,
+ self.red * self.alpha,
+ self.green * self.alpha,
+ self.blue * self.alpha ];
+ let end = [ other.alpha,
+ other.red * other.alpha,
+ other.green * other.alpha,
+ other.blue * other.alpha ];
+ let diff = start.iter().zip(&end)
+ .fold(0.0f64, |n, (&a, &b)| {
+ let diff = (a - b) as f64;
+ n + diff * diff
+ });
+ Ok(diff)
+ }
+}
+
impl ComputeDistance for CalcLengthOrPercentage {
#[inline]
fn compute_distance(&self, other: &Self) -> Result<f64, ()> {
self.compute_squared_distance(other).map(|sq| sq.sqrt())
}
#[inline]
fn compute_squared_distance(&self, other: &Self) -> Result<f64, ()> {