diff options
author | David Shin <dshin@mozilla.com> | 2022-06-24 13:18:17 +0000 |
---|---|---|
committer | Martin Robinson <mrobinson@igalia.com> | 2023-10-02 14:37:19 +0000 |
commit | 09fc10c5c20cfa95304d80f28ca44b5eb7cd2720 (patch) | |
tree | cd6e02b4e6405f00bfba06235ef603c0160699ce | |
parent | bb5de5833cdb79fa66cded04856673608e258a47 (diff) | |
download | servo-09fc10c5c20cfa95304d80f28ca44b5eb7cd2720.tar.gz servo-09fc10c5c20cfa95304d80f28ca44b5eb7cd2720.zip |
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
-rw-r--r-- | components/style/piecewise_linear.rs | 16 |
1 files 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<ValueType>) { 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 { |