From fe1f4400693690b68db5a7ec0976ba998624a740 Mon Sep 17 00:00:00 2001 From: Laurenz Date: Fri, 30 Dec 2022 10:07:46 +0100 Subject: [PATCH] Clamp shape radii --- src/geom/rounded.rs | 5 +++-- tests/ref/visualize/shape-rounded.png | Bin 0 -> 769 bytes tests/typ/visualize/shape-rounded.typ | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 tests/ref/visualize/shape-rounded.png create mode 100644 tests/typ/visualize/shape-rounded.typ diff --git a/src/geom/rounded.rs b/src/geom/rounded.rs index 7a58dae2b..dbe21ac6f 100644 --- a/src/geom/rounded.rs +++ b/src/geom/rounded.rs @@ -52,6 +52,7 @@ fn stroke_segments( let mut connection = Connection::default(); let mut path = Path::new(); let mut always_continuous = true; + let max_radius = size.x.min(size.y) / 2.0; for side in [Side::Top, Side::Right, Side::Bottom, Side::Left] { let continuous = stroke.get(side) == stroke.get(side.next_cw()); @@ -62,8 +63,8 @@ fn stroke_segments( &mut path, side, size, - radius.get(side.start_corner()), - radius.get(side.end_corner()), + radius.get(side.start_corner()).clamp(Abs::zero(), max_radius), + radius.get(side.end_corner()).clamp(Abs::zero(), max_radius), connection, ); diff --git a/tests/ref/visualize/shape-rounded.png b/tests/ref/visualize/shape-rounded.png new file mode 100644 index 0000000000000000000000000000000000000000..ae8df178cdc15a3708f762676223d13e6818ff62 GIT binary patch literal 769 zcmeAS@N?(olHy`uVBq!ia0y~yU}OQZD>#4zgW;FUHy9Y0PI$UFhE&{od*|WCMFt|Q z4=y`iVk~2jbzr~1Sk@rh!nc9>&4ITJ)(cvuOc2^+fA99(Soc_t!rtq}b^9tU4ySV{ z-qAi_z;hUcxF6f=xF|3Qb~vyo2{dw`Fb@?A#%-RR-v4*sDwBXv-}~`)0*Q7a;r~~B zSN|T>^1POJ`@dIwQVm&WEqu@Y&a|4X$KH_jON8Zmw!-Um=dbgbHk_(sIh4shWxM}X zN!B-OD_FuAp8j=w&(jcSacIp%TRZpLOzamq7Q6jCAANws#81zOe+xI?EKx3P(S^}f zJ8#R}I_VoIgyd%MMmni!=E;pGb?SS=GpLpghRg`$5t^Y~! z(vul{O;;oS=7b#Esc^|LLtIzj-#L+V4VC7E#)hl@vI^4;oHoBY_u+S&kjr$frdBSg z8@Ur=7jZa0*fDS8#v zx3_$p)OkA1&f#O=tl3%{w_V>d=j~Qr>9sS(n-iGtt9ITh;;)&m^7^UwgO?$OY=>^| zpAfnz?nKq}ai zB$DxCyWTUMubZ=*eiKbe|175MKEB&N)-eAgq@7|i_xw2k&$CdlPBNNN3 z{v5cVa4O3(k>&lTcH8`S9~j@--}`O2`}XH&RlHk1Ngu5Hy5}w5b={5MZam1FKgWXQ zee80E7q#_!V&;6Ge!BnP>cnkznZ+;u=L`SK>iny`N;dwE+Mh{n9}kwKu58$}rg!E% tbBUjq8BtOaQu=c8VQEX00HK`|=j*+hEvvj$@C+zzd%F6$taD0e0szm6RbK!A literal 0 HcmV?d00001 diff --git a/tests/typ/visualize/shape-rounded.typ b/tests/typ/visualize/shape-rounded.typ new file mode 100644 index 000000000..862141ba6 --- /dev/null +++ b/tests/typ/visualize/shape-rounded.typ @@ -0,0 +1,6 @@ +// Test rounded rectangles and squares. + +--- +// Ensure that radius is clamped. +#rect(radius: -20pt) +#square(radius: 30pt)