forked from levskaya/polyhedronisme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
polyhedronisme.min.js
1 lines (1 loc) · 40 KB
/
polyhedronisme.min.js
1
(function(){var r,aW,aC,bq,ao,a7,T,Y,X,aJ,ap,a3,aV,aM,h,p,az,q,ag,a5,A,z,aK,bj,a0,O,aB,bk,bo,g,o,bm,aP,M,bl,a8,J,aA,af,bf,ak,v,bw,ar,E,aE,S,aL,ax,ad,w,aD,bb,an,K,a4,aG,Q,k,am,x,a6,bv,i,ba,aN,F,G,aO,ae,aw,e,n,L,a9,aY,aI,d,s,bu,al,aq,av,bi,H,aZ,R,ah,bs,y,N,B,br,V,bg,aj,aS,bc,U,aa,t,bt,aQ,be,bd,aF,P,I,u,C,j,Z,aT,aH,at,au,a2,aU,aR,W,a1,bh,b,l,ab,D,f,ai,a,ac,m,bp,ay,aX,c,bn;aQ=Math.random;Z=Math.round;an=Math.floor;W=Math.sqrt;a2=Math.sin;J=Math.cos;b=Math.tan;O=Math.asin;a5=Math.acos;aB=Math.atan;bc=Math.pow;ag=Math.abs;aM=Math.PI;T=Math.LN10;e=Math.log;bc=Math.pow;n=function(bx){return e(bx)/T};au=function(bz,by){var bx;bx=bc(10,n(bz)-an(n(bz)));return""+(Z(bx*(by-1)))};M=function(bz){var by,bx;if((bz==null)||typeof bz!=="object"){return bz}bx=new bz.constructor();for(by in bz){bx[by]=M(bz[by])}return bx};be=function(by){var bx;bx=an(aQ()*by.length);return by[bx]};d=function(by,bx){return[by*bx[0],by*bx[1],by*bx[2]]};q=function(by,bx){return[by[0]*bx[0],by[1]*bx[1],by[2]*bx[2]]};A=function(by,bx){return[by[0]+bx[0],by[1]+bx[1],by[2]+bx[2]]};bh=function(by,bx){return[by[0]-bx[0],by[1]-bx[1],by[2]-bx[2]]};E=function(by,bx){return by[0]*bx[0]+by[1]*bx[1]+by[2]*bx[2]};aA=function(by,bx){return[by[1]*bx[2]-by[2]*bx[1],by[2]*bx[0]-by[0]*bx[2],by[0]*bx[1]-by[1]*bx[0]]};L=function(bx){return W(E(bx,bx))};a9=function(bx){return E(bx,bx)};bp=function(bx){return d(1/W(a9(bx)),bx)};aY=function(by,bx){return d(1/2,A(by,bx))};m=function(bz,by,bx){return[(1-bx)*bz[0]+bx*by[0],(1-bx)*bz[1]+bx*by[1],(1-bx)*bz[2]+bx*by[2]]};av=function(by,bx){return m(by,bx,1/3)};aF=function(bx){return d(1/a9(bx),bx)};l=function(bz,by){var bx;bx=bh(by,bz);return bh(bz,d(E(bx,bz)/a9(bx),bx))};ax=function(by,bx){return W(a9(l(by,bx)))};aw=function(bE,bD,bB){var bC,bz,by,bx,bA;bz=bh(bD,bE);bC=bh(bE,bB);by=a9(bz);bA=-E(bC,bz)/by;if(bA<=0){return a9(bC)}else{if(bA>=1){bx=a9(bh(bD,bB))}}bx=a9(aA(bz,bC))/by;return bx};aZ=function(bB,bA,bz){var by,bx;by=bh(bA,bB);bx=bh(bz,bA);return aA(by,bx)};G=function(bD,bC,bA){var by,bE,bB,bz,bx,bH,bG,bF,bI;for(by=0,bE=bD.length;by<bE;by++){bH=bD[by];for(bx=0,bB=bC.length;bx<bB;bx++){bG=bC[bx];if(bH===bG){for(bI=0,bz=bA.length;bI<bz;bI++){bF=bA[bI];if(bH===bF){return bH}}}}}return null};bo=function(bB){var bA,by,bx,bz;bA=[0,0,0];for(by=0,bx=bB.length;by<bx;by++){bz=bB[by];bA=A(bA,bz)}return d(1/bB.length,bA)};al=function(bA){var bz,bB,bx,by,bC,bF,bE,bD;bx=[0,0,0];by=bA.slice(-2),bF=by[0],bE=by[1];for(bz=0,bB=bA.length;bz<bB;bz++){bD=bA[bz];bx=A(bx,aZ(bF,bE,bD));bC=[bE,bD],bF=bC[0],bE=bC[1]}return bp(bx)};bl=function(bA){var bx,bz,bB,by,bC,bF,bE,bD;bx=0;by=bA.slice(0,2),bF=by[0],bE=by[1];bC=bA.slice(2);for(bz=0,bB=bC.length;bz<bB;bz++){bD=bC[bz];bx+=L(aA(bh(bE,bF),bh(bD,bF)));bE=bD}return bx};aD=function(bE){var bC,bz,bF,bB,bA,bx,by,bG,bD,bM,bL,bK,bJ,bH,bI;bC=[];by=bE.slice(0,2),bK=by[0],bJ=by[1];bG=bE.slice(2);for(bz=0,bF=bG.length;bz<bF;bz++){bH=bG[bz];bC.push(L(aA(bh(bJ,bK),bh(bH,bK))));bJ=bH}bC.sort(function(bO,bN){return bO-bN});bM="";for(bx=0,bB=bC.length;bx<bB;bx++){bI=bC[bx];bM+=au(bI,2)}bD=bC.reverse();for(bL=0,bA=bD.length;bL<bA;bL++){bI=bD[bL];bM+=au(bI,2)}return bM};aa=function(bE){var bD,bz,bC,by,bx,bB,bA,bG,bF;bA=M(bE);bF=bE[0];bA=_.map(bA,function(bH){return bH-bF});by=al(bE);bD=bp(bo(bE));bx=aA(by,bD);bB=[];for(bz=0,bC=bA.length;bz<bC;bz++){bG=bA[bz];bB.push([E(by,bG),E(bx,bG)])}return bB};a8=function(bA){var bz,by,bx,bB;bx=new Array(bA.length);for(bz=by=0,bB=bA.length;0<=bB?by<bB:by>bB;bz=0<=bB?++by:--by){bx[bz]=bA[bz].slice(0)}return bx};s=function(by,bx){return[by[0][0]*bx[0]+by[0][1]*bx[1]+by[0][2]*bx[2],by[1][0]*bx[0]+by[1][1]*bx[1]+by[1][2]*bx[2],by[2][0]*bx[0]+by[2][1]*bx[1]+by[2][2]*bx[2]]};aI=function(bx,by){return[[bx[0][0]*by[0][0]+bx[0][1]*by[1][0]+bx[0][2]*by[2][0],bx[0][0]*by[0][1]+bx[0][1]*by[1][1]+bx[0][2]*by[2][1],bx[0][0]*by[0][2]+bx[0][1]*by[1][2]+bx[0][2]*by[2][2]],[bx[1][0]*by[0][0]+bx[1][1]*by[1][0]+bx[1][2]*by[2][0],bx[1][0]*by[0][1]+bx[1][1]*by[1][1]+bx[1][2]*by[2][1],bx[1][0]*by[0][2]+bx[1][1]*by[1][2]+bx[1][2]*by[2][2]],[bx[2][0]*by[0][0]+bx[2][1]*by[1][0]+bx[2][2]*by[2][0],bx[2][0]*by[0][1]+bx[2][1]*by[1][1]+bx[2][2]*by[2][1],bx[2][0]*by[0][2]+bx[2][1]*by[1][2]+bx[2][2]*by[2][2]]]};w=[[1,0,0],[0,1,0],[0,0,1]];j=function(bB,bz,bA){var bC,by,bx;bC=[[J(bB),-1*a2(bB),0],[a2(bB),J(bB),0],[0,0,1]];bx=[[J(bz),0,-1*a2(bz)],[0,1,0],[a2(bz),0,J(bz)]];by=[[1,0,0],[0,J(bA),-1*a2(bA)],[0,a2(bA),J(bA)]];return aI(by,aI(bx,bC))};aX=function(bB,bK,bJ,bF){var bD,by,bA,bz,bE,bI,bH,bx,bG,bC;bB/=2;bI=a2(bB);bD=J(bB);bH=bI*bI;by=L([bK,bJ,bF]);if(by===0){bz=[0,0,1],bK=bz[0],bJ=bz[1],bF=bz[2]}if(by!==1){bE=bp([bK,bJ,bF]),bK=bE[0],bJ=bE[1],bF=bE[2]}if(bK===1&&bJ===0&&bF===0){bA=[[1,0,0],[0,1-2*bH,2*bI*bD],[0,-2*bI*bD,1-2*bH]]}else{if(bK===0&&bJ===1&&bF===0){bA=[[1-2*bH,0,-2*bI*bD],[0,1,0],[2*bI*bD,0,1-2*bH]]}else{if(bK===0&&bJ===0&&bF===1){bA=[[1-2*bH,2*bI*bD,0],[-2*bI*bD,1-2*bH,0],[0,0,1]]}else{bx=bK*bK;bG=bJ*bJ;bC=bF*bF;bA=[[1-2*(bG+bC)*bH,2*(bK*bJ*bH+bF*bI*bD),2*(bK*bF*bH-bJ*bI*bD)],[2*(bJ*bK*bH-bF*bI*bD),1-2*(bC+bx)*bH,2*(bJ*bF*bH+bK*bI*bD)],[2*(bF*bK*bH+bJ*bI*bD),2*(bF*bJ*bH-bK*bI*bD),1-2*(bx+bG)*bH]]}}}return bA};y=function(bz,by,bA,bD,bx){var bB,bC;bC=(by*bD-bA)/(1-bD);bB=bx*bD/(1-bD);return[bB*bz[0]/(bz[2]+bC),bB*bz[1]/(bz[2]+bC)]};aO=function(bE,bB,bH,bF,bL,bA,bz,by){var bK,bx,bG,bC,bI,bN,bP,bD,bJ,bM,bO;bJ=(bL*bz-bA)/(1-bz);bK=by*bz/(1-bz);bG=bE-bH;bN=bB-bF;bx=bK*bK;bM=bJ*bJ;bC=bG*bG;bP=bN*bN;bI=(2*bK*bG*bJ+W(4*bx*bC*bM+4*bC*(bx+bC+bP)*(1-bM)))/(2*(bx+bC+bP));bD=(bK*bN*bJ)/(bx+bC+bP)+(bN*W(4*bx*bM+4*(bx+bC+bP)*(1-bM)))/(2*(bx+bC+bP));bO=W(1-bI*bI-bD*bD);return[bI,bD,bO]};aG=function(bz,by){var bA,bx;bx=aA(bz,by);bA=a5(E(bz,by));return aX(-1*bA,bx[0],bx[1],bx[2])};bb=function(bA){var bz,by,bx,bC,bB;bz=[];bC=bA.slice(-1)[0];for(by=0,bx=bA.length;by<bx;by++){bB=bA[by];bz.push([bC,bB]);bC=bB}return bz};c=function(bx){var bD,bC,bA,bE,bB,by,bz,bG,bF;bF=[];bz=bx.face;for(bC=bA=0,bE=bz.length;bA<bE;bC=++bA){bD=bz[bC];for(by=0,bB=bD.length;by<bB;by++){bG=bD[by];bF[bG]=bx.face_class[bC]}}return bF};aT=["#ff7777","#dddddd","#889999","#fff0e5","#aa3333","#ff0000","#ffffff","#aaaaaa"];bv=function(by){var bx;if(by[0]==="#"){by=by.slice(1)}if(by.length===3){bx=by.split("").map(function(bz){return parseInt(bz+bz,16)/255})}else{bx=by.match(/.{2}/g).map(function(bz){return parseInt(bz,16)/255})}return bx};a3=aT;ah=function(bx){if(bx<a3.length){return bv(a3[bx])}else{return bv(a3[a3.length-1])}};R=function(bx){var bG,bz,bD,bB,bF,bA,bC,by,bE;bx.face_class=[];bD={};bz=function(bH,bK){var bI,bJ;bJ=Z(100*bH);if(bJ in bK){return bK[bJ]}else{bI=_.toArray(bK).length;bK[bJ]=bI;return bI}};by=bx.face;for(bA=0,bC=by.length;bA<bC;bA++){bB=by[bA];if(ao==="area"){bF=(function(){var bH,bJ,bI;bI=[];for(bJ=0,bH=bB.length;bJ<bH;bJ++){bE=bB[bJ];bI.push(bx.xyz[bE])}return bI})();bG=bz(bl(bF),bD)}else{if(ao==="signature"){bF=(function(){var bH,bJ,bI;bI=[];for(bJ=0,bH=bB.length;bJ<bH;bJ++){bE=bB[bJ];bI.push(bx.xyz[bE])}return bI})();bG=bz(aD(bF),bD)}else{bG=bB.length-3}}bx.face_class.push(bG)}console.log(_.toArray(bD).length+" face classes");return bx};aU=function(bx){var by,bG,bB,bF,bH,bC,bA,bD,bz,bE;by=bx.centers();bF=bx.normals();bC=[0,0,(B*N-br)/(1-N)];bH=function(bJ,bI){return -E(bh(bC,bJ[0]),bJ[1])*E(bh(bI[0],bJ[0]),bJ[1])};bz=function(bJ,bI){return bJ[0][2]-bI[0][2]};bE=_.zip(by,bF,(function(){bD=[];for(var bI=0,bJ=bx.face.length;0<=bJ?bI<bJ:bI>bJ;0<=bJ?bI++:bI--){bD.push(bI)}return bD}).apply(this)).sort(bz).map(function(bI){return bI[2]});bx.face=(function(){var bI,bK,bJ;bJ=[];for(bK=0,bI=bE.length;bK<bI;bK++){bG=bE[bK];bJ.push(bx.face[bG])}return bJ})();return bx.face_class=(function(){var bI,bK,bJ;bJ=[];for(bK=0,bI=bE.length;bK<bI;bK++){bG=bE[bK];bJ.push(bx.face_class[bG])}return bJ})()};aS=(function(){function bx(bA,by,bz){this.face=by||new Array();this.xyz=bA||new Array();this.name=bz||"null polyhedron"}bx.prototype.data=function(){var by;by=this.face.length+this.xyz.length-2;return this.face.length+" faces, "+by+" edges, "+this.xyz.length+" vertices"};bx.prototype.moreData=function(){return"min. edge length "+(this.minEdgeLength().toPrecision(2))+"; min. face radius "+(this.minFaceRadius().toPrecision(2))};bx.prototype.edges=function(){var bI,bF,bH,bG,by,bE,bC,bA,bD,bB,bz,bJ;bE={};bJ=[];bF=_.map(this.face,bb);for(bA=0,bD=bF.length;bA<bD;bA++){by=bF[bA];for(bz=0,bB=by.length;bz<bB;bz++){bG=by[bz];if(bG[0]<bG[1]){bI=bG[0],bH=bG[1]}else{bH=bG[0],bI=bG[1]}bE[bI+"~"+bH]=bG}}for(bC in bE){bG=bE[bC];bJ.push(bG)}return bJ};bx.prototype.minEdgeLength=function(){var bC,bD,bz,by,bA,bB;bA=Number.MAX_VALUE;bB=this.edges();for(bz=0,by=bB.length;bz<by;bz++){bD=bB[bz];bC=a9(bh(this.xyz[bD[0]],this.xyz[bD[1]]));if(bC<bA){bA=bC}}return W(bA)};bx.prototype.minFaceRadius=function(){var bH,bA,bC,bG,bD,bB,bE,bJ,bI,by,bz,bF;bJ=Number.MAX_VALUE;bI=this.face.length;bA=this.centers();for(bD=bB=0,bz=bI;0<=bz?bB<bz:bB>bz;bD=0<=bz?++bB:--bB){bH=bA[bD];bF=bb(this.face[bD]);for(by=0,bE=bF.length;by<bE;by++){bG=bF[by];bC=aw(this.xyz[bG[0]],this.xyz[bG[1]],bH);if(bC<bJ){bJ=bC}}}return W(bJ)};bx.prototype.centers=function(){var bD,bE,bB,bA,bF,bC,by,bz,bG;bD=[];bz=this.face;for(bA=0,bF=bz.length;bA<bF;bA++){bE=bz[bA];bB=[0,0,0];for(by=0,bC=bE.length;by<bC;by++){bG=bE[by];bB=A(bB,this.xyz[bG])}bD.push(d(1/bE.length,bB))}return bD};bx.prototype.normals=function(){var bC,bz,by,bD,bB,bA;bD=[];bB=this.face;for(bz=0,by=bB.length;bz<by;bz++){bC=bB[bz];bD.push(al((function(){var bE,bG,bF;bF=[];for(bG=0,bE=bC.length;bG<bE;bG++){bA=bC[bG];bF.push(this.xyz[bA])}return bF}).call(this)))}return bD};bx.prototype.toOBJ=function(){var bI,bF,bB,bJ,bE,bD,bC,by,bz,bH,bA,bK,bG,bN,bM,bL;bH="#Produced by polyHédronisme http://levskaya.github.com/polyhedronisme\n";bH+="group "+this.name+"\n";bH+="#vertices\n";bA=this.xyz;for(bB=0,bJ=bA.length;bB<bJ;bB++){bM=bA[bB];bH+="v "+bM[0]+" "+bM[1]+" "+bM[2]+"\n"}bH+="#normal vector defs \n";bK=this.face;for(bz=0,bE=bK.length;bz<bE;bz++){bI=bK[bz];by=al((function(){var bO,bQ,bP;bQ=[];for(bP=0,bO=bI.length;bP<bO;bP++){bM=bI[bP];bQ.push(this.xyz[bM])}return bQ}).call(this));bH+="vn "+by[0]+" "+by[1]+" "+by[2]+"\n"}bH+="#face defs \n";bG=this.face;for(bF=bN=0,bD=bG.length;bN<bD;bF=++bN){bI=bG[bF];bH+="f ";for(bL=0,bC=bI.length;bL<bC;bL++){bM=bI[bL];bH+=(bM+1)+"//"+(bF+1)+" "}bH+="\n"}return bH};bx.prototype.toX3D=function(){var bA,bL,bO,bG,bC,bH,bE,bD,bB,by,bz,bI,bF,bM,bK,bJ,bN;bA=0.01;bN='<?xml version="1.0" encoding ="UTF-8"?>\n<X3D profile="Interchange" version="3.0">\n<head>\n<component name="Rendering" level="3"/>\n<meta name="generator" content="Polyhedronisme"/>\n<meta name="version" content="0.1.0"/>\n</head>\n<Scene>\n<Shape>\n<IndexedFaceSet normalPerVertex="false" coordIndex="';bz=this.face;for(bC=0,bH=bz.length;bC<bH;bC++){bG=bz[bC];for(by=0,bE=bG.length;by<bE;by++){bK=bG[by];bN+=bK+" "}bN+="-1\n"}bN+='">\n';bN+='<Color color="';bI=c(this);for(bM=0,bD=bI.length;bM<bD;bM++){bL=bI[bM];bO=ah(bL);bN+=bO[0]+" "+bO[1]+" "+bO[2]+" "}bN+='"/>';bN+='<Coordinate point="';bF=this.xyz;for(bJ=0,bB=bF.length;bJ<bB;bJ++){bK=bF[bJ];bN+=(bK[0]*bA)+" "+(bK[1]*bA)+" "+(bK[2]*bA)+" "}bN+='"/>\n';bN+="</IndexedFaceSet>\n</Shape>\n</Scene>\n</X3D>";return bN};bx.prototype.toVRML=function(){var bA,bL,bO,bG,bC,bH,bE,bD,bB,by,bz,bI,bF,bM,bK,bJ,bN;bA=0.01;bN='#VRML V2.0 utf8\n#Generated by Polyhedronisme\nNavigationInfo {\n type [ "EXAMINE", "ANY" ]\n}\nTransform {\n scale 1 1 1\n translation 0 0 0\n children\n [\n Shape\n {\n geometry IndexedFaceSet\n {\n creaseAngle .5\n solid FALSE\n coord Coordinate\n {\n point\n [';bz=this.xyz;for(bC=0,bH=bz.length;bC<bH;bC++){bK=bz[bC];bN+=(bK[0]*bA)+" "+(bK[1]*bA)+" "+(bK[2]*bA)+","}bN=bN.slice(0,-1);bN+=" ]\n}\ncolor Color\n{\n color\n [";bI=this.face_class;for(by=0,bE=bI.length;by<bE;by++){bL=bI[by];bO=ah(bL);bN+=bO[0]+" "+bO[1]+" "+bO[2]+" ,"}bN=bN.slice(0,-1);bN+=" ]\n}\ncolorPerVertex FALSE\ncoordIndex\n[";bF=this.face;for(bM=0,bD=bF.length;bM<bD;bM++){bG=bF[bM];for(bJ=0,bB=bG.length;bJ<bB;bJ++){bK=bG[bJ];bN+=bK+", "}bN+="-1,"}bN=bN.slice(0,-1);bN+=" ]\n }\n appearance Appearance\n {\n material Material\n {\n ambientIntensity 0.2\n diffuseColor 0.9 0.9 0.9\n specularColor .1 .1 .1\n shininess .5\n }\n }\n }\n ]\n}";return bN};return bx})();f=function(){var bx;bx=new aS();bx.name="T";bx.face=[[0,1,2],[0,2,3],[0,3,1],[1,3,2]];bx.xyz=[[1,1,1],[1,-1,-1],[-1,1,-1],[-1,-1,1]];return bx};aq=function(){var bx;bx=new aS();bx.name="O";bx.face=[[0,1,2],[0,2,3],[0,3,4],[0,4,1],[1,4,5],[1,5,2],[2,5,3],[3,5,4]];bx.xyz=[[0,0,1.414],[1.414,0,0],[0,1.414,0],[-1.414,0,0],[0,-1.414,0],[0,0,-1.414]];return bx};ak=function(){var bx;bx=new aS();bx.name="C";bx.face=[[3,0,1,2],[3,4,5,0],[0,5,6,1],[1,6,7,2],[2,7,4,3],[5,4,7,6]];bx.xyz=[[0.707,0.707,0.707],[-0.707,0.707,0.707],[-0.707,-0.707,0.707],[0.707,-0.707,0.707],[0.707,-0.707,-0.707],[0.707,0.707,-0.707],[-0.707,0.707,-0.707],[-0.707,-0.707,-0.707]];return bx};ba=function(){var bx;bx=new aS();bx.name="I";bx.face=[[0,1,2],[0,2,3],[0,3,4],[0,4,5],[0,5,1],[1,5,7],[1,7,6],[1,6,2],[2,6,8],[2,8,3],[3,8,9],[3,9,4],[4,9,10],[4,10,5],[5,10,7],[6,7,11],[6,11,8],[7,10,11],[8,11,9],[9,11,10]];bx.xyz=[[0,0,1.176],[1.051,0,0.526],[0.324,1,0.525],[-0.851,0.618,0.526],[-0.851,-0.618,0.526],[0.325,-1,0.526],[0.851,0.618,-0.526],[0.851,-0.618,-0.526],[-0.325,1,-0.526],[-1.051,0,-0.526],[-0.325,-1,-0.526],[0,0,-1.176]];return bx};ar=function(){var bx;bx=new aS();bx.name="D";bx.face=[[0,1,4,7,2],[0,2,6,9,3],[0,3,8,5,1],[1,5,11,10,4],[2,7,13,12,6],[3,9,15,14,8],[4,10,16,13,7],[5,8,14,17,11],[6,12,18,15,9],[10,11,17,19,16],[12,13,16,19,18],[14,15,18,19,17]];bx.xyz=[[0,0,1.07047],[0.713644,0,0.797878],[-0.356822,0.618,0.797878],[-0.356822,-0.618,0.797878],[0.797878,0.618034,0.356822],[0.797878,-0.618,0.356822],[-0.934172,0.381966,0.356822],[0.136294,1,0.356822],[0.136294,-1,0.356822],[-0.934172,-0.381966,0.356822],[0.934172,0.381966,-0.356822],[0.934172,-0.381966,-0.356822],[-0.797878,0.618,-0.356822],[-0.136294,1,-0.356822],[-0.136294,-1,-0.356822],[-0.797878,-0.618034,-0.356822],[0.356822,0.618,-0.797878],[0.356822,-0.618,-0.797878],[-0.713644,0,-0.797878],[0,0,-1.07047]];return bx};U=function(bB){var bx,bI,bG,bE,bA,by,bC,bL,bK,bJ,bH,bF,bD,bz,bN,bM;bz=2*aM/bB;bI=Math.sin(bz/2);by=new aS();by.name="P"+bB;for(bG=bE=0,bC=bB;0<=bC?bE<bC:bE>bC;bG=0<=bC?++bE:--bE){by.xyz.push([-J(bG*bz),-a2(bG*bz),-bI])}for(bG=bA=0,bL=bB;0<=bL?bA<bL:bA>bL;bG=0<=bL?++bA:--bA){by.xyz.push([-J(bG*bz),-a2(bG*bz),bI])}by.face.push((function(){bF=[];for(var bO=bK=bB-1;bK<=0?bO<=0:bO>=0;bK<=0?bO++:bO--){bF.push(bO)}return bF}).apply(this));by.face.push((function(){bD=[];for(var bP=bB,bO=2*bB;bB<=bO?bP<bO:bP>bO;bB<=bO?bP++:bP--){bD.push(bP)}return bD}).apply(this));for(bG=bx=0,bH=bB;0<=bH?bx<bH:bx>bH;bG=0<=bH?++bx:--bx){by.face.push([bG,(bG+1)%bB,(bG+1)%bB+bB,bG+bB])}by=z(by,1);return by};a0=function(bK){var bP,bO,bN,bM,bL,bI,bz,bH,by,bG,bF,bD,bC,bJ,bx,bA,bE,bB;bA=2*aM/bK;bN=W(1-4/(4+2*J(bA/2)-2*J(bA)));bH=W(1-bN*bN);bO=W(bN*bN+bc(bH*J(bA/2),2));bH=-bH/bO;bN=-bN/bO;bz=new aS();bz.name="A"+bK;for(bM=bL=0,by=bK;0<=by?bL<by:bL>by;bM=0<=by?++bL:--bL){bz.xyz.push([bH*J(bM*bA),bH*a2(bM*bA),bN])}for(bM=bI=0,bG=bK;0<=bG?bI<bG:bI>bG;bM=0<=bG?++bI:--bI){bz.xyz.push([bH*J((bM+0.5)*bA),bH*a2((bM+0.5)*bA),-bN])}bz.face.push((function(){bJ=[];for(var bQ=bF=bK-1;bF<=0?bQ<=0:bQ>=0;bF<=0?bQ++:bQ--){bJ.push(bQ)}return bJ}).apply(this));bz.face.push((function(){bx=[];for(var bR=bK,bQ=2*bK-1;bK<=bQ?bR<=bQ:bR>=bQ;bK<=bQ?bR++:bR--){bx.push(bR)}return bx}).apply(this));for(bM=bP=0,bC=bK-1;0<=bC?bP<=bC:bP>=bC;bM=0<=bC?++bP:--bP){bz.face.push([bM,(bM+1)%bK,bM+bK]);bz.face.push([bM,bM+bK,(bK+bM-1)%bK+bK])}bz=z(bz,1);return bz};bt=function(bA){var bI,bE,bC,bz,bx,bB,bG,bF,bD,by,bH;by=2*aM/bA;bI=1;bx=new aS();bx.name="Y"+bA;for(bE=bC=0,bB=bA;0<=bB?bC<bB:bC>bB;bE=0<=bB?++bC:--bC){bx.xyz.push([-J(bE*by),-a2(bE*by),-0.2])}bx.xyz.push([0,0,bI]);bx.face.push((function(){bD=[];for(var bJ=bG=bA-1;bG<=0?bJ<=0:bJ>=0;bG<=0?bJ++:bJ--){bD.push(bJ)}return bD}).apply(this));for(bE=bH=0,bF=bA;0<=bF?bH<bF:bH>bF;bE=0<=bF?++bH:--bH){bx.face.push([bE,(bE+1)%bA,bA])}bx=g(bx,3);return bx};aj=(function(){function bx(){this.flags=new Object();this.verts=new Object();this.xyzs=new Object()}bx.prototype.newV=function(bz,by){if(this.verts[bz]===void 0){this.verts[bz]=0;return this.xyzs[bz]=by}};bx.prototype.newFlag=function(by,bA,bz){if(this.flags[by]===void 0){this.flags[by]={}}return this.flags[by][bA]=bz};bx.prototype.topoly=function(){var bz,bD,bH,bC,bB,by,bA,bE,bG,bF;by=new aS();bz=0;bA=this.verts;for(bC in bA){bG=bA[bC];by.xyz[bz]=this.xyzs[bC];this.verts[bC]=bz;bz++}bz=0;bE=this.flags;for(bC in bE){bD=bE[bC];by.face[bz]=[];for(bB in bD){bG=bD[bB];bF=bG;break}bG=bF;by.face[bz].push(this.verts[bG]);bG=this.flags[bC][bG];bH=0;while(bG!==bF){by.face[bz].push(this.verts[bG]);bG=this.flags[bC][bG];bH++;if(bH>1000){console.log("Bad flag spec, have a neverending face:",bC,this.flags[bC]);break}}bz++}by.name="unknown polyhedron";return by};return bx})();ae=function(bD,bN,bB){var bA,bT,bS,bP,bU,bz,bQ,bO,bR,bF,bE,bG,bK,bM,bL,bC,bJ,bI,bH,by,bx;bN||(bN=0);bB||(bB=0.1);console.log("Taking kis of "+(bN===0?"":bN)+"-sided faces of "+bD.name+"...");bP=new aj();bC=bD.xyz;for(bQ=bO=0,bR=bC.length;bO<bR;bQ=++bO){bL=bC[bQ];bP.newV("v"+bQ,bL)}bK=bD.normals();bT=bD.centers();bz=false;bJ=bD.face;for(bQ=bM=0,bF=bJ.length;bM<bF;bQ=++bM){bS=bJ[bQ];by="v"+bS[bS.length-1];for(bI=0,bE=bS.length;bI<bE;bI++){bH=bS[bI];bx="v"+bH;if(bS.length===bN||bN===0){bz=true;bA="apex"+bQ;bU=""+bQ+by;bP.newV(bA,A(bT[bQ],d(bB,bK[bQ])));bP.newFlag(bU,by,bx);bP.newFlag(bU,bx,bA);bP.newFlag(bU,bA,by)}else{bP.newFlag(""+bQ,by,bx)}by=bx}}if(!bz){console.log("No "+bN+"-fold components were found.")}bG=bP.topoly();bG.name="k"+(bN===0?"":bN)+bD.name;return bG};aK=function(bx){var bG,bJ,bE,bC,bH,bD,by,bB,bz,bA,bI,bF,bM,bL,bK;console.log("Taking ambo of "+bx.name+"...");by=function(bO,bN){if(bO<bN){return bO+"_"+bN}else{return bN+"_"+bO}};bJ=new aj();bA=bx.face;for(bE=bC=0,bH=bA.length;bC<bH;bE=++bC){bG=bA[bE];bI=bG.slice(-2),bM=bI[0],bL=bI[1];for(bz=0,bD=bG.length;bz<bD;bz++){bK=bG[bz];if(bM<bL){bJ.newV(by(bM,bL),aY(bx.xyz[bM],bx.xyz[bL]))}bJ.newFlag("orig"+bE,by(bM,bL),by(bL,bK));bJ.newFlag("dual"+bL,by(bL,bK),by(bM,bL));bF=[bL,bK],bM=bF[0],bL=bF[1]}}bB=bJ.topoly();bB.name="a"+bx.name;return bB};a6=function(bB){var bU,bT,bQ,bV,bR,bP,bO,bS,bE,bD,bC,bH,bN,bA,bM,bL,bJ,bG,bK,bI,bz,by,bx,bF;console.log("Taking gyro of "+bB.name+"...");bQ=new aj();bA=bB.xyz;for(bR=bO=0,bS=bA.length;bO<bS;bR=++bO){bI=bA[bR];bQ.newV("v"+bR,bp(bI))}bU=bB.centers();bM=bB.face;for(bR=bN=0,bE=bM.length;bN<bE;bR=++bN){bT=bM[bR];bQ.newV("center"+bR,bp(bU[bR]))}bL=bB.face;for(bR=bK=0,bD=bL.length;bK<bD;bR=++bK){bT=bL[bR];bJ=bT.slice(-2),bz=bJ[0],by=bJ[1];for(bP=bF=0,bC=bT.length;bF<bC;bP=++bF){bI=bT[bP];bx=bI;bQ.newV(bz+"~"+by,av(bB.xyz[bz],bB.xyz[by]));bV=bR+"f"+bz;bQ.newFlag(bV,"center"+bR,bz+"~"+by);bQ.newFlag(bV,bz+"~"+by,by+"~"+bz);bQ.newFlag(bV,by+"~"+bz,"v"+by);bQ.newFlag(bV,"v"+by,by+"~"+bx);bQ.newFlag(bV,by+"~"+bx,"center"+bR);bG=[by,bx],bz=bG[0],by=bG[1]}}bH=bQ.topoly();bH.name="g"+bB.name;return bH};t=function(bB){var bP,bM,bQ,bN,bL,bO,bD,bC,bE,bK,bA,bJ,bI,bG,bH,bF,bz,by,bx;console.log("Taking propellor of "+bB.name+"...");bM=new aj();bA=bB.xyz;for(bN=bL=0,bO=bA.length;bL<bO;bN=++bL){bF=bA[bN];bM.newV("v"+bN,bp(bF))}bJ=bB.face;for(bN=bK=0,bD=bJ.length;bK<bD;bN=++bK){bP=bJ[bN];bI=bP.slice(-2),bz=bI[0],by=bI[1];for(bH=0,bC=bP.length;bH<bC;bH++){bF=bP[bH];bx=""+bF;bM.newV(bz+"~"+by,av(bB.xyz[bz],bB.xyz[by]));bQ=bN+"f"+by;bM.newFlag("v"+bN,bz+"~"+by,by+"~"+bx);bM.newFlag(bQ,bz+"~"+by,by+"~"+bz);bM.newFlag(bQ,by+"~"+bz,"v"+by);bM.newFlag(bQ,"v"+by,by+"~"+bx);bM.newFlag(bQ,by+"~"+bx,bz+"~"+by);bG=[by,bx],bz=bG[0],by=bG[1]}}bE=bM.topoly();bE.name="p"+bB.name;return bE};u=function(bB){var bz,bx,bC,bA,by;console.log("Taking reflection of "+bB.name+"...");for(bz=bx=0,bA=bB.xyz.length-1;0<=bA?bx<=bA:bx>=bA;bz=0<=bA?++bx:--bx){bB.xyz[bz]=d(-1,bB.xyz[bz])}for(bz=bC=0,by=bB.face.length-1;0<=by?bC<=by:bC>=by;bz=0<=by?++bC:--bC){bB.face[bz]=bB.face[bz].reverse()}bB.name="r"+bB.name;return bB};aL=function(bA){var bX,bW,bV,bU,bY,bT,bF,bQ,bR,bP,bO,bS,bE,bD,bC,bB,bN,bz,bL,bK,bI,bH,bM,bJ,by,bx,bG;console.log("Taking dual of "+bA.name+"...");bQ=new aj();bF=[];for(bR=bO=0,bz=bA.xyz.length-1;0<=bz?bO<=bz:bO>=bz;bR=0<=bz?++bO:--bO){bF[bR]={}}bL=bA.face;for(bR=bN=0,bS=bL.length;bN<bS;bR=++bN){bT=bL[bR];by=bT[bT.length-1];for(bJ=0,bE=bT.length;bJ<bE;bJ++){bx=bT[bJ];bF[by]["v"+bx]=""+bR;by=bx}}bU=bA.centers();for(bR=bG=0,bK=bA.face.length-1;0<=bK?bG<=bK:bG>=bK;bR=0<=bK?++bG:--bG){bQ.newV(""+bR,bU[bR])}bI=bA.face;for(bR=bX=0,bD=bI.length;bX<bD;bR=++bX){bT=bI[bR];by=bT[bT.length-1];for(bW=0,bC=bT.length;bW<bC;bW++){bx=bT[bW];bQ.newFlag(by,bF[bx]["v"+by],""+bR);by=bx}}bY=bQ.topoly();bM=[];bH=bY.face;for(bV=0,bB=bH.length;bV<bB;bV++){bT=bH[bV];bP=G(bA.face[bT[0]],bA.face[bT[1]],bA.face[bT[2]]);bM[bP]=bT}bY.face=bM;if(bA.name[0]!=="d"){bY.name="d"+bA.name}else{bY.name=bA.name.slice(1)}return bY};bm=function(by,bK){var bH,bx,bJ,bF,bD,bI,bE,bC,bM,bz,bA,bN,bG,bL,bB;console.log("Taking chamfer of "+by.name+"...");bK||(bK=0.5);bJ=new aj();bM=by.normals();bA=by.face;for(bF=bD=0,bI=bA.length;bD<bI;bF=++bD){bH=bA[bF];bN=bH[bH.length-1];bG=bF+"_"+bN;for(bz=0,bE=bH.length;bz<bE;bz++){bL=bH[bz];bJ.newV(bL,d(1+bK,by.xyz[bL]));bB=bF+"_"+bL;bJ.newV(bB,A(by.xyz[bL],d(bK*1.5,bM[bF])));bJ.newFlag("orig"+bF,bG,bB);bx=(bN<bL?"hex"+bN+"_"+bL:"hex"+bL+"_"+bN);bJ.newFlag(bx,bL,bB);bJ.newFlag(bx,bB,bG);bJ.newFlag(bx,bG,bN);bN=bL;bG=bB}}bC=bJ.topoly();bC.name="c"+by.name;return bC};bn=function(bB,bM){var bT,bU,bE,bS,bP,bV,bQ,bO,bN,bR,bD,bC,bF,bL,bA,bK,bJ,bH,bI,bG,bz,bW,by,bx;console.log("Taking whirl of "+bB.name+"...");bM||(bM=0);bP=new aj();bA=bB.xyz;for(bQ=bN=0,bR=bA.length;bN<bR;bQ=++bN){bG=bA[bQ];bP.newV("v"+bQ,bp(bG))}bT=bB.centers();bK=bB.face;for(bQ=bL=0,bD=bK.length;bL<bD;bQ=++bL){bS=bK[bQ];bJ=bS.slice(-2),bz=bJ[0],by=bJ[1];for(bO=bI=0,bC=bS.length;bI<bC;bO=++bI){bG=bS[bO];bx=bG;bW=av(bB.xyz[bz],bB.xyz[by]);bP.newV(bz+"~"+by,bW);bU="center"+bQ+"~"+bz;bE="center"+bQ+"~"+by;bP.newV(bU,bp(av(bT[bQ],bW)));bV=bQ+"f"+bz;bP.newFlag(bV,bU,bz+"~"+by);bP.newFlag(bV,bz+"~"+by,by+"~"+bz);bP.newFlag(bV,by+"~"+bz,"v"+by);bP.newFlag(bV,"v"+by,by+"~"+bx);bP.newFlag(bV,by+"~"+bx,bE);bP.newFlag(bV,bE,bU);bP.newFlag("c"+bQ,bU,bE);bH=[by,bx],bz=bH[0],by=bH[1]}}bF=bP.topoly();bF.name="w"+bB.name;return bF};F=function(bB,bQ,bC,bR){var bZ,bX,bW,bT,bY,bz,bU,bS,bV,bG,bF,bE,bD,bI,bN,bP,bO,bA,bM,bL,bK,bJ,by,bx,bH;bQ||(bQ=0);bC||(bC=0.5);bR||(bR=-0.2);console.log("Taking inset of "+(bQ===0?"":bQ)+"-sided faces of "+bB.name+"...");bT=new aj();bA=bB.xyz;for(bU=bS=0,bV=bA.length;bS<bV;bU=++bS){bO=bA[bU];bT.newV("v"+bU,bO)}bN=bB.normals();bX=bB.centers();bM=bB.face;for(bU=bP=0,bG=bM.length;bP<bG;bU=++bP){bW=bM[bU];if(bW.length===bQ||bQ===0){for(bK=0,bF=bW.length;bK<bF;bK++){bJ=bW[bK];bT.newV("f"+bU+"v"+bJ,A(m(bB.xyz[bJ],bX[bU],bC),d(bR,bN[bU])))}}}bz=false;bL=bB.face;for(bU=bH=0,bE=bL.length;bH<bE;bU=++bH){bW=bL[bU];by="v"+bW[bW.length-1];for(bZ=0,bD=bW.length;bZ<bD;bZ++){bJ=bW[bZ];bx="v"+bJ;if(bW.length===bQ||bQ===0){bz=true;bY=bU+by;bT.newFlag(bY,by,bx);bT.newFlag(bY,bx,"f"+bU+bx);bT.newFlag(bY,"f"+bU+bx,"f"+bU+by);bT.newFlag(bY,"f"+bU+by,by);bT.newFlag("ex"+bU,"f"+bU+by,"f"+bU+bx)}else{bT.newFlag(bU,by,bx)}by=bx}}if(!bz){console.log("No "+bQ+"-fold components were found.")}bI=bT.topoly();bI.name="n"+(bQ===0?"":bQ)+bB.name;return bI};ad=function(bB,bP){var bW,bV,bU,bR,bz,bS,bQ,bT,bF,bE,bD,bC,bH,bM,bO,bN,bA,bL,bK,bJ,bI,by,bx,bG;bP||(bP=0);console.log("Taking extrusion of "+(bP===0?"":bP)+"-sided faces of "+bB.name+"...");bR=new aj();bA=bB.xyz;for(bS=bQ=0,bT=bA.length;bQ<bT;bS=++bQ){bN=bA[bS];bR.newV("v"+bS,bN)}bM=bB.normals();bV=bB.centers();bL=bB.face;for(bS=bO=0,bF=bL.length;bO<bF;bS=++bO){bU=bL[bS];if(bU.length===bP||bP===0){for(bJ=0,bE=bU.length;bJ<bE;bJ++){bI=bU[bJ];bR.newV("f"+bS+"v"+bI,A(bB.xyz[bI],d(0.3,bM[bS])))}}}bz=false;bK=bB.face;for(bS=bG=0,bD=bK.length;bG<bD;bS=++bG){bU=bK[bS];by="v"+bU[bU.length-1];for(bW=0,bC=bU.length;bW<bC;bW++){bI=bU[bW];bx="v"+bI;if(bU.length===bP||bP===0){bz=true;bR.newFlag(bS+by,by,bx);bR.newFlag(bS+by,bx,"f"+bS+bx);bR.newFlag(bS+by,"f"+bS+bx,"f"+bS+by);bR.newFlag(bS+by,"f"+bS+by,by);bR.newFlag("ex"+bS,"f"+bS+by,"f"+bS+bx)}else{bR.newFlag(bS,by,bx)}by=bx}}if(!bz){console.log("No "+bP+"-fold components were found.")}bH=bR.topoly();bH.name="x"+(bP===0?"":bP)+bB.name;return bH};i=function(bC,bR,bE,bx){var b0,bY,bW,bX,bT,bZ,bA,bU,bS,bV,bH,bG,bF,bD,bJ,bO,bQ,bP,bB,bN,bM,bL,bK,bz,by,bI;bR||(bR=0);bE||(bE=0.5);bx||(bx=0.2);console.log("Skeletonizing "+(bR===0?"":bR)+"-sided faces of "+bC.name+"...");bW=aL(bC).normals();bO=bC.normals();bY=bC.centers();bT=new aj();bB=bC.xyz;for(bU=bS=0,bV=bB.length;bS<bV;bU=++bS){bP=bB[bU];bT.newV("v"+bU,bP);bT.newV("downv"+bU,A(bP,d(-1*bx,bW[bU])))}bN=bC.face;for(bU=bQ=0,bH=bN.length;bQ<bH;bU=++bQ){bX=bN[bU];for(bL=0,bG=bX.length;bL<bG;bL++){bK=bX[bL];bT.newV("fin"+bU+"v"+bK,m(bC.xyz[bK],bY[bU],bE));bT.newV("findown"+bU+"v"+bK,A(m(bC.xyz[bK],bY[bU],bE),d(-1*bx,bO[bU])))}}bM=bC.face;for(bU=bI=0,bF=bM.length;bI<bF;bU=++bI){bX=bM[bU];bz="v"+bX[bX.length-1];for(b0=0,bD=bX.length;b0<bD;b0++){bK=bX[b0];by="v"+bK;bA=true;bZ=bU+bz;bT.newFlag(bZ,bz,by);bT.newFlag(bZ,by,"fin"+bU+by);bT.newFlag(bZ,"fin"+bU+by,"fin"+bU+bz);bT.newFlag(bZ,"fin"+bU+bz,bz);bZ="sides"+bU+bz;bT.newFlag(bZ,"fin"+bU+bz,"fin"+bU+by);bT.newFlag(bZ,"fin"+bU+by,"findown"+bU+by);bT.newFlag(bZ,"findown"+bU+by,"findown"+bU+bz);bT.newFlag(bZ,"findown"+bU+bz,"fin"+bU+bz);bZ="bottom"+bU+bz;bT.newFlag(bZ,"down"+by,"down"+bz);bT.newFlag(bZ,"down"+bz,"findown"+bU+bz);bT.newFlag(bZ,"findown"+bU+bz,"findown"+bU+by);bT.newFlag(bZ,"findown"+bU+by,"down"+by);bz=by}}bJ=bT.topoly();bJ.name="h"+bC.name;return bJ};a1=function(bD){var bW,bV,bS,bT,bR,bU,bI,bG,bJ,bQ,bP,bC,bO,bN,bL,bM,bK,bz,bX,by,bB,bA,bx,bH,bF,bE;console.log("Taking stella of "+bD.name+"...");bW=bD.centers();bS=new aj();bC=bD.xyz;for(bT=bR=0,bU=bC.length;bR<bU;bT=++bR){bP=bC[bT];bS.newV("v"+bT,bP)}bO=bD.face;for(bT=bQ=0,bI=bO.length;bQ<bI;bT=++bQ){bV=bO[bT];bz="v"+bV[bV.length-2];by="v"+bV[bV.length-1];bH=bD.xyz[bV[bV.length-2]];bF=bD.xyz[bV[bV.length-1]];for(bM=0,bG=bV.length;bM<bG;bM++){bK=bV[bM];bx="v"+bK;bE=bD.xyz[bK];bX=bz+"~"+by;bB=by+"~"+bz;bA=by+"~"+bx;bS.newV(bX,aY(aY(bH,bF),bW[bT]));bS.newFlag("in"+bT,bX,bA);bS.newFlag("f"+bT+by,bA,bX);bS.newFlag("f"+bT+by,bX,by);bS.newFlag("f"+bT+by,by,bA);bS.newFlag("f"+bX,bz,bB);bS.newFlag("f"+bX,bB,bX);bS.newFlag("f"+bX,bX,bz);bN=[by,bx],bz=bN[0],by=bN[1];bL=[bF,bE],bH=bL[0],bF=bL[1]}}bJ=bS.topoly();bJ.name="l"+bD.name;return bJ};ab=function(bA,bz){var bE,bD,bC,by,bB,bx,bF;bE=0.1;bx=a8(bA);for(by=0,bB=bz.length;by<bB;by++){bC=bz[by];bF=l(bx[bC[0]],bx[bC[1]]);bD=d(bE*1/2*(1-W(E(bF,bF))),bF);bx[bC[0]]=A(bx[bC[0]],bD);bx[bC[1]]=A(bx[bC[1]],bD)}return bx};bd=function(bB,bA){var bE,bD,bx,by,bC,bz,bF;bx=(function(){var bH,bG,bJ,bI;bI=[];for(bH=0,bG=bA.length;bH<bG;bH++){bJ=bA[bH],bE=bJ[0],bD=bJ[1];bI.push(l(bB[bE],bB[bD]))}return bI})();bz=[0,0,0];for(by=0,bC=bx.length;by<bC;by++){bF=bx[by];bz=A(bz,bF)}bz=d(1/bA.length,bz);return _.map(bB,function(bG){return bh(bG,bz)})};C=function(bA){var bx,bz,by;bz=[0,0,0];bx=_.max(_.map(bA,function(bB){return L(bB)}));by=1/bx;return _.map(bA,function(bB){return[by*bB[0],by*bB[1],by*bB[2]]})};bg=function(bD,bA){var bI,bG,bH,bE,bB,bF,bC,bz,bx,by,bJ;bI=0.1;bx=a8(bD);for(bB=0,bF=bA.length;bB<bF;bB++){bE=bA[bB];bH=(function(){var bK,bM,bL;bL=[];for(bM=0,bK=bE.length;bM<bK;bM++){bJ=bE[bM];bL.push(bD[bJ])}return bL})();bz=al(bH);bG=bo(bH);if(E(bz,bG)<0){bz=d(-1,bz)}for(by=0,bC=bE.length;by<bC;by++){bJ=bE[by];bx[bJ]=A(bx[bJ],d(E(d(bI,bz),bh(bG,bD[bJ])),bz))}}return bx};o=function(by,bG){var bD,bA,bE,bC,bF,bx,bB,bH,bz;bG||(bG=1);console.log("Canonicalizing "+by.name+"...");bA=by.face;bD=by.edges();bx=by.xyz;bF=1;for(bE=bC=0,bz=bG;0<=bz?bC<=bz:bC>=bz;bE=0<=bz?++bC:--bC){bH=a8(bx);bx=ab(bx,bD);bx=bd(bx,bD);bx=bg(bx,bA);bF=_.max(_.map(_.zip(bx,bH),function(bJ){var bI,bK;bI=bJ[0],bK=bJ[1];return L(bh(bI,bK))}));if(bF<1e-8){break}}console.log("[canonicalization done, last |deltaV|="+bF+"]");bB=new aS(bx,by.face,by.name);console.log("canonicalize",bB);return bB};P=function(bA){var bB,bz,by,bx;bz=bA.centers();for(by=0,bx=bz.length;by<bx;by++){bB=bz[by];bB=d(1/E(bB,bB),bB)}return bz};I=function(by){var bN,bF,bA,bH,bC,bI,bD,bx,bz,bB,bJ,bG,bE,bM,bL,bK;bN=[];bB=by.face;for(bC=0,bI=bB.length;bC<bI;bC++){bH=bB[bC];bA=[0,0,0];bx=[0,0,0];bF=0;bJ=bH.slice(-2),bM=bJ[0],bL=bJ[1];for(bz=0,bD=bH.length;bz<bD;bz++){bK=bH[bz];bA=A(bA,by.xyz[bK]);bx=A(bx,aZ(by.xyz[bM],by.xyz[bL],by.xyz[bK]));bF+=ax(by.xyz[bM],by.xyz[bL]);bG=[bL,bK],bM=bG[0],bL=bG[1]}bA=d(1/bH.length,bA);bx=bp(bx);bF=bF/bH.length;bE=aF(d(E(bA,bx),bx));bN.push(d((1+bF)/2,bE))}return bN};g=function(bC,bz){var bB,by,bx,bA;bz||(bz=1);by=aL(bC);console.log("Pseudo-canonicalizing "+bC.name+"...");for(bB=bx=0,bA=bz;0<=bA?bx<bA:bx>bA;bB=0<=bA?++bx:--bx){by.xyz=I(bC);bC.xyz=I(by)}return new aS(bC.xyz,bC.face,bC.name)};z=function(bC,bz){var bB,by,bx,bA;bz||(bz=1);by=aL(bC);console.log("Planarizing "+bC.name+"...");for(bB=bx=0,bA=bz;0<=bA?bx<bA:bx>bA;bB=0<=bA?++bx:--bx){by.xyz=P(bC);bC.xyz=P(by)}return new aS(bC.xyz,bC.face,bC.name)};K=function(bZ){var bY,bU,bN,bS,bX,bG,b0,bQ,bL,bI,bW,bB,bT,bM,bD,bE,bR,bH,bP,bV,bF,bO,bC,bA,bz,by,bx,bK,bJ;bH=999;bT=[];bM=[];bD=bZ.length;bW=function(b1,b2){return(b1||b2)&&!(b1&&b2)};bY=function(b3,b2,b1){return(b2[0]-b3[0])*(b1[1]-b3[1])-(b1[0]-b3[0])*(b2[1]-b3[1])};bL=function(b3,b2,b1){return bY(b3,b2,b1)>0};bI=function(b3,b2,b1){return bY(b3,b2,b1)>=0};bN=function(b3,b2,b1){return bY(b3,b2,b1)===0};bU=function(b3,b2,b1){if(bN(b3,b2,b1)){return false}if(b3[0]!==b2[0]){return(b3[0]<=b1[0])&&(b1[0]<=b2[0])||(b3[0]>=b1[0])&&(b1[0]>=b2[0])}else{return(b3[1]<=b1[1])&&(b1[1]<=b2[1])||(b3[1]>=b1[1])&&(b1[1]>=b2[1])}};bQ=function(b4,b3,b2,b1){if(bN(b4,b3,b2)||bN(b4,b3,b1)||bN(b2,b1,b4)||bN(b2,b1,b3)){return false}return bW(bL(b4,b3,b2),bL(b4,b3,b1))&&bW(bL(b2,b1,b4),bL(b2,b1,b3))};b0=function(b4,b3,b2,b1){if(bQ(b4,b3,b2,b1)){return true}else{if(bU(b4,b3,b2)||bU(b4,b3,b1)||bU(b2,b1,b4)||bU(b2,b1,b3)){return true}else{return false}}};bG=function(b3,b1){var b4,b2;b2=(b3+1+bD)%bD;b4=(b3-1+bD)%bD;if(bI(bZ[b3],bZ[b2],bZ[b4])){return bL(bZ[b3],bZ[b1],bZ[b4])&&bL(bZ[b1],bZ[b3],bZ[b2])}return !(bI(bZ[b3],bZ[b1],bZ[b2])&&bI(bZ[b1],bZ[b3],bZ[b4]))};bX=function(b2,b1){var b4,b3;b4=0;while(true){b3=(b4+1+bD)%bD;if((b4!==b2)&&(b3!==b2)&&(b4!==b1)&&(b3!==b1)&&bQ(bZ[b2],bZ[b1],bZ[b4],bZ[b3])){return false}b4=(b4+1+bD)%bD;if(b4===0){break}}return true};bS=function(b2,b1){return bG(b2,b1)&&bG(b1,b2)&&bX(b2,b1)};bA=0;while(true){bz=(bA+1+bD)%bD;bC=(bA-1+bD)%bD;bM[bA]=bS(bC,bz);bA=(bA+1+bD)%bD;if(bA===0){break}}bV=(function(){bO=[];for(var b1=0,b2=bD-1;0<=b2?b1<=b2:b1>=b2;0<=b2?b1++:b1--){bO.push(b1)}return bO}).apply(this);bP=bD;bJ=bH;bE=0;while(bJ>0&&bP>3){bJ-=1;bz=bE;bK=bH;while(true){bK-=1;bB=false;if(bM[bz]){by=(bz+1+bD)%bD;bx=(by+1+bD)%bD;bA=(bz-1+bD)%bD;bC=(bA-1+bD)%bD;bT.push([bV[bA],bV[by]]);bM[bA]=bS(bC,by);bM[by]=bS(bA,bx);bZ=bZ.slice(0,+bz+1||9000000000).concat(bZ.slice(by));bV=bV.slice(0,+bz+1||9000000000).concat(bV.slice(by));if(bC>bz){bC-=1}if(bA>bz){bA-=1}if(by>bz){by-=1}if(bx>bz){bx-=1}bD--;bE=by;bP--;bB=true}bz=(bz+1+bD)%bD;if(!(bK>0&&!bB&&bz!==bE)){break}}}return bT};a=function(by,bx){if(((by[0]===bx[0])&&(by[1]===bx[1])&&(by[2]===bx[2]))||(by[0]===bx[1])&&(by[1]===bx[2])&&(by[2]===bx[0])||(by[0]===bx[2])&&(by[1]===bx[0])&&(by[2]===bx[1])){return true}else{return false}};v=function(b4,bW){var bR,bP,bN,bL,bJ,bT,b5,bV,bU,bQ,bX,b3,b2,bS,bF,bE,bD,bC,bB,bA,bz,by,b1,bx,b0,bO,bM,bK,bI,bH,bG,b6,bZ,b9,b8,b7,bY;bQ=[];bx=[];b0=(function(){var cc,cb,ca;ca=[];for(b3=cc=0,cb=b4.length-1;0<=cb?cc<=cb:cc>=cb;b3=0<=cb?++cc:--cc){ca.push([b3,(b3+1)%b4.length])}return ca})();for(b2=0,bS=b0.length;b2<bS;b2++){bO=b0[b2],b8=bO[0],b7=bO[1];bQ[b8]=[b7];bx[b7]=[b8]}for(b1=0,bF=bW.length;b1<bF;b1++){b5=bW[b1];bQ[b5[0]].push(b5[1]);bQ[b5[1]].push(b5[0]);bx[b5[0]].push(b5[1]);bx[b5[1]].push(b5[0])}b6=[];for(bZ=0,bE=bW.length;bZ<bE;bZ++){b5=bW[bZ];bM=bQ[b5[1]];for(bY=0,bD=bM.length;bY<bD;bY++){bV=bM[bY];bK=bx[b5[0]];for(bR=0,bC=bK.length;bR<bC;bR++){bU=bK[bR];if(bV===bU){b6.push([b5[0],b5[1],bV])}}}bI=bQ[b5[0]];for(bP=0,bB=bI.length;bP<bB;bP++){bV=bI[bP];bH=bx[b5[1]];for(bN=0,bA=bH.length;bN<bA;bN++){bU=bH[bN];if(bV===bU){b6.push([b5[1],b5[0],bV])}}}}b9=[b6.pop()];for(bL=0,bz=b6.length;bL<bz;bL++){bG=b6[bL];bT=false;for(bJ=0,by=b9.length;bJ<by;bJ++){bX=b9[bJ];if(a(bG,bX)){bT=true;break}}if(!bT){b9.push(bG)}}return b9};ac=function(by,bx){var bB,bA,bJ,bH,bG,bE,bI,bF,bD,bz,bC,bM,bL,bK;bx=bx||false;console.log("Triangulating faces of "+by.name+"...");bD=new aS();bD.xyz=M(by.xyz);bD.face_class=[];bC=by.face;for(bH=bE=0,bI=bC.length;bE<bI;bH=++bE){bJ=bC[bH];if(bJ.length>3){bB=aa((function(){var bN,bP,bO;bO=[];for(bP=0,bN=bJ.length;bP<bN;bP++){bK=bJ[bP];bO.push(by.xyz[bK])}return bO})());bA=K(bB);bL=v(bJ,bA);for(bG=bz=0,bF=bL.length;bz<bF;bG=++bz){bM=bL[bG];bD.face.push([bJ[bM[0]],bJ[bM[1]],bJ[bM[2]]]);if(bx){bD.face_class.push(by.face_class[bH])}}}else{bD.face.push([bJ[0],bJ[1],bJ[2]]);if(bx){bD.face_class.push(by.face_class[bH])}}}bD.name=by.name;return bD};ai=function(bx){var bC,bA,bD,bB,by,bz,bE,bF;bE="";bz=bx.face;for(bA=0,bD=bz.length;bA<bD;bA++){bC=bz[bA];for(by=0,bB=bC.length;by<bB;by++){bF=bC[by];bE+=bF+"->"}bE+="\n"}return console.log(bE)};D=function(){var bA,bx,bB,bD,bE,bC,bz,by;by=["T","O","C","I","D","P3","P4","A4","A5","Y3","Y4"];bC=["k","a","g","p","d","n","x","*"];console.log("===== Test Basic Ops =====");for(bA=0,bx=bC.length;bA<bx;bA++){bE=bC[bA];console.log("Operator "+bE);for(bD=0,bB=by.length;bD<bB;bD++){bz=by[bD];console.log(bE+bz+":",generatePoly(bE+bz))}}return console.log("===== Done Testing Basic Ops =====")};aV='/* series of opspecs */\nstart = opspec+\n\n/* opspec one of:\n A - single letter\n A3 - single letter and float\n B(5,4.3,3) - function call format w. float args\n*/\nopspec =\n let:opcode args:opargs {return {"op":let,"args":args};}\n/ let:opcode float:float {return {"op":let,"args":[float]};}\n/ let:opcode {return {"op":let,"args":[]};}\n\n/*\nparentheses surrounding comma-delimited list of floats i.e.\n( 1 , 3.2, 4 ) or (1) or (2,3)\n*/\nopargs = "("\n num:( float:float ","? {return float} )+\n ")" {return num;}\n\n/* just a letter */\nopcode = op:[a-zA-Z] {return op;}\n\n/* standard numerical types */\nint = digits:[0-9-]+ { return parseInt(digits.join(""), 10); }\nfloat = digits:[0-9.-]+ { return parseFloat(digits.join(""), 10); }';bi=PEG.buildParser(aV);bw=function(by,bx){return by.apply(this,bx||[])};bk={T:f,O:aq,C:ak,I:ba,D:ar,P:U,A:a0,Y:bt};H={d:aL,k:ae,a:aK,g:a6,p:t,r:u,h:i,c:bm,w:bn,n:F,x:ad,l:a1,z:ac,K:g,C:o,A:z};aR=[[/e/g,"aa"],[/b/g,"ta"],[/o/g,"jj"],[/m/g,"kj"],[/t(\d*)/g,"dk$1d"],[/j/g,"dad"],[/s/g,"dgd"],[/dd/g,""],[/ad/g,"a"],[/gd/g,"g"],[/aO/g,"aC"],[/aI/g,"aD"],[/gO/g,"gC"],[/gI/g,"gD"]];a4=function(bC){var by,bA,bz,bx,bD,bB;bA=bC;for(bz=0,bx=aR.length;bz<bx;bz++){bB=aR[bz],bD=bB[0],by=bB[1];bA=bA.replace(bD,by)}console.log(bC+" executed as "+bA);return bA};bu=function(bE){var by,bF,bz,bC,bA,bH,bB,bG,bD,bx;bD=a4(bE);bG=bi.parse(bD).reverse();bA=bG.shift();bF=bk[bA.op];by=bA.args;bx=bw(bF,by);for(bz=0,bC=bG.length;bz<bC;bz++){bA=bG[bz];bB=H[bA.op];bH=[bx].concat(bA.args);bx=bw(bB,bH)}bx.xyz=bd(bx.xyz,bx.edges());bx.xyz=C(bx.xyz);bx=R(bx);return bx};af={};bq=500;aC=400;Q={};k=M(w);am=M(w);V=800;B=5;br=0;N=0.8;p=bq/2;az=aC/2;x=new Date();r=true;aW="rgba(255,255,255,1.0)";ao="signature";h="fillstroke";bf=0.5;ap=false;Y=0;X=0;aJ=[1,0,0];a7=["C2dakD","oC20kkkT","kn4C40A0dA4","opD","lT","lK5oC","knD","dn6x4K5bT","oox4P7","n18n18n9n9n9soxY9"];aH=function(bz,bx){var bA,by;bA=window.BlobBuilder||window.WebKitBlobBuilder||window.MozBlobBuilder;by=new bA();by.append(bz);return saveAs(by.getBlob("text/plain;charset="+document.characterSet),bx)};bs=function(){var bx,bC,bB,bA,bz,by;by={};bx=/\+/g;bz=/([^&=]+)=?([^&]*)/g;bC=function(bD){return decodeURIComponent(bD.replace(bx," "))};bA=window.location.search.substring(1);while(bB=bz.exec(bA)){by[bC(bB[1])]=bC(bB[2])}return by};at=function(){var bx,by;by=$("#spec").val().split(/\s+/g).slice(0,2);bx=location.protocol+"//"+location.host+location.pathname;bx+="?recipe="+encodeURIComponent(by[0]);if(a3!==aT){bx+="&palette="+encodeURIComponent(a3.reduce(function(bz,bA){return bz+" "+bA}))}return $("#link").attr("href",bx)};aN=function(){var bx,by;bx=$("#poly");bx.width(bq);bx.height(aC);af=bx[0].getContext("2d");af.lineWidth=bf;if(r){af.clearRect(0,0,bq,aC)}else{af.clearRect(0,0,bq,aC);af.fillStyle=aW;af.fillRect(0,0,bq,aC)}by=$("#expandcollapse");return by.click(function(){if(/minus/.test(by.attr("src"))){$("#morestats").hide();return by.attr("src","media/plus.png")}else{$("#morestats").show();return by.attr("src","media/minus.png")}})};aP=function(){if(r){return af.clearRect(0,0,bq,aC)}else{af.clearRect(0,0,bq,aC);af.fillStyle=aW;return af.fillRect(0,0,bq,aC)}};S=function(bC,bP){var bx,bF,bD,bK,by,bN,bO,bE,bM,bz,bB,bL,bJ,bI,bA,bH,bG;bP||(bP=[3,3,3]);bz=_.map(bC.xyz,function(bQ){return bQ});bC.xyz=_.map(bC.xyz,function(bQ){return s(k,bQ)});aU(bC);bB=bC.face;for(bK=bN=0,bO=bB.length;bN<bO;bK=++bN){bF=bB[bK];af.beginPath();bA=bF[bF.length-1];bL=y(A(bP,bC.xyz[bA]),B,br,N,V),bH=bL[0],bG=bL[1];af.moveTo(bH+p,bG+az);for(bM=0,bE=bF.length;bM<bE;bM++){bI=bF[bM];bJ=y(A(bP,bC.xyz[bI]),B,br,N,V),bH=bJ[0],bG=bJ[1];af.lineTo(bH+p,bG+az)}bx=ah(bC.face_class[bK]);bD=(function(){var bQ,bS,bR;bS=[];for(bR=0,bQ=bF.length;bR<bQ;bR++){bI=bF[bR];bS.push(bC.xyz[bI])}return bS})();by=E(al(bD),bp([1,-1,0]));bx=d((by/2+0.5)*0.7+0.3,bx);if(h==="fill"||h==="fillstroke"){af.fillStyle="rgba("+(Z(bx[0]*255))+", "+(Z(bx[1]*255))+", "+(Z(bx[2]*255))+", "+1+")";af.fill();af.strokeStyle="rgba("+(Z(bx[0]*255))+", "+(Z(bx[1]*255))+", "+(Z(bx[2]*255))+", "+1+")";af.stroke()}if(h==="fillstroke"){af.fillStyle="rgba("+(Z(bx[0]*255))+", "+(Z(bx[1]*255))+", "+(Z(bx[2]*255))+", "+1+")";af.fill();af.strokeStyle="rgba(0,0,0, .3)";af.stroke()}if(h==="stroke"){af.strokeStyle="rgba(0,0,0, .8)";af.stroke()}}return bC.xyz=bz};aE=function(){var bA,by,bx,bB,bz;aP();bz=[];for(bA=by=0,bx=Q.length;by<bx;bA=++by){bB=Q[bA];bz.push(S(bB,[0+3*bA,0,3]))}return bz};ay=function(){var bA,by,bx,bB,bz;bz=[];for(bA=by=0,bx=Q.length;by<bx;bA=++by){bB=Q[bA];$("#basicstats").text(bB.data());bz.push($("#morestats").text(bB.moreData()))}return bz};bj=function(){var bz,bA,by,bx,bB;aP();bz=(2*Math.PI)/180*x.getSeconds()*0.1;for(bA=by=0,bx=Q.length;by<bx;bA=++by){bB=Q[bA];S(bB,[0+3*bA,0,3])}return setTimeout(bj,100)};$(function(){var by,bx;aN();bx=bs();if("recipe" in bx){by=[bx.recipe];$("#spec").val(by)}else{by=[be(a7)];$("#spec").val(by);at()}if("palette" in bx){a3=bx.palette.split(/\s+/g);at()}$("#palette").val(a3.reduce(function(bz,bA){return bz+" "+bA}));Q=_.map(by,function(bz){return bu(bz)});ay();aE();$("#spec").change(function(bz){by=$("#spec").val().split(/\s+/g).slice(0,2);Q=_.map(by,function(bA){return bu(bA)});ay();at();return aE()});$("#palette").change(function(bz){a3=$(this).val().split(/\s+/g);at();return aE()});$("#poly").mousewheel(function(bB,bC,bA,bz){bB.preventDefault();V*=(10+bC)/10;return aE()});$("#poly").mousedown(function(bz){var bA;bz.preventDefault();ap=true;Y=bz.clientX-$(this).offset().left;X=bz.clientY-($(this).offset().top-$(window).scrollTop());bA=aO(Y,X,p,az,B,br,N,V);if(bA[0]*bA[1]*bA[2]*0===0){aJ=bA}return am=M(k)});$("#poly").mouseup(function(bz){bz.preventDefault();return ap=false});$("#poly").mouseleave(function(bz){bz.preventDefault();return ap=false});$("#poly").mousemove(function(bC){var bA,bz,bB;bC.preventDefault();if(ap){bA=bC.clientX-$(this).offset().left;bz=bC.clientY-($(this).offset().top-$(window).scrollTop());bB=aO(bA,bz,p,az,B,br,N,V);if(bB[0]*bB[1]*bB[2]*0===0&&aJ[0]*aJ[1]*aJ[2]*0===0){k=aI(aG(aJ,bB),am)}return aE()}});$("#strokeonly").click(function(bz){h="stroke";return aE()});$("#fillonly").click(function(bz){h="fill";return aE()});$("#fillandstroke").click(function(bz){h="fillstroke";return aE()});$("#siderot").click(function(bz){k=aX(aM/2,0,1,0);return aE()});$("#toprot").click(function(bz){k=aX(aM/2,1,0,0);return aE()});$("#frontrot").click(function(bz){k=j(0,0,0);return aE()});$("#pngsavebutton").click(function(bC){var bB,bA,bz;bB=$("#poly")[0];bz=$("#spec").val().split(/\s+/g)[0];bA="polyhedronisme-"+bz.replace(/\([^\)]+\)/g,"")+".png";return bB.toBlob(function(bD){return saveAs(bD,bA)})});$("#objsavebutton").click(function(bC){var bA,bB,bz;bB=Q[0].toOBJ();bz=$("#spec").val().split(/\s+/g)[0];bA="polyhedronisme-"+bz.replace(/\([^\)]+\)/g,"")+".obj";return aH(bB,bA)});return $("#x3dsavebutton").click(function(bC){var bA,bz,bB,bD;bB=ac(Q[0],true);bD=bB.toVRML();bz=$("#spec").val().split(/\s+/g)[0];bA="polyhedronisme-"+bz.replace(/\([^\)]+\)/g,"")+".wrl";return aH(bD,bA)})})}).call(this);