From 2658022a5f71690c18478d94c64d445aa38a68ee Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Mon, 14 Nov 2005 23:14:58 +0100 Subject: fix wrap-around bug in ProjectionTangential --- src/ProjectionTangential.H | 2 ++ src/ProjectionTangential.cxx | 25 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/ProjectionTangential.H b/src/ProjectionTangential.H index d4646d7..8e7673e 100644 --- a/src/ProjectionTangential.H +++ b/src/ProjectionTangential.H @@ -31,6 +31,8 @@ class ProjectionTangential : public Projection { double comp_scale(double alph_a, double alph_b, double d1, double d2); + double angle_dist(double a1, double a2); + int optimize(const Hill *m1, const Hill *m2, ViewParams *parms); public: diff --git a/src/ProjectionTangential.cxx b/src/ProjectionTangential.cxx index 8297ee4..032005d 100644 --- a/src/ProjectionTangential.cxx +++ b/src/ProjectionTangential.cxx @@ -76,6 +76,27 @@ ProjectionTangential::comp_params(const Hill *m1, const Hill *m2, ViewParams *pa } } +double +ProjectionTangential::angle_dist(double a1, double a2) { + double ret; + + a1 = fmod(a1, 2.0 * pi_d); + if (a1 < 0.0) { + a1 = a1 + 2.0 * pi_d; + } + a2 = fmod(a2, 2.0 * pi_d); + if (a2 < 0.0) { + a2 = a2 + 2.0 * pi_d; + } + + ret = fabs(a1 - a2); + if (ret > pi_d) { + ret = 2.0 * pi_d - ret; + } + + return ret; +} + int ProjectionTangential::optimize(const Hill *m1, const Hill *m2, ViewParams *parms) { int i; @@ -118,10 +139,10 @@ ProjectionTangential::optimize(const Hill *m1, const Hill *m2, ViewParams *parms // atan(tan_dir_view) is not the only possible solution. // Choose the one which is close to m1->alph. - if (fabs(parms->a_center - m1->alph) > pi_d/2.0) { + if (angle_dist(parms->a_center, m1->alph) > pi_d/2.0) { parms->a_center = parms->a_center + pi_d; } - + parms->scale = n_scale; // use the point with greater distance from center for tilt computation -- cgit v1.2.3