From 7bf6b08fcda6c2fc37405e4a77f23b73191bd671 Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Mon, 14 Nov 2005 22:28:49 +0100 Subject: fix ProjectionSphaeric::comp_params() sprinkle some const add copy constructor to Hill --- src/ProjectionSphaeric.cxx | 87 ++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 42 deletions(-) (limited to 'src/ProjectionSphaeric.cxx') diff --git a/src/ProjectionSphaeric.cxx b/src/ProjectionSphaeric.cxx index 528dd23..8ace1c0 100644 --- a/src/ProjectionSphaeric.cxx +++ b/src/ProjectionSphaeric.cxx @@ -24,63 +24,67 @@ #include "ProjectionSphaeric.H" -#define TILT_DIFF_UNDEF 100000.0 +#define BEST_UNDEF 10000000.0 int -ProjectionSphaeric::comp_params(Hill *m1, Hill *m2, ViewParams *parms) { - Hill *tmp; - double a_center_tmp[2], scale_tmp, a_nick_tmp[2]; - double a_tilt_tmp[2], a_tilt_diff[2]; - double a_tilt1, a_tilt2; +ProjectionSphaeric::comp_params(const Hill *m1, const Hill *m2, ViewParams *parms) { + const Hill *m_tmp; + Hill *tmp_m1; + Hill *tmp_m2; + double val; + ViewParams best, tmp; + double best_val = BEST_UNDEF; double d_m1_2, d_m2_2, d_m1_m2_2; - int i; + int i, j; - if (m1->x > m2->x) { - tmp = m1; + if (m1->x < m2->x) { + m_tmp = m1; m1 = m2; - m2 = tmp; + m2 = m_tmp; } d_m1_2 = pow(m1->x, 2.0) + pow(m1->y, 2.0); d_m2_2 = pow(m2->x, 2.0) + pow(m2->y, 2.0); d_m1_m2_2 = pow(m1->x - m2->x, 2.0) + pow(m1->y - m2->y, 2.0); - scale_tmp = comp_scale(m1, m2, d_m1_m2_2); + tmp.scale = comp_scale(m1, m2, d_m1_m2_2); - for(i=0; i<2; i++) { // we need to try two solutions ... - a_tilt_diff[i] = TILT_DIFF_UNDEF; // initialize to a high value - - a_center_tmp[i] = comp_dir_view(m1, m2, d_m1_2, d_m2_2, scale_tmp, - i==0?1.0:-1.0); - a_nick_tmp[i] = comp_nick_view(m1, m2, d_m1_2, scale_tmp, a_center_tmp[i]); - - if (isnan(a_center_tmp[i]) || isnan(scale_tmp) || isnan(a_nick_tmp[i])) { - ; - } else { - a_tilt1 = comp_tilt_view(m1, scale_tmp, a_center_tmp[i], a_nick_tmp[i]); - a_tilt2 = comp_tilt_view(m2, scale_tmp, a_center_tmp[i], a_nick_tmp[i]); - - if (!isnan(a_tilt1) && !isnan(a_tilt2)) { - a_tilt_diff[i] = fabs(a_tilt1 - a_tilt2); - } + for(i=0; i<2; i++) { // we need to try four possible solutions ... + for(j=0; j<2; j++) { + tmp.a_center = comp_dir_view(m1, m2, d_m1_2, d_m2_2, + tmp.scale, i==0?1.0:-1.0); + tmp.a_nick = comp_nick_view(m1, m2, d_m1_2, tmp.scale, tmp.a_center, + j==0?1.0:-1.0); // use the point with greater distance from center for tilt computation if (d_m1_2 > d_m2_2) { - a_tilt_tmp[i] = a_tilt1; + tmp.a_tilt = comp_tilt_view(m1, tmp.scale, tmp.a_center, tmp.a_nick); } else { - a_tilt_tmp[i] = a_tilt2; + tmp.a_tilt = comp_tilt_view(m2, tmp.scale, tmp.a_center, tmp.a_nick); + } + + if (isnan(tmp.a_center) || isnan(tmp.scale) || + isnan(tmp.a_nick) || isnan(tmp.a_tilt)) { + ; + } else { + tmp_m1 = new Hill(*m1); + tmp_m2 = new Hill(*m2); + set_coordinates(tmp_m1, &tmp); + set_coordinates(tmp_m2, &tmp); + val = sqrt(pow(tmp_m1->x - m1->x, 2.0) + pow(tmp_m1->y - m1->y, 2.0)); + val += sqrt(pow(tmp_m2->x - m2->x, 2.0) + pow(tmp_m2->y - m2->y, 2.0)); + delete(tmp_m1); + delete(tmp_m2); + if (val < best_val) { + best_val = val; + best = tmp; + } } } } - i = a_tilt_diff[0]a_center = a_center_tmp[i]; - parms->scale = scale_tmp; - parms->a_nick = a_nick_tmp[i]; - parms->a_tilt = a_tilt_tmp[i]; + if (best_val < BEST_UNDEF) { + *parms = best; return 0; } else { return 1; @@ -100,7 +104,7 @@ ProjectionSphaeric::set_coordinates(Hill *m, const ViewParams *parms) { } double -ProjectionSphaeric::comp_scale(Hill *m1, Hill *m2, double d_m1_m2_2) { +ProjectionSphaeric::comp_scale(const Hill *m1, const Hill *m2, double d_m1_m2_2) { double sign1 = 1.0; double nick_m1 = m1->a_nick; double nick_m2 = m2->a_nick; @@ -113,7 +117,7 @@ ProjectionSphaeric::comp_scale(Hill *m1, Hill *m2, double d_m1_m2_2) { // using the sign3 parameter one can choose between the two possible solutions // sign3 must be 1.0 or -1.0 double -ProjectionSphaeric::comp_dir_view(Hill *m1, Hill *m2, double d_m1_2, double d_m2_2, double scale, double sign3) { +ProjectionSphaeric::comp_dir_view(const Hill *m1, const Hill *m2, double d_m1_2, double d_m2_2, double scale, double sign3) { double dir_view; double nick_m1 = m1->a_nick; double nick_m2 = m2->a_nick; @@ -127,9 +131,8 @@ ProjectionSphaeric::comp_dir_view(Hill *m1, Hill *m2, double d_m1_2, double d_m2 double -ProjectionSphaeric::comp_nick_view(Hill *m1, Hill *m2, double d_m1_2, double scale, double dir_view) { +ProjectionSphaeric::comp_nick_view(const Hill *m1, const Hill *m2, double d_m1_2, double scale, double dir_view, double sign1) { double nick_view; - double sign1 = -1.0; double nick_m1 = m1->a_nick; double dir_m1 = m1->alph; @@ -139,7 +142,7 @@ ProjectionSphaeric::comp_nick_view(Hill *m1, Hill *m2, double d_m1_2, double sca } double -ProjectionSphaeric::comp_tilt_view(Hill *m, double scale, double dir_view, double nick_view) { +ProjectionSphaeric::comp_tilt_view(const Hill *m, double scale, double dir_view, double nick_view) { double sin_a_tilt1, sin_a_tilt2, sin_a_tilt, res; double x_tmp = (m->alph - dir_view) * scale; double y_tmp = (m->a_nick - nick_view) * scale; -- cgit v1.2.3