//--------------------------------------------------------------------------- Projection_ZYGRIB::Projection_ZYGRIB (const Projection_ZYGRIB &model) : Projection(model) { dscale = 1.2; setMapPointInScreen(CX, CY, W/2, H/2); setScale(scale); }
//==================================================================================== //==================================================================================== //--------------------------------------------------------------------------- Projection_ZYGRIB::Projection_ZYGRIB (int w, int h, double cx, double cy, double scale) : Projection(w, h, cx, cy, scale) { //printf("init Projection_ZYGRIB : W=%d H=%d CX=%f CY=%f scale=%f\n", W,H,CX,CY,scale); dscale = 1.2; setMapPointInScreen(CX, CY, W/2, H/2); setScale(scale); }
//-------------------------------------------------------------- void Projection_ZYGRIB::setVisibleArea (double x0, double y0, double x1, double y1) { if (x1 == x0) { x1 = x0+0.1; } if (y1 == y0) { y1 = y0+0.1; } if (x0 > x1) { double a = x1; x1 = x0; x0 = a; } if (y0 > y1) { double a = y1; y1 = y0; y0 = a; } while (x0 > 360) { x0 -= 360; x1 -= 360; } while (x0 < -360) { x0 += 360; x1 += 360; } while (y0 <= -98) { y0 += 10; y1 += 10; } while (y1 >= 98) { y0 -= 10; y1 -= 10; } double sx, sy; // Nouvelle position du centre setMapPointInScreen( (x0+x1)/2.0, (y0+y1)/2.0 , W/2, H/2); sx = fabs(W/(x1-x0)); sy = fabs(H/(y1-y0)) / dscale; scale = (sx<sy) ? sx : sy; setScale(scale); }
//-------------------------------------------------------------- void Projection::move (double dx, double dy) { double px,py; screen2map(W/2,H/2, &px,&py); setMapPointInScreen(px, py, (int)(W/2+dx*W+0.5), (int)(H/2-dy*H+0.5)); }
//-------------------------------------------------------------- void Projection::setCentralPixel (int pi, int pj) { double x, y; screen2map(pi, pj, &x, &y); setMapPointInScreen(x, y, W/2, H/2); }
//-------------------------------------------------------------- void Projection_libproj::setVisibleArea(double x0, double y0, double x1, double y1) { //printf("setVisibleArea X(%f %f) Y(%f %f)\n", x0, x1,y0,y1); if (x1 == x0) { x1 = x0+0.1; } if (y1 == y0) { y1 = y0+0.1; } if (x0 > x1) { double a = x1; x1 = x0; x0 = a; } if (y0 > y1) { double a = y1; y1 = y0; y0 = a; } while (x0 > 360) { x0 -= 360; x1 -= 360; } while (x0 < -360) { x0 += 360; x1 += 360; } while (y0 <= -98) { y0 += 10; y1 += 10; } while (y1 >= 98) { y0 -= 10; y1 -= 10; } if (x0 > 180. && x1 > 180.) { // in this case screen2map returns -180 .. 0 x0 -= 360.; x1 -= 360.; } double sx, sy; // On cherche l'échelle qui permet d'englober la zone // En commençant par placer le coin haut gauche (x0,y1) de la zone int n; double dsc, smin, stest, smax, xx,yy; sx = sy = scale; // Vertical scale stest = 0; smin = 0.01; smax = scalemax; n = 0; do { dsc = stest; stest = (smin+smax)/2.0; dsc = fabs(dsc-stest); setScale(stest); setMapPointInScreen(x0,y1, 0,0); screen2map(W, H, &xx,&yy); if (yy < y0) smin = stest; else smax = stest; //printf("Y %3d smin=%f smax=%f %f -> %f\n", n,smin,smax, y1,yy); n ++; } while (n<30 && dsc>1e-4); sy = stest; // Horizontal scale stest = 0; smin = 0.01; smax = scalemax; n = 0; do { dsc = stest; stest = (smin+smax)/2.0; dsc = fabs(dsc-stest); setScale(stest); setMapPointInScreen(x0,y1, 0,0); screen2map(W, H, &xx,&yy); if (xx > x1) smin = stest; else smax = stest; //printf("X %3d stest=%f %f -> %f\n", n,stest, x1,xx); n ++; } while (n<30 && dsc>1e-4); sx = stest; if (sx < sy) { setScale(sx); setMapPointInScreen(x0, (y0+y1)/2, 0,H/2); //printf("1\n"); } else { //printf("2\n"); setScale(sy); setMapPointInScreen( (x0+x1)/2, y0, W/2,H); } }