#include #include #include #include typedef unsigned int nd; // 32 bits typedef double R; #define N 100000 #define C const nd sp[N][8]; // mutable space for blob as octree C nd E = 0, F = 255; nd f = 256; R sq(R x){return x*x;} // R max(R x, R y){return x 1+r || fabs(y) > 1+r || fabs(z) > 1+r) return E; // beyond some face if(sh(x)+sh(y)+sh(z)1 || fabs(y)>1 || fabs(z)>1){ // center not in cube if( fabs(x)<1 && sg(y)+sg(z) > r*r // between yz planes but outside rounded box || fabs(y)<1 && sg(x)+sg(z) > r*r || fabs(z)<1 && sg(x)+sg(y) > r*r) return E; if(sg(x)+sg(y)+sg(z) > r*r) return E;} if(d) {nd new = buy(); char pure=1; if(0) printf("%11.6f %11.6f %11.6f, r=%11.6f, nd=%d\n", x, y, z, r, new); for(int j=0; j<8; ++j) { nd n = ball(2*x+(j&4?-1:1), 2*y+(j&2?-1:1), 2*z+(j&1?-1:1), 2*r, d-1); pure = pure && (n==F || n==E); sp[new][j] = n;} if(pure) {int a=0; for(int j=0; j<8; ++j) a = (a<<1) | (sp[new][j]==F); sell(new); return a;} return new;} return x*x+y*y+z*z>k)&1?255:0; // for j to 255 sp[j] is a cube all of whose children are pure. if(0) pr(256); tst(0, 0, 0, 0.786); pr(f); return 0;}