From 09fc10c5c20cfa95304d80f28ca44b5eb7cd2720 Mon Sep 17 00:00:00 2001 From: David Shin Date: Fri, 24 Jun 2022 13:18:17 +0000 Subject: [PATCH] style: `linear(...)` Easing: First linear entry should Get 0.0 assigned for input if not specified Previously, had the smallest input value over all entries was assigned. However, that does not match the behaviour of `linear-gradient(...)`, which this easing function is modeled after. Differential Revision: https://phabricator.services.mozilla.com/D149916 --- components/style/piecewise_linear.rs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/components/style/piecewise_linear.rs b/components/style/piecewise_linear.rs index 61bb6e31837..f833d6350ea 100644 --- a/components/style/piecewise_linear.rs +++ b/components/style/piecewise_linear.rs @@ -137,6 +137,7 @@ impl PiecewiseLinearFunctionBuilder { fn create_entry(&mut self, y: ValueType, x: Option) { let x = match x { Some(x) if x.is_finite() => x, + _ if self.entries.is_empty() => 0.0, // First x is 0 if not specified (Or not finite) _ => { self.entries.push(BuildEntry { x: None, y }); return; @@ -184,22 +185,15 @@ impl PiecewiseLinearFunctionBuilder { }; } // Guaranteed at least two elements. - // Start and end elements guaranteed to have defined x value. - // Note(dshin): Spec asserts that start/end elements are supposed to have 0/1 assigned - // respectively if their x values are undefined at this time; however, the spec does - // not disallow negative/100%+ inputs, and inputs like `linear(0, 0.1 -10%, 0.9 110%, 1.0)` - // would break the assumption that the x values in the list increase monotonically. - // Otherwise, we still want 0/1 assigned to the start/end values regardless of - // adjacent x values (i.e. `linear(0, 0.1 10%, 0.9 90%, 1.0)` == - // `linear(0 0%, 0.1 10%, 0.9 90%, 1.0)` != `linear(0 10%, 0.1 10%, 0.9 90%, 1.0 90%)`) - self.entries[0] - .x - .get_or_insert(self.smallest_x.filter(|x| x < &0.0).unwrap_or(0.0)); + // Start element's x value should've been assigned when the first value was pushed. + debug_assert!(self.entries[0].x.is_some(), "Expected an entry with x defined!"); + // Spec asserts that if the last entry does not have an x value, it is assigned the largest seen x value. self.entries .last_mut() .unwrap() .x .get_or_insert(self.largest_x.filter(|x| x > &1.0).unwrap_or(1.0)); + // Now we have at least two elements with x values, with start & end x values guaranteed. let mut result = Vec::with_capacity(self.entries.len()); result.push(PiecewiseLinearFunctionEntry {