From 92c343bcf05ee3491d7cea619e9f63bcdbf67d1d Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sun, 8 May 2005 15:56:48 +0000 Subject: cleanups cleanups --- src/Panorama.cxx | 94 ++++++++++++++++++++++++++++++++++---------------------- src/gipfel.cxx | 12 ++++---- 2 files changed, 63 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/Panorama.cxx b/src/Panorama.cxx index ff1a3a0..b3d1dad 100644 --- a/src/Panorama.cxx +++ b/src/Panorama.cxx @@ -1,5 +1,5 @@ // -// "$Id: Panorama.cxx,v 1.32 2005/05/05 19:44:08 hofmann Exp $" +// "$Id: Panorama.cxx,v 1.33 2005/05/08 17:56:48 hofmann Exp $" // // Panorama routines. // @@ -211,12 +211,16 @@ Panorama::guess(Mountains *p, Mountain *m1) { } } - a_center = a_center_best; - a_nick = a_nick_best; - a_tilt = a_tilt_best; - scale = scale_best; - fprintf(stderr, "best %f\n", best); - fprintf(stderr, "center = %f, scale = %f, nick=%f\n", a_center /deg2rad, scale, a_nick/deg2rad); + if (best < 4000.0) { + a_center = a_center_best; + a_nick = a_nick_best; + a_tilt = a_tilt_best; + scale = scale_best; + fprintf(stderr, "best %f\n", best); + fprintf(stderr, "center = %f, scale = %f, nick=%f\n", a_center /deg2rad, scale, a_nick/deg2rad); + } else { + fprintf(stderr, "No solution found.\n"); + } update_visible_mountains(); return 0; } @@ -224,6 +228,7 @@ Panorama::guess(Mountains *p, Mountain *m1) { int Panorama::comp_params(Mountain *m1, Mountain *m2) { Mountain *tmp; + double a_center_tmp, scale_tmp, a_nick_tmp; if (m1->x > m2->x) { tmp = m1; @@ -237,16 +242,25 @@ Panorama::comp_params(Mountain *m1, Mountain *m2) { x2 = m2->x; y2 = m2->y; - a_center = comp_center_angle(m1->alph, m2->alph, x1, x2); - scale = comp_scale(m1->alph, m2->alph, x1, x2); - a_nick = atan ((y1 + tan(m1->a_nick) * scale) / - (scale - y1 * tan(m1->a_nick))); + a_center_tmp = comp_center_angle(m1->alph, m2->alph, x1, x2); + scale_tmp = comp_scale(m1->alph, m2->alph, x1, x2); + a_nick_tmp = atan ((y1 + tan(m1->a_nick) * scale) / + (scale - y1 * tan(m1->a_nick))); - optimize(m1, m2); + if (isnan(a_center_tmp) || isnan(scale_tmp) || isnan(a_nick_tmp)) { + return 1; + } else { + + a_center = a_center_tmp; + scale = scale_tmp; + a_nick = a_nick_tmp; - update_visible_mountains(); + optimize(m1, m2); - return 0; + update_visible_mountains(); + + return 0; + } } int @@ -279,36 +293,42 @@ Panorama::optimize(Mountain *m1, Mountain *m2) { d_m1_2, d_m2_2, d_m1_m2_2); } - a_nick = atan(tan_nick_view); - a_center = atan(tan_dir_view); - - if (a_center > pi_d) { - a_center = a_center - 2.0 * pi_d; - } else if (a_center < -pi_d) { - a_center = a_center + 2.0 * pi_d; - } + if (isnan(tan_dir_view) || isnan(tan_nick_view) || + isnan(tan_dir_view) || isnan(n_scale)) { + fprintf(stderr, "No solution found.\n"); + return 1; + } else { - // atan(tan_dir_view) is not the only possible solution. - // Choose the one which is close to m1->alph. - if (fabs(a_center - m1->alph) > pi_d/2.0) { - a_center = a_center + pi_d; - } + a_nick = atan(tan_nick_view); + a_center = atan(tan_dir_view); + + if (a_center > pi_d) { + a_center = a_center - 2.0 * pi_d; + } else if (a_center < -pi_d) { + a_center = a_center + 2.0 * pi_d; + } + + // atan(tan_dir_view) is not the only possible solution. + // Choose the one which is close to m1->alph. + if (fabs(a_center - m1->alph) > pi_d/2.0) { + a_center = a_center + pi_d; + } - scale = n_scale; + scale = n_scale; - // use the point with greater distance from center for tilt computation - if (d_m1_2 > d_m2_2) { + // use the point with greater distance from center for tilt computation + if (d_m1_2 > d_m2_2) { a_tilt = comp_tilt(tan_nick_view, tan_dir_view, n_scale, tan_nick_m1, tan_dir_m1, (double) x1, (double) y1); - } else { - a_tilt = comp_tilt(tan_nick_view, tan_dir_view, n_scale, - tan_nick_m2, tan_dir_m2, - (double) x2, (double) y2); - } - + } else { + a_tilt = comp_tilt(tan_nick_view, tan_dir_view, n_scale, + tan_nick_m2, tan_dir_m2, + (double) x2, (double) y2); + } - return 0; + return 0; + } } void diff --git a/src/gipfel.cxx b/src/gipfel.cxx index 87689a3..d855dd1 100644 --- a/src/gipfel.cxx +++ b/src/gipfel.cxx @@ -1,5 +1,5 @@ // -// "$Id: gipfel.cxx,v 1.19 2005/05/05 19:56:38 hofmann Exp $" +// "$Id: gipfel.cxx,v 1.20 2005/05/08 17:56:48 hofmann Exp $" // // flpsed program. // @@ -178,7 +178,7 @@ int main(int argc, char** argv) { m = new Fl_Menu_Bar(0, 0, 800, 30); m->menu(menuitems); - s_center = new Fl_Value_Slider(50, 30, 650, 15, "direction"); + s_center = new Fl_Value_Slider(50, 30, 650, 15, "Direction"); s_center->type(1); s_center->box(FL_THIN_DOWN_BOX); s_center->labelsize(10); @@ -188,7 +188,7 @@ int main(int argc, char** argv) { s_center->callback((Fl_Callback*)angle_cb); s_center->align(FL_ALIGN_LEFT); - s_scale = new Fl_Slider(100, 45, 160, 15, "scale"); + s_scale = new Fl_Slider(100, 45, 160, 15, "Scale"); s_scale->type(1); s_scale->box(FL_THIN_DOWN_BOX); s_scale->labelsize(10); @@ -198,7 +198,7 @@ int main(int argc, char** argv) { s_scale->callback((Fl_Callback*)scale_cb); s_scale->align(FL_ALIGN_LEFT); - s_nick = new Fl_Slider(360, 45, 160, 15, "nick"); + s_nick = new Fl_Slider(360, 45, 160, 15, "Nick"); s_nick->type(1); s_nick->box(FL_THIN_DOWN_BOX); s_nick->labelsize(10); @@ -208,7 +208,7 @@ int main(int argc, char** argv) { s_nick->callback((Fl_Callback*)nick_cb); s_nick->align(FL_ALIGN_LEFT); - s_tilt = new Fl_Slider(50, 60, 160, 15, "tilt"); + s_tilt = new Fl_Slider(50, 60, 160, 15, "Tilt"); s_tilt->type(1); s_tilt->box(FL_THIN_DOWN_BOX); s_tilt->labelsize(10); @@ -218,7 +218,7 @@ int main(int argc, char** argv) { s_tilt->callback((Fl_Callback*)tilt_cb); s_tilt->align(FL_ALIGN_LEFT); - Fl_Slider* s_height_dist = new Fl_Slider(620, 45, 160, 15, "height-dist"); + Fl_Slider* s_height_dist = new Fl_Slider(620, 45, 160, 15, "Visibility"); s_height_dist->type(1); s_height_dist->box(FL_THIN_DOWN_BOX); s_height_dist->labelsize(10); -- cgit v1.2.3