summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-03-29 14:00:12 +0200
committerJohannes Hofmann <Johannes.Hofmann@gmx.de>2009-03-29 14:00:12 +0200
commitd2eca5bbe81dc4a899c97f1423c392554113f852 (patch)
treec853ff74d7b221cd1b6b610e9e397c2cc681586d /src
parentdfb33cc7bd701e7549d28cb496c2dab73c92e2d2 (diff)
fix long standing bug in label positioning code
Diffstat (limited to 'src')
-rw-r--r--src/GipfelWidget.cxx20
-rw-r--r--src/Hill.H7
-rw-r--r--src/Hill.cxx19
3 files changed, 41 insertions, 5 deletions
diff --git a/src/GipfelWidget.cxx b/src/GipfelWidget.cxx
index c72cb39..f0403cf 100644
--- a/src/GipfelWidget.cxx
+++ b/src/GipfelWidget.cxx
@@ -344,6 +344,7 @@ GipfelWidget::set_labels(Hills *v) {
for (int i = 0; i < v->get_num(); i++) {
Hill *m = v->get(i);
+ Hills colliding;
if (m->flags & (Hill::DUPLICATE | Hill::TRACK_POINT))
continue;
@@ -363,13 +364,22 @@ GipfelWidget::set_labels(Hills *v) {
if (!show_hidden && (n->flags & Hill::HIDDEN))
continue;
+ if (overlap(m->x, m->label_x,
+ n->x - CROSS_SIZE, n->label_x + CROSS_SIZE))
+ colliding.add(n);
+ }
+
+ colliding.sort_label_y();
+
+ for (int j = 0; j < colliding.get_num(); j++) {
+ Hill *n = colliding.get(j);
+
// Check for overlapping labels and
// overlaps between labels and peak markers
- if ((overlap(m->x, m->label_x, n->x, n->label_x) &&
- overlap(m->y + m->label_y - height, height,
- n->y + n->label_y - height, height)) ||
- (overlap(m->x, m->label_x, n->x - 2, 4) &&
- overlap(m->y + m->label_y - height, height, n->y - 2, 4))) {
+ if (overlap(m->y + m->label_y - height, height,
+ n->y + n->label_y - height, height) ||
+ overlap(m->y + m->label_y - height,
+ height, n->y - CROSS_SIZE, 2 * CROSS_SIZE)) {
m->label_y = (int) rint(n->y + n->label_y - m->y - height - 2);
}
diff --git a/src/Hill.H b/src/Hill.H
index fb02feb..b4ced70 100644
--- a/src/Hill.H
+++ b/src/Hill.H
@@ -41,6 +41,12 @@ class Hills {
Hill **m;
public:
+ typedef enum {
+ SORT_PHI,
+ SORT_NAME,
+ SORT_LABEL_Y
+ } SortType;
+
Hills();
Hills(const Hills *h);
~Hills();
@@ -52,6 +58,7 @@ class Hills {
void add(Hills *h);
void sort_phi();
void sort_name();
+ void sort_label_y();
void sort();
void clear();
void clobber();
diff --git a/src/Hill.cxx b/src/Hill.cxx
index f4ba112..9056d2f 100644
--- a/src/Hill.cxx
+++ b/src/Hill.cxx
@@ -225,6 +225,17 @@ comp_mountains_name(const void *n1, const void *n2) {
}
}
+static int
+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
+ return 0;
+}
+
void
Hills::sort() {
if (!m)
@@ -250,6 +261,14 @@ Hills::sort_name() {
}
void
+Hills::sort_label_y() {
+ if (!m)
+ return;
+
+ qsort(m, num, sizeof(Hill *), comp_mountains_label_y);
+}
+
+void
Hills::clear() {
if (m) {
free(m);