From 84ed4c9b9d2cece669bf4eee7eeb3ae5fecf4003 Mon Sep 17 00:00:00 2001 From: treeform Date: Thu, 17 Mar 2022 07:50:58 -0700 Subject: [PATCH] Fix for #393 and other polygon improvements. --- src/pixie/paths.nim | 11 ++++++----- tests/paths/polygon3.png | Bin 0 -> 771 bytes tests/paths/polygon4.png | Bin 0 -> 434 bytes tests/paths/polygon5.png | Bin 0 -> 902 bytes tests/paths/polygon6.png | Bin 0 -> 737 bytes tests/paths/polygon7.png | Bin 0 -> 972 bytes tests/paths/polygon8.png | Bin 0 -> 1012 bytes tests/test_paths.nim | 9 +++++++++ 8 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 tests/paths/polygon3.png create mode 100644 tests/paths/polygon4.png create mode 100644 tests/paths/polygon5.png create mode 100644 tests/paths/polygon6.png create mode 100644 tests/paths/polygon7.png create mode 100644 tests/paths/polygon8.png diff --git a/src/pixie/paths.nim b/src/pixie/paths.nim index deb3d4d..97efba7 100644 --- a/src/pixie/paths.nim +++ b/src/pixie/paths.nim @@ -632,13 +632,14 @@ proc polygon*( path: Path, x, y, size: float32, sides: int ) {.raises: [PixieError].} = ## Adds an n-sided regular polygon at (x, y) with the parameter size. - if sides <= 0: + ## Polygons "face" north. + if sides <= 2: raise newException(PixieError, "Invalid polygon sides value") - path.moveTo(x + size * cos(0.0), y + size * sin(0.0)) - for side in 0 .. sides: + path.moveTo(x + size * sin(0.0), y - size * cos(0.0)) + for side in 1 .. sides: path.lineTo( - x + size * cos(side.float32 * 2.0 * PI / sides.float32), - y + size * sin(side.float32 * 2.0 * PI / sides.float32) + x + size * sin(side.float32 * 2.0 * PI / sides.float32), + y - size * cos(side.float32 * 2.0 * PI / sides.float32) ) proc polygon*( diff --git a/tests/paths/polygon3.png b/tests/paths/polygon3.png new file mode 100644 index 0000000000000000000000000000000000000000..0fdd5aa2cdfe2417c336f67dbcd8c061b9a7e8b6 GIT binary patch literal 771 zcmV+e1N{7nP)|>Ng0%|4E?IlUt;n2+-p?b};h!2|_@@N>-L_ zvbFG?w(5hGT-;8G9lE10pdclQ0Usfxv;2|vYJ-%FcF<&ByhuOV;3U1LtHH6E7uAIx zD2ZKZt)*siKWi%;P?D2-oygX&kDR3j7)krBU_G(B_@%y9f|2xRSX?kN$u=qwl1#tl zN=x3IbM55lORR~t?kFoU=-x`vmmE0W7_{cqOk)8?Thct);z`No7d#aRZOPd^-iVgP z``!|Ot|T@b;1V(;^IT1ct|Xu2+XL<6d{Km^WXAiNDmwby8A=U-Y9w zPjck2IH&FXGx0$qT9RS4WlJFzY_{*T0RXOxzLfshu~XX(r^13Bp0xZyDVLn-CEz$r0002ovPDHLkV1k*l BWy1gf literal 0 HcmV?d00001 diff --git a/tests/paths/polygon4.png b/tests/paths/polygon4.png new file mode 100644 index 0000000000000000000000000000000000000000..d761edc95be4542bebe32722edabc5032512b376 GIT binary patch literal 434 zcmeAS@N?(olHy`uVBq!ia0vp^DIm-NBp5+TOM1H6Fge2vDw!oMt zHyOG*UE0=Hc;wvZYE5ZdZQ+qOqpMNlaB!B3^t2$QsSh2j)B9Khnlv-Syx@sdeOR|34+3Y;}KFBul8x>dQYYVo*!Vv2yJ%=+yWtBXr|+E3KI z)LNf^@v_sBwMX2VOr{<=F=5&yNzF?ELCWqMCP_0jb{U8?iKKe4Xk5C`u{L9|gU?a} zts_BNi(Pn@nq(~r$vW)7b<{w{MXN7S(P<+Ozo+PVgNZJNyyBdq*EdXb*vKni8C1ip zz|UpCQM6ouS<#%!NaE9C17@XoE)$JU3j>&yv-i(ATpccY|IjMiUAIeRGEF#;!Yxhj ZiuI1;Te9X(3i<|$3{O`-mvv4FO#q?Ls-*w` literal 0 HcmV?d00001 diff --git a/tests/paths/polygon5.png b/tests/paths/polygon5.png new file mode 100644 index 0000000000000000000000000000000000000000..029669f923595020ea7c684d447fce1539e18303 GIT binary patch literal 902 zcmV;119|+3P)EuhN)(g{fkgO$EG(>A)?(^P+`E3=yXTylA(0;D_fYGc|Cyh2VD|26W2=CY zNTJ3hg&LO>YFtvNaY>=ZCB^?aE=O~2=d{#0nDj}~yqT$I-udJ#lHM$1X=z@IX>B;9)u-VkP2UhgPeAs$-Q z_v5f0m`&~(?8+b~p)Usveq~_Ef!CbN0h3tNI}BA|Nm3b<)-~0VCgJe#U!(Pcft(>&s&iqCSg&Qk68j->qkPUWT$TCmDwuyY*y503}k{_jXzdp=qEN!YlL3(vuqtOVSXtOQCTg&LO>YFtvNaY>=ZC50N76lz>j ctjf6l0^k_bh?oiw-T(jq07*qoM6N<$f-BLccK`qY literal 0 HcmV?d00001 diff --git a/tests/paths/polygon6.png b/tests/paths/polygon6.png new file mode 100644 index 0000000000000000000000000000000000000000..c16c400c321c54864ad69538edd9ebfd4b4e45d3 GIT binary patch literal 737 zcmV<70v`Q|P)I#Ua9kufE)pvS!g(7i>edWg9<;|Y4xG_{gT~Zyq=E(2pIJWiuYw4-pRTEA@|Rd@+Q zQF0{QTx#B;bdNVNYQ88$NmAE$+AdmcZ#ghBCAwikLE^Y^v&yt;iK^q(?~+S13`>da z+@nTpaR!%vVKAK;NU)OVkye{zIRM!9wZ~(b0gha$+}j z60Ir5>EF;lSA01KF40a!+$FiktSG7X{~B7vo2A*(w9t}B0Op?cZFXXBSHMgCj-+IiN&pgf zKh|59zn?oUN{e3$2|z56Y?K%BKQDPd6&$M={F`J+zwKG?%8o_!=+CVh64nxcWaQ~~ ztho}^yRBO*DiVOH+Y=33*@{}2_F^otrGjYanoXoO7I&O+oSE}~UI?NO_xEMy-t#}_$2}LFJ2R90 z0Cb5G`nr_R*QJEME+zDJDWR`RiJx;_DOa|4zfrmlrg|ltt4d;Hx1|rfQqrib%V4S5 z9j#4|&dD0?)ZR!UFA2=A-5KSc8kJ?ScTTvEM94~l3;xcVJAK&P%>2=gFVoLp)GMHL&DSla&(OOo~4kH%syC~8A>&WrWP98KT{QN#FBYOs?$Qen>>V=i%d^Hd5&pB zlIXIkwMM#i660#?f@dR>?-6`S+{wz7fvD9@V6rvl#gO}mf+tyW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