mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
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
This commit is contained in:
parent
bb5de5833c
commit
09fc10c5c2
1 changed files with 5 additions and 11 deletions
|
@ -137,6 +137,7 @@ impl PiecewiseLinearFunctionBuilder {
|
||||||
fn create_entry(&mut self, y: ValueType, x: Option<ValueType>) {
|
fn create_entry(&mut self, y: ValueType, x: Option<ValueType>) {
|
||||||
let x = match x {
|
let x = match x {
|
||||||
Some(x) if x.is_finite() => 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 });
|
self.entries.push(BuildEntry { x: None, y });
|
||||||
return;
|
return;
|
||||||
|
@ -184,22 +185,15 @@ impl PiecewiseLinearFunctionBuilder {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// Guaranteed at least two elements.
|
// Guaranteed at least two elements.
|
||||||
// Start and end elements guaranteed to have defined x value.
|
// Start element's x value should've been assigned when the first value was pushed.
|
||||||
// Note(dshin): Spec asserts that start/end elements are supposed to have 0/1 assigned
|
debug_assert!(self.entries[0].x.is_some(), "Expected an entry with x defined!");
|
||||||
// respectively if their x values are undefined at this time; however, the spec does
|
// Spec asserts that if the last entry does not have an x value, it is assigned the largest seen x value.
|
||||||
// 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));
|
|
||||||
self.entries
|
self.entries
|
||||||
.last_mut()
|
.last_mut()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.x
|
.x
|
||||||
.get_or_insert(self.largest_x.filter(|x| x > &1.0).unwrap_or(1.0));
|
.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());
|
let mut result = Vec::with_capacity(self.entries.len());
|
||||||
result.push(PiecewiseLinearFunctionEntry {
|
result.push(PiecewiseLinearFunctionEntry {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue