diff options
| author | +merlan #flirora <flirora@flirora.xyz> | 2025-02-12 07:38:40 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-12 12:38:40 +0000 |
| commit | 02cd43e27f2aafd7c332d7672a837e1b11cce120 (patch) | |
| tree | e6165259b163ef8364c45645f8b03d507f8e7e63 /crates/typst-library/src/visualize/gradient.rs | |
| parent | 83ad407d3ccff4a8de1e7ffe198bfed874f5c0c7 (diff) | |
`Gradient::repeat`: Fix floating-point error in stop calculation (#5837)
Diffstat (limited to 'crates/typst-library/src/visualize/gradient.rs')
| -rw-r--r-- | crates/typst-library/src/visualize/gradient.rs | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/crates/typst-library/src/visualize/gradient.rs b/crates/typst-library/src/visualize/gradient.rs index 431f07dd..d6530dd0 100644 --- a/crates/typst-library/src/visualize/gradient.rs +++ b/crates/typst-library/src/visualize/gradient.rs @@ -582,12 +582,11 @@ impl Gradient { let mut stops = stops .iter() .map(move |&(color, offset)| { - let t = i as f64 / n as f64; let r = offset.get(); if i % 2 == 1 && mirror { - (color, Ratio::new(t + (1.0 - r) / n as f64)) + (color, Ratio::new((i as f64 + 1.0 - r) / n as f64)) } else { - (color, Ratio::new(t + r / n as f64)) + (color, Ratio::new((i as f64 + r) / n as f64)) } }) .collect::<Vec<_>>(); @@ -1230,7 +1229,7 @@ fn process_stops(stops: &[Spanned<GradientStop>]) -> SourceResult<Vec<(Color, Ra }; if stop.get() < last_stop { - bail!(*span, "offsets must be in strictly monotonic order"); + bail!(*span, "offsets must be in monotonic order"); } last_stop = stop.get(); |
