Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
frozolotl committed Mar 29, 2024
1 parent d60c8f4 commit 3e26a5f
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion crates/typst/src/layout/ratio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Ratio {

impl Debug for Ratio {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{:?}%", self.get())
write!(f, "{:?}%", self.get() * 100.0)
}
}

Expand Down
6 changes: 5 additions & 1 deletion crates/typst/src/visualize/gradient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,11 @@ fn sample_stops(stops: &[(Color, Ratio)], mixing_space: ColorSpace, t: f64) -> C

let (col_0, pos_0) = stops[low - 1];
let (col_1, pos_1) = stops[low];
let t = (t - pos_0.get()) / (pos_1.get() - pos_0.get());
let mut delta = pos_1.get() - pos_0.get();
if delta == 0.0 {
delta = 1.0;
}
let t = (t - pos_0.get()) / delta;

Color::mix_iter(
[WeightedColor::new(col_0, 1.0 - t), WeightedColor::new(col_1, t)],
Expand Down
Binary file added tests/ref/bugs/3826-gradient-div-zero.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions tests/typ/bugs/3826-gradient-div-zero.typ
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Issue #3826: Second stop at 0% in gradient crashes compiler in web app

---
#rect(width: 100%, fill: gradient.linear((red, 0%), (blue, 0%), (green, 100%)))

0 comments on commit 3e26a5f

Please sign in to comment.