p5.prototype.marchingSquares=function(u,p){null==p&&(p=0);let h=[];function s(u,p,h){return h[0]=.5+h[0]+u,h[1]=.5+h[1]+p,h[2]=.5+h[2]+u,h[3]=.5+h[3]+p,h}for(let n=0;n<u.length-1;n++)for(let t=0;t<u[n].length-1;t++)u[n][t]>p&&u[n][t+1]>p&&u[n+1][t]>p&&u[n+1][t+1]>p?(h.push(s(t,n,[0,0,0,1])),h.push(s(t,n,[0,1,1,1])),h.push(s(t,n,[1,1,1,0])),h.push(s(t,n,[1,0,0,0]))):u[n][t]>p&&u[n][t+1]>p&&u[n+1][t]<=p&&u[n+1][t+1]>p?(h.push(s(t,n,[0,0,0,.5])),h.push(s(t,n,[0,.5,.5,1])),h.push(s(t,n,[.5,1,1,1])),h.push(s(t,n,[1,1,1,0])),h.push(s(t,n,[1,0,0,0]))):u[n][t]>p&&u[n][t+1]>p&&u[n+1][t]>p&&u[n+1][t+1]<=p?(h.push(s(t,n,[0,0,0,1])),h.push(s(t,n,[0,1,.5,1])),h.push(s(t,n,[.5,1,1,.5])),h.push(s(t,n,[1,.5,1,0])),h.push(s(t,n,[1,0,0,0]))):u[n][t]>p&&u[n][t+1]>p&&u[n+1][t]<=p&&u[n+1][t+1]<=p?(h.push(s(t,n,[0,0,1,0])),h.push(s(t,n,[1,0,1,.5])),h.push(s(t,n,[1,.5,0,.5])),h.push(s(t,n,[0,.5,0,0]))):u[n][t]>p&&u[n][t+1]<=p&&u[n+1][t]>p&&u[n+1][t+1]>p?(h.push(s(t,n,[0,0,0,1])),h.push(s(t,n,[0,1,1,1])),h.push(s(t,n,[1,1,1,.5])),h.push(s(t,n,[1,.5,.5,0])),h.push(s(t,n,[.5,0,0,0]))):u[n][t]>p&&u[n][t+1]<=p&&u[n+1][t]<=p&&u[n+1][t+1]>p?(h.push(s(t,n,[0,0,0,.5])),h.push(s(t,n,[0,.5,.5,1])),h.push(s(t,n,[.5,1,1,1])),h.push(s(t,n,[1,1,1,.5])),h.push(s(t,n,[1,.5,.5,0])),h.push(s(t,n,[.5,0,0,0]))):u[n][t]>p&&u[n][t+1]<=p&&u[n+1][t]>p&&u[n+1][t+1]<=p?(h.push(s(t,n,[0,0,.5,0])),h.push(s(t,n,[.5,0,.5,1])),h.push(s(t,n,[.5,1,0,1])),h.push(s(t,n,[0,1,0,0]))):u[n][t]>p&&u[n][t+1]<=p&&u[n+1][t]<=p&&u[n+1][t+1]<=p?(h.push(s(t,n,[0,0,.5,0])),h.push(s(t,n,[.5,0,0,.5])),h.push(s(t,n,[0,.5,0,0]))):u[n][t]<=p&&u[n][t+1]>p&&u[n+1][t]>p&&u[n+1][t+1]>p?(h.push(s(t,n,[.5,0,1,0])),h.push(s(t,n,[1,0,1,1])),h.push(s(t,n,[1,1,0,1])),h.push(s(t,n,[0,1,0,.5])),h.push(s(t,n,[0,.5,.5,0]))):u[n][t]<=p&&u[n][t+1]>p&&u[n+1][t]<=p&&u[n+1][t+1]>p?(h.push(s(t,n,[.5,0,1,0])),h.push(s(t,n,[1,0,1,1])),h.push(s(t,n,[1,1,.5,1])),h.push(s(t,n,[.5,1,.5,0]))):u[n][t]<=p&&u[n][t+1]>p&&u[n+1][t]>p&&u[n+1][t+1]<=p?(h.push(s(t,n,[.5,0,1,0])),h.push(s(t,n,[1,0,1,.5])),h.push(s(t,n,[1,.5,.5,1])),h.push(s(t,n,[.5,1,0,1])),h.push(s(t,n,[0,1,0,.5])),h.push(s(t,n,[0,.5,.5,0]))):u[n][t]<=p&&u[n][t+1]>p&&u[n+1][t]<=p&&u[n+1][t+1]<=p?(h.push(s(t,n,[.5,0,1,0])),h.push(s(t,n,[1,0,1,.5])),h.push(s(t,n,[1,.5,.5,0]))):u[n][t]<=p&&u[n][t+1]<=p&&u[n+1][t]>p&&u[n+1][t+1]>p?(h.push(s(t,n,[0,.5,1,.5])),h.push(s(t,n,[1,.5,1,1])),h.push(s(t,n,[1,1,0,1])),h.push(s(t,n,[0,1,0,.5]))):u[n][t]<=p&&u[n][t+1]<=p&&u[n+1][t]<=p&&u[n+1][t+1]>p?(h.push(s(t,n,[1,.5,1,1])),h.push(s(t,n,[1,1,.5,1])),h.push(s(t,n,[.5,1,1,.5]))):u[n][t]<=p&&u[n][t+1]<=p&&u[n+1][t]>p&&u[n+1][t+1]<=p&&(h.push(s(t,n,[0,.5,0,1])),h.push(s(t,n,[0,1,.5,1])),h.push(s(t,n,[.5,1,0,.5])));let n=[];return h.map((function(u){h.map((function(p){var h,s;u!==p&&(s=p,((h=u)[0]==s[0]&&h[1]==s[1]&&h[2]==s[2]&&h[3]==s[3]||h[0]==s[2]&&h[1]==s[3]&&h[2]==s[0]&&h[3]==s[1])&&n.push(u))}))})),n.map((function(u){h.splice(h.indexOf(u),1)})),h};