Bug 1356941 - ComputedDistance for IntermediateColor. r?boris draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Mon, 24 Apr 2017 15:03:43 +0900
changeset 566924 d091d501be41dd3ff93c290e07f5e4462b798c3b
parent 566923 036771108dd59f04f4ef886c715077bcd08fe160
child 566925 c4ecb69da33b92e23fb13d8f86f636bd97e9f271
push id55379
push userhikezoe@mozilla.com
push dateMon, 24 Apr 2017 06:04:15 +0000
reviewersboris
bugs1356941
milestone55.0a1
Bug 1356941 - ComputedDistance for IntermediateColor. r?boris MozReview-Commit-ID: 9jGqw4V5dqO
servo/components/style/properties/helpers/animated_properties.mako.rs
--- a/servo/components/style/properties/helpers/animated_properties.mako.rs
+++ b/servo/components/style/properties/helpers/animated_properties.mako.rs
@@ -2431,16 +2431,33 @@ impl ComputeDistance for IntermediateRGB
                                .fold(0.0f64, |n, (&a, &b)| {
                                    let diff = (a - b) as f64;
                                    n + diff * diff
                                });
         Ok(diff)
     }
 }
 
+impl ComputeDistance for IntermediateColor {
+    #[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, ()> {
+        match (*self, *other) {
+            (IntermediateColor::IntermediateRGBA(ref this), IntermediateColor::IntermediateRGBA(ref other)) => {
+                this.compute_squared_distance(other)
+            },
+            _ => Ok(0.0),
+        }
+    }
+}
+
 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, ()> {