-
Notifications
You must be signed in to change notification settings - Fork 0
/
min.js
1 lines (1 loc) · 3.64 KB
/
min.js
1
self.curvedPolygon=function(n){"use strict";var e=Math.PI;function a(n){var e=n.inRadius,a=n.anglePerSide;return 2*e*Math.tan(a/2)}function i(n){var e=n.allPoints,a=n.borderRadius,i=n.alpha;return e.length?"M ".concat(e[0].join(" ")," ").concat(e.slice(1).map((function(n,e){return e%2==0?"A ".concat(a," ").concat(a," ").concat(i," 0 0 ").concat(n.join(" ")):"L ".concat(n.join(" "))})).join(" ")," z"):""}function r(n){for(var e=n.sideCount,a=n.radiusOfInnerPolygon,i=n.borderRadius,r=n.alpha,t=n.cx,d=void 0===t?0:t,s=n.cy,u=void 0===s?0:s,c=n.rotate,h=[],l=0;l<e;l++){var g=o([l*r+r/2-c,a],[l*r-c,i]),p=o([l*r+r/2-c,a],[(l+1)*r-c,i]);h.push(g,p)}var y=h.map((function(n){var e=n[0],a=n[1];return[e+d,a+u]}));return y}function t(n){return 2*e/n}function o(n,e){var a=n[0],i=n[1],r=e[0],t=e[1],o=i*Math.cos(a),d=t*Math.cos(r);return[i*Math.sin(a)+t*Math.sin(r),o+d]}return n.roundedPolygonByCircumRadius=function(n){var o=n.circumRadius,d=n.sideCount,s=void 0===d?3:d,u=n.borderRadius,c=void 0===u?0:u,h=n.cx,l=void 0===h?0:h,g=n.cy,p=void 0===g?0:g,y=n.rotate,v=void 0===y?0:y,R=[],f=[];if(s<3&&R.push("sideCount cannot be smaller than 3. There is no polygon with fewer sides than a triangle. No fun shapes here. :) Sorry!"),R.length)return{d:"",errors:R};var m=function(n){var e=n.circumRadius,a=t(n.sideCount),i=e*(2*Math.sin(a/2)),r=i/(2*Math.tan(a/2));return{sideLength:i,angleIntendedBySide:a,inRadius:r}}({sideCount:s,circumRadius:o}),b=m.sideLength,w=m.inRadius,M=m.angleIntendedBySide,L=a({inRadius:c,anglePerSide:M});return c>w&&f.push("borderRadius(".concat(c,") is larger than inradius(").concat(w,") of the polygon. The resulting shape won't really be a polygon.\n To get a proper curved polygon, either make the border radius smaller than ").concat(w," or make the sideLength larger than ").concat(L,".\n Ignore this warning if you intentionally want this curious pattern.\n ")),c<0&&f.push("You provided a negative borderRadius. Might produce an unexpected shape that is not a polygon. Ignore this warning if this was intentional."),{d:i({allPoints:r({sideCount:s,radiusOfInnerPolygon:o-c/Math.cos(M/2),borderRadius:c,alpha:M,rotate:v=v*e/180,cx:l,cy:p}),borderRadius:c,alpha:M}),meta:{circumRadius:o,inRadius:w,sideLength:b,borderRadius:c,minSideLength:L},warnings:f}},n.roundedPolygonBySideLength=function(n){var o=n.sideLength,d=n.sideCount,s=void 0===d?3:d,u=n.borderRadius,c=void 0===u?0:u,h=n.cx,l=void 0===h?0:h,g=n.cy,p=void 0===g?0:g,y=n.rotate,v=void 0===y?0:y,R=[],f=[];if(s<3&&R.push("sideCount cannot be smaller than 3. There is no polygon with fewer sides than a triangle. No fun shapes here. :) Sorry!"),R.length)return{d:"",errors:R};var m=function(n){var e=n.sideLength,a=t(n.sideCount),i=e/(2*Math.sin(a/2)),r=e/(2*Math.tan(a/2));return{circumRadius:i,angleIntendedBySide:a,inRadius:r}}({sideLength:o,sideCount:s}),b=m.circumRadius,w=m.angleIntendedBySide,M=m.inRadius,L=a({inRadius:c,anglePerSide:w});return c>M&&f.push("borderRadius(".concat(c,") is larger than inradius(").concat(M,") of the polygon. The resulting shape won't really be a polygon.\n To get a proper curved polygon, either make the border radius smaller than ").concat(M," or make the sideLength larger than ").concat(L,".\n Ignore this warning if you intentionally want this curious pattern.\n ")),c<0&&f.push("You provided a negative borderRadius. Might produce an unexpected shape that is not a polygon. Ignore this warning if this was intentional."),{d:i({allPoints:r({sideCount:s,radiusOfInnerPolygon:b-c/Math.cos(w/2),borderRadius:c,alpha:w,rotate:v=v*e/180,cx:l,cy:p}),borderRadius:c,alpha:w}),meta:{circumRadius:b,inRadius:M,sideLength:o,borderRadius:c,minSideLength:L},warnings:f}},n}({});