inline LL triarea(plane::iterator x){ LL res=0; if (x!=t.begin()) res+=traparea(pre(x),x); if (next(x)!=t.end()) res+=traparea(x,next(x)); if (x!=t.begin() && next(x)!=t.end()) res+=traparea(next(x),pre(x)); return res; }
inline LL traparea(plane::iterator p0,plane::iterator p1){ return traparea(p0->first,p0->second,p1->first,p1->second); }
float egrid (float (*func)(float a[], float x, float y), float xmin, float xmax, float ymin, float ymax, float a[]) { void minmaxphi (float xmin, float xmax, float ymin, float ymax, float a[], float *minphi, float *maxphi, int quad[]); void minmaxrad (float xmin, float xmax, float ymin, float ymax, float a[], float *minr, float *maxr); float phi2xy (float phi, float r, float a[], float *x, float *y); void swap (float *min, float *max); float traparea (float a[], float cphi, float r); float xf[33], yf[3], minphi, maxphi, minr, maxr, x, y, theta, r, cphi, flux, dphi, dflux, temp; int i, done = 0, centpix = 0, quad[5]={0, 0, 0, 0, 0}; a[9] = -(a[9] - PI/2.); /* A kludge, due to the definition of PA in nuker.c */ if (xmin > xmax) swap (&xmin, &xmax); if (ymin > ymax) swap (&ymin, &ymax); minmaxphi (xmin, xmax, ymin, ymax, a, &minphi, &maxphi, quad); minmaxrad (xmin, xmax, ymin, ymax, a, &minr, &maxr); if ((xmin <= a[1] && xmax >= a[1]) && (ymin <= a[2] && ymax >= a[2]) || quad[0]==1) { minr = 0.; centpix = 1; if ((xmin < a[1] && xmax > a[1]) && (ymin < a[2] && ymax > a[2])) { minphi = 0.; maxphi = 2. * PI; }; } maxr = maxr / a[8]; /* Make sure we integrate out */ minr = minr * a[8]; /* and in far enough. */ if (minr == 0.) centpix = 1; /* If the center is on the boundary */ flux = 0.; dphi = DELPHI /180. * PI; for (cphi = minphi; cphi <= maxphi; cphi += dphi) { r = maxr; done = 0; while (!done && r >= minr) { r = r / (1+ASTEP); phi2xy (cphi, r, a, &x, &y); if (x >= xmin && x <= xmax && y >= ymin && y <= ymax) { dflux = func (a, x, y) * traparea (a, cphi, r); flux += dflux; if (centpix && (dflux/flux) < 1.e-5) done = 1; } else if (r < minr) done = 1; }; }; a[9] = (-a[9] + PI/2.); /* Convert back to the regular def. of PA */ return (flux); }