From 52ff5964e677526cc5a84f030c69ae76fa0da0cc Mon Sep 17 00:00:00 2001 From: +merlan #flirora Date: Tue, 24 Jun 2025 17:23:09 -0400 Subject: [PATCH] Make behavior match PDF backend behavior again --- crates/typst-library/src/visualize/gradient.rs | 12 +++++++++--- ...162-coincident-gradient-stops-export-png.png | Bin 520 -> 522 bytes 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/typst-library/src/visualize/gradient.rs b/crates/typst-library/src/visualize/gradient.rs index 20539197c..f61a60ee4 100644 --- a/crates/typst-library/src/visualize/gradient.rs +++ b/crates/typst-library/src/visualize/gradient.rs @@ -1287,13 +1287,19 @@ fn sample_stops(stops: &[(Color, Ratio)], mixing_space: ColorSpace, t: f64) -> C assert!(!stops.is_empty(), "Cannot sample from gradient with no stops"); let t = t.clamp(0.0, 1.0); - let j = stops.partition_point(|(_, ratio)| ratio.get() < t); + let mut j = stops.partition_point(|(_, ratio)| ratio.get() < t); if j == 0 { - return stops[0].0; + while stops.get(j + 1).is_some_and(|(_, r)| r.is_zero()) { + j += 1; + } + return stops[j].0; } if j == stops.len() { - return stops.last().unwrap().0; + while j > 0 && stops[j].1.is_one() { + j -= 1; + } + return stops[j].0; } let (col_0, pos_0) = stops[j - 1]; diff --git a/tests/ref/issue-6162-coincident-gradient-stops-export-png.png b/tests/ref/issue-6162-coincident-gradient-stops-export-png.png index 886ea195d7803623f0422d1c66e6edd2a1797c34..d269342c7c6678e525f62b7d85b080e2fcfd812d 100644 GIT binary patch delta 496 zcmV>0HLPn}i0I!Y! zv5Nq+hyb;O0k(k#xP1${c@VsH6uog5zik`AXdc33A;e!J#(!ES$5biFPAkesF3dnb z%0NuWKv%{;VZ=Xa!as4pKX|=9e!D(|xju@wK996Ml(IdUusxowJ)^5Vr>H%vraZ5t zJhP!Zx1Kz^oIAdmJHnSc#gseAkvq(eI?szb(ug|Mg*w=RIop3Z-h4UXcsb;CIp%RV z>1{adX*lj>IDheBH}hRL_EE-|M?f>}p9%R2| z0001TNklJQ3`N1P4+~`rreYo>_Q8}iDQQUO$oDFDSARE2TCVLo_xN8w z!C){L3zk delta 494 zcmVSq{bql(A z2Dp6zwt)b(gnt0DhybyR0I!Y!u95((l>n-k0H~V)rk((#p#Y<#0HLP^i_; zFc=I5gTY`h7@QckcO|LTXYWrZ7z_r3!C){L3