diff --git a/crates/typst/src/visualize/shape.rs b/crates/typst/src/visualize/shape.rs index 4567739e9..e37e5f90c 100644 --- a/crates/typst/src/visualize/shape.rs +++ b/crates/typst/src/visualize/shape.rs @@ -1108,7 +1108,7 @@ impl ControlPoints { + 2.0 * (o.y - c_i.y).to_raw() * (c_i.y - c_o.y).to_raw(); let c = (c_i.x - c_o.x).to_raw().powi(2) + (c_i.y - c_o.y).to_raw().powi(2) - r.to_raw().powi(2); - let t = (-b + (b * b - 4.0 * a * c).sqrt()) / (2.0 * a); + let t = (-b + (b * b - 4.0 * a * c).max(0.0).sqrt()) / (2.0 * a); c_i + t * (o - c_i) } diff --git a/tests/ref/bugs/3700-deformed-stroke.png b/tests/ref/bugs/3700-deformed-stroke.png new file mode 100644 index 000000000..f1db28366 Binary files /dev/null and b/tests/ref/bugs/3700-deformed-stroke.png differ diff --git a/tests/typ/bugs/3700-deformed-stroke.typ b/tests/typ/bugs/3700-deformed-stroke.typ new file mode 100644 index 000000000..7ca6ba6ba --- /dev/null +++ b/tests/typ/bugs/3700-deformed-stroke.typ @@ -0,0 +1,11 @@ +// Test shape fill & stroke for specific values that used to make the stroke +// deformed. +// https://github.com/typst/typst/issues/3700 + +--- +#rect( + radius: 1mm, + width: 100%, + height: 10pt, + stroke: (left: rgb("46b3c2") + 16.0mm), +) \ No newline at end of file