diff options
author | Johannes Hofmann <johannes.hofmann@gmx.de> | 2005-06-19 14:54:02 +0000 |
---|---|---|
committer | Johannes Hofmann <johannes.hofmann@gmx.de> | 2005-06-19 14:54:02 +0000 |
commit | 1c92fda21514b790219dec9a2e5a85718cb83e73 (patch) | |
tree | 2ecff677606140a8332cc9d4f8487feb30d6780f /src/Hill.cxx | |
parent | fe61e9b1f5b135f30bd1bf22a2be77ee85573ff9 (diff) |
add duplicate removal
add duplicate removal
Diffstat (limited to 'src/Hill.cxx')
-rw-r--r-- | src/Hill.cxx | 55 |
1 files changed, 54 insertions, 1 deletions
diff --git a/src/Hill.cxx b/src/Hill.cxx index 5dbe226..8f2f527 100644 --- a/src/Hill.cxx +++ b/src/Hill.cxx @@ -1,5 +1,5 @@ // -// "$Id: Hill.cxx,v 1.14 2005/05/10 18:12:47 hofmann Exp $" +// "$Id: Hill.cxx,v 1.15 2005/06/19 16:54:02 hofmann Exp $" // // Hill routines. // @@ -38,6 +38,7 @@ Hill::Hill(const char *n, double p, double l, double h) { alph = 0.0; x = 0; y = 0; + duplicate = 0; } Hill::Hill(int x_tmp, int y_tmp) { @@ -105,6 +106,31 @@ Hills::load(const char *file) { return 0; } +void Hills::mark_duplicates(double dist) { + Hill *m, *n; + int i, j; + + sort_phi(); + + for(i=0; i<get_num();i++) { + m = get(i); + + if (m) { + j = i + 1; + n = get(j); + while (n && fabs(n->phi - m->phi) <= dist) { + // fprintf(stderr, "%s %f %f %s %f %f\n", m->name, m->phi, m->lam, n->name, n->phi, n->lam); + if (fabs(n->lam - m->lam) <= dist) { + fprintf(stderr, "Duplicate: %s <=> %s\n", m->name, n->name); + n->duplicate = 1; + } + j = j + 1; + n = get(j); + } + } + } +} + Hills::~Hills() { if (m) { @@ -142,6 +168,24 @@ comp_mountains(const void *n1, const void *n2) { } } +static int +comp_mountains_phi(const void *n1, const void *n2) { + Hill *m1 = *(Hill **)n1; + Hill *m2 = *(Hill **)n2; + + if (m1 && m2) { + if (m1->phi < m2->phi) { + return 1; + } else if (m1->phi > m2->phi) { + return -1; + } else { + return 0; + } + } else { + return 0; + } +} + void Hills::sort() { if (!m) { @@ -152,6 +196,15 @@ Hills::sort() { } void +Hills::sort_phi() { + if (!m) { + return; + } + + qsort(m, num, sizeof(Hill *), comp_mountains_phi); +} + +void Hills::clear() { if (m) { free(m); |