From 5de36f7b97c237ad0fc4a0b4ccecd7adcb43181b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Cruz?= <103905440+Tom4sCruz@users.noreply.github.com> Date: Sat, 6 Apr 2024 12:21:38 +0100 Subject: [PATCH] Deformed stroke for some length values fix (#3860) --- crates/typst/src/visualize/shape.rs | 2 +- tests/ref/bugs/3700-deformed-stroke.png | Bin 0 -> 144 bytes tests/typ/bugs/3700-deformed-stroke.typ | 11 +++++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/ref/bugs/3700-deformed-stroke.png create mode 100644 tests/typ/bugs/3700-deformed-stroke.typ 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 0000000000000000000000000000000000000000..f1db2836674b7c5a1046c27051479b0f6f76b4f4 GIT binary patch literal 144 zcmeAS@N?(olHy`uVBq!ia0y~yU}OQZ1DKeBWE0=xGeC+bz$e5NNdN!;|H7O1ZkrF4 zd+cWf^6foc978H@y}hxJmq9^*#gS*$wR;!p)f4Tk0Azh@0+RE%mN$PYWte%P;ldQl)+V4)44$rjF6*2UngEi*GSUD5 literal 0 HcmV?d00001 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