mirror of
https://github.com/typst/typst
synced 2025-08-12 14:17:55 +08:00
Gradient::repeat Fix floating-point error in stop calculation
Fixes #5819
This commit is contained in:
parent
e4f8e57c53
commit
a985d1a29c
@ -582,12 +582,11 @@ impl Gradient {
|
|||||||
let mut stops = stops
|
let mut stops = stops
|
||||||
.iter()
|
.iter()
|
||||||
.map(move |&(color, offset)| {
|
.map(move |&(color, offset)| {
|
||||||
let t = i as f64 / n as f64;
|
|
||||||
let r = offset.get();
|
let r = offset.get();
|
||||||
if i % 2 == 1 && mirror {
|
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 {
|
} else {
|
||||||
(color, Ratio::new(t + r / n as f64))
|
(color, Ratio::new((i as f64 + r) / n as f64))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
@ -658,3 +658,9 @@ $ A = mat(
|
|||||||
height: 10pt,
|
height: 10pt,
|
||||||
fill: gradient.linear(violet, blue, space: cmyk)
|
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())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user