summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-03-29 14:10:09 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-03-29 14:10:09 +0200
commit50c4c4b9ce488f2c7691ea26bf670b0abfc797cd (patch)
treee0fa3d1cbdee56225514de49139e073d48a555b6 /src
parentd2eca5bbe81dc4a899c97f1423c392554113f852 (diff)
change Hills::sort() interface
Diffstat (limited to 'src')
-rw-r--r--src/GipfelWidget.cxx2
-rw-r--r--src/Hill.H6
-rw-r--r--src/Hill.cxx62
-rw-r--r--src/Panorama.cxx2
-rw-r--r--src/choose_hill.cxx2
5 files changed, 37 insertions, 37 deletions
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index f0403cf..e334484 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -369,7 +369,7 @@ GipfelWidget::set_labels(Hills *v) {
colliding.add(n);
}
- colliding.sort_label_y();
+ colliding.sort(Hills::SORT_LABEL_Y);
for (int j = 0; j < colliding.get_num(); j++) {
Hill *n = colliding.get(j);
diff --git a/src/Hill.H b/src/Hill.H
index b4ced70..ac4917a 100644
--- a/src/Hill.H
+++ b/src/Hill.H
@@ -42,6 +42,7 @@ class Hills {
public:
typedef enum {
+ SORT_ALPHA,
SORT_PHI,
SORT_NAME,
SORT_LABEL_Y
@@ -56,10 +57,7 @@ class Hills {
void add(Hill *m);
void remove(const Hill *m);
void add(Hills *h);
- void sort_phi();
- void sort_name();
- void sort_label_y();
- void sort();
+ void sort(SortType t);
void clear();
void clobber();
int contains(const Hill *m) const;
diff --git a/src/Hill.cxx b/src/Hill.cxx
index 9056d2f..d79f4ad 100644
--- a/src/Hill.cxx
+++ b/src/Hill.cxx
@@ -128,7 +128,7 @@ void Hills::mark_duplicates(double dist) {
Hill *m, *n;
int i, j;
- sort_phi();
+ sort(SORT_PHI);
for(i=0; i<get_num();i++) {
m = get(i);
@@ -175,7 +175,7 @@ Hills::add(Hills *h) {
}
static int
-comp_mountains(const void *n1, const void *n2) {
+comp_mountains_alpha(const void *n1, const void *n2) {
Hill *m1 = *(Hill **)n1;
Hill *m2 = *(Hill **)n2;
@@ -230,42 +230,44 @@ comp_mountains_label_y(const void *n1, const void *n2) {
Hill *m1 = *(Hill **)n1;
Hill *m2 = *(Hill **)n2;
- if (m1 && m2)
- return (m2->y + m2->label_y) - (m1->y + m1->label_y);
- else
+ if (m1 && m2) {
+ if ((m2->y + m2->label_y) > (m1->y + m1->label_y))
+ return 1;
+ else if ((m2->y + m2->label_y) < (m1->y + m1->label_y))
+ return -1;
+ else
+ return 0;
+ } else {
return 0;
+ }
}
void
-Hills::sort() {
- if (!m)
- return;
-
- qsort(m, num, sizeof(Hill *), comp_mountains);
-}
-
-void
-Hills::sort_phi() {
- if (!m)
- return;
-
- qsort(m, num, sizeof(Hill *), comp_mountains_phi);
-}
-
-void
-Hills::sort_name() {
+Hills::sort(SortType t) {
+ int (*cmp)(const void *, const void *);
+
if (!m)
return;
- qsort(m, num, sizeof(Hill *), comp_mountains_name);
-}
-
-void
-Hills::sort_label_y() {
- if (!m)
- return;
+ switch (t) {
+ case SORT_ALPHA:
+ cmp = comp_mountains_alpha;
+ break;
+ case SORT_PHI:
+ cmp = comp_mountains_phi;
+ break;
+ case SORT_NAME:
+ cmp = comp_mountains_name;
+ break;
+ case SORT_LABEL_Y:
+ cmp = comp_mountains_label_y;
+ break;
+ default:
+ fprintf(stderr, "ERROR: Unknown sort type %d\n", t);
+ return;
+ }
- qsort(m, num, sizeof(Hill *), comp_mountains_label_y);
+ qsort(m, num, sizeof(Hill *), cmp);
}
void
diff --git a/src/Panorama.cxx b/src/Panorama.cxx
index e52b55c..7c4124f 100644
--- a/src/Panorama.cxx
+++ b/src/Panorama.cxx
@@ -297,7 +297,7 @@ Panorama::update_angles() {
m->alph = alpha(m);
}
- mountains->sort();
+ mountains->sort(Hills::SORT_ALPHA);
update_close_mountains();
}
diff --git a/src/choose_hill.cxx b/src/choose_hill.cxx
index 7f59d68..c83d8b1 100644
--- a/src/choose_hill.cxx
+++ b/src/choose_hill.cxx
@@ -15,7 +15,7 @@ choose_hill(const Hills *hills, const char *l) {
Hills *h_sort = new Hills(hills);
Hill *ret;
- h_sort->sort_name();
+ h_sort->sort(Hills::SORT_NAME);
for (int i=0; i<h_sort->get_num(); i++) {
char buf[256];