summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-04-01 13:16:44 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-04-01 13:16:44 +0200
commit9d8a88c1a46cc95f69e9bc0e50ed1134bef6c715 (patch)
treefa40a289a4fb129420c4c3099df0471c4236d9b4 /src
parentc368443056c0eda834f4924ca36c141d8d97f89e (diff)
fix bug in cylindrical projection
If one peak is "left" and one is "right" of north, cylindrical projection was not able to compute proper viewing parameters. This is fixed by adjusting alpha angles of known hills to be increasing with x.
Diffstat (limited to 'src')
-rw-r--r--src/Hill.H3
-rw-r--r--src/Hill.cxx20
-rw-r--r--src/ProjectionCylindrical.H1
-rw-r--r--src/ProjectionCylindrical.cxx16
-rw-r--r--src/ProjectionLSQ.H2
5 files changed, 39 insertions, 3 deletions
diff --git a/src/Hill.H b/src/Hill.H
index ac4917a..d408dc7 100644
--- a/src/Hill.H
+++ b/src/Hill.H
@@ -45,7 +45,8 @@ class Hills {
SORT_ALPHA,
SORT_PHI,
SORT_NAME,
- SORT_LABEL_Y
+ SORT_LABEL_Y,
+ SORT_X
} SortType;
Hills();
diff --git a/src/Hill.cxx b/src/Hill.cxx
index f45c197..b053568 100644
--- a/src/Hill.cxx
+++ b/src/Hill.cxx
@@ -242,6 +242,23 @@ comp_mountains_label_y(const void *n1, const void *n2) {
}
}
+static int
+comp_mountains_x(const void *n1, const void *n2) {
+ Hill *m1 = *(Hill **)n1;
+ Hill *m2 = *(Hill **)n2;
+
+ if (m1 && m2) {
+ if (m2->x < m1->x)
+ return 1;
+ else if (m2->x > m1->x)
+ return -1;
+ else
+ return 0;
+ } else {
+ return 0;
+ }
+}
+
void
Hills::sort(SortType t) {
int (*cmp)(const void *, const void *);
@@ -262,6 +279,9 @@ Hills::sort(SortType t) {
case SORT_LABEL_Y:
cmp = comp_mountains_label_y;
break;
+ case SORT_X:
+ cmp = comp_mountains_x;
+ break;
default:
fprintf(stderr, "ERROR: Unknown sort type %d\n", t);
return;
diff --git a/src/ProjectionCylindrical.H b/src/ProjectionCylindrical.H
index 41bad29..06709c4 100644
--- a/src/ProjectionCylindrical.H
+++ b/src/ProjectionCylindrical.H
@@ -13,6 +13,7 @@ class ProjectionCylindrical : public ProjectionLSQ {
public:
virtual double get_view_angle() {return 6.2831853;}; /* 360 deg */
+ virtual int comp_params(const Hills *h, ViewParams *parms);
#define ARGS double c_view, double c_nick, double c_tilt, double scale, double k0, double k1, double x0, double m_view, double m_nick
virtual double mac_x(ARGS);
diff --git a/src/ProjectionCylindrical.cxx b/src/ProjectionCylindrical.cxx
index d41e5f8..094b494 100644
--- a/src/ProjectionCylindrical.cxx
+++ b/src/ProjectionCylindrical.cxx
@@ -1,5 +1,5 @@
//
-// Copyright 2006 Johannes Hofmann <Johannes.Hofmann@gmx.de>
+// Copyright 2006-2009 Johannes Hofmann <Johannes.Hofmann@gmx.de>
//
// This software may be used and distributed according to the terms
// of the GNU General Public License, incorporated herein by reference.
@@ -10,3 +10,17 @@
#include "ProjectionCylindrical.H"
#include "ProjectionCylindrical_funcs.cxx"
+
+int
+ProjectionCylindrical::comp_params(const Hills *h, ViewParams *parms) {
+ Hills h_monotone(h);
+
+ h_monotone.sort(Hills::SORT_X);
+
+ // ensure that alpha is increasing with x.
+ for (int i = 1; i < h_monotone.get_num(); i++)
+ if (h_monotone.get(i)->alph < h_monotone.get(i - 1)->alph)
+ h_monotone.get(i)->alph += asin(1.0) * 4.0; // += 2pi
+
+ return ProjectionLSQ::comp_params(&h_monotone, parms);
+}
diff --git a/src/ProjectionLSQ.H b/src/ProjectionLSQ.H
index 626c513..a380b4c 100644
--- a/src/ProjectionLSQ.H
+++ b/src/ProjectionLSQ.H
@@ -32,7 +32,7 @@ class ProjectionLSQ {
void get_coordinates(double a_view, double a_nick,
const ViewParams *parms, double *x, double *y);
- int comp_params(const Hills *h, ViewParams *parms);
+ virtual int comp_params(const Hills *h, ViewParams *parms);
virtual double get_view_angle();