From 50c4c4b9ce488f2c7691ea26bf670b0abfc797cd Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Sun, 29 Mar 2009 14:10:09 +0200 Subject: change Hills::sort() interface --- src/GipfelWidget.cxx | 2 +- src/Hill.H | 6 ++--- src/Hill.cxx | 62 +++++++++++++++++++++++++++------------------------- src/Panorama.cxx | 2 +- src/choose_hill.cxx | 2 +- 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; iy + 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; iget_num(); i++) { char buf[256]; -- cgit v1.2.3