*/
protected void computeParameters() {
int w, h;
if (ul == null)
ul = new Point(0, 0); //HACK
// quick calculate the maxscale
maxscale = CADRG_calc_maxscale();
if (scale > maxscale)
scale = maxscale;
// Compute the "ADRG" scale, which gets used below.
double adrgscale = 1000000.0 / scale; // 1 million (from ADRG
// spec)
if (adrgscale > CADRG_SCALE_LIMIT) {
Debug.message("proj", "CADRG: adrgscale > CADRG_SCALE_LIMIT");
adrgscale = CADRG_SCALE_LIMIT;
}
// Compute the y pixel constant based on scale.
y_pix_constant = CADRG_y_pix_constant(adrgscale);
if (Debug.debugging("proj")) {
Debug.output("Y pix constant = " + y_pix_constant);
}
// What zone are we in?
zone = getZone(ProjMath.radToDeg(ctrLat), y_pix_constant);
if (Debug.debugging("proj")) {
Debug.output("Zone = " + zone);
}
// Compute the x pixel constant, based on scale and zone.
x_pix_constant = CADRG_x_pix_constant(adrgscale, zone);
if (Debug.debugging("proj")) {
Debug.output("x_pix_constant = " + x_pix_constant);
}
// Now I can compute the world coordinate.
if (world == null)
world = new Point(0, 0);
world.x = (int) ProjMath.roundAdjust(x_pix_constant);
world.y = (int) ProjMath.roundAdjust(y_pix_constant * 4.0 / 2.0);
Debug.message("proj", "world = " + world.x + "," + world.y);
// Compute scaled pixels per RADIAN, not SCOORD
spps_x = (double) x_pix_constant / MoreMath.TWO_PI/* MoreMath.DEG_TO_SC(360) */;
spps_y = (double) y_pix_constant / MoreMath.HALF_PI/* MoreMath.DEG_TO_SC(90) */;
Debug.message("proj", "spps = " + spps_x + "," + spps_y);
// Fix the "small world" situation, computing ox, oy.
if (width > world.x) {
Debug.message("proj", "CADRG: fixing small world");
w = world.x;
// ox = (int) ProjMath.roundAdjust((width - w) / 2.0);
} else {
w = width;
// ox = 0;
}
if (height > world.y) {
h = (int) world.y;
oy = (int) ProjMath.roundAdjust((height - h) / 2.0);
} else {
h = height;
oy = 0;
}
// compute the "upper left" adjustment.
long temp = (long) ProjMath.roundAdjust(spps_y * ctrLat);
if (Debug.debugging("proj")) {
Debug.output("CADRG.temp = " + temp);
}
if (ul == null)
ul = new Point(0, 0);
ul.x = (int) ProjMath.roundAdjust(-w / 2.0);
if ((temp != 0) && (oy != 0)) {
ul.y = (int) ProjMath.roundAdjust(h / 2.0);
} else {
ul.y = (int) temp + (int) ProjMath.roundAdjust(h / 2.0);