Gradient::repeat Fix floating-point error in stop calculation

Fixes #5819
This commit is contained in:
+merlan #flirora 2025-02-07 18:23:25 -05:00
parent e4f8e57c53
commit a985d1a29c
2 changed files with 8 additions and 3 deletions

View File

@ -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<_>>();

View File

@ -658,3 +658,9 @@ $ A = mat(
height: 10pt,
fill: gradient.linear(violet, blue, space: cmyk)
)
--- issue-5819-gradient-repeat ---
#let my-gradient = gradient.linear(red, blue).repeat(5)
#let _ = gradient.linear(..my-gradient.stops())
#let my-gradient2 = gradient.linear(red, blue).repeat(5, mirror: true)
#let _ = gradient.linear(..my-gradient2.stops())