diff --git a/src/data/poi.cpp b/src/data/poi.cpp index e8cf6a68..8a326f50 100644 --- a/src/data/poi.cpp +++ b/src/data/poi.cpp @@ -10,6 +10,14 @@ #include "poi.h" +static bool cb(size_t data, void* context) +{ + QSet *set = (QSet*) context; + set->insert((int)data); + + return true; +} + POI::File::File(int start, int end, const QVector &data) : _enabled(true) { @@ -24,6 +32,33 @@ POI::File::File(int start, int end, const QVector &data) } } +void POI::File::search(const RectC &rect, QSet &set) const +{ + qreal min[2], max[2]; + + if (_enabled) { + if (rect.left() > rect.right()) { + min[0] = rect.topLeft().lon(); + min[1] = rect.bottomRight().lat(); + max[0] = 180.0; + max[1] = rect.topLeft().lat(); + _tree.Search(min, max, cb, &set); + + min[0] = -180.0; + min[1] = rect.bottomRight().lat(); + max[0] = rect.bottomRight().lon(); + max[1] = rect.topLeft().lat(); + _tree.Search(min, max, cb, &set); + } else { + min[0] = rect.topLeft().lon(); + min[1] = rect.bottomRight().lat(); + max[0] = rect.bottomRight().lon(); + max[1] = rect.topLeft().lat(); + _tree.Search(min, max, cb, &set); + } + } +} + POI::POI(QObject *parent) : QObject(parent) { @@ -83,43 +118,10 @@ TreeNode POI::loadDir(const QString &path) return tree; } -static bool cb(size_t data, void* context) -{ - QSet *set = (QSet*) context; - set->insert((int)data); - - return true; -} - void POI::search(const RectC &rect, QSet &set) const { - qreal min[2], max[2]; - - for (ConstIterator it = _files.constBegin(); it != _files.constEnd(); ++it) { - const File *file = *it; - - if (file->isEnabled()) { - if (rect.left() > rect.right()) { - min[0] = rect.topLeft().lon(); - min[1] = rect.bottomRight().lat(); - max[0] = 180.0; - max[1] = rect.topLeft().lat(); - file->tree().Search(min, max, cb, &set); - - min[0] = -180.0; - min[1] = rect.bottomRight().lat(); - max[0] = rect.bottomRight().lon(); - max[1] = rect.topLeft().lat(); - file->tree().Search(min, max, cb, &set); - } else { - min[0] = rect.topLeft().lon(); - min[1] = rect.bottomRight().lat(); - max[0] = rect.bottomRight().lon(); - max[1] = rect.topLeft().lat(); - file->tree().Search(min, max, cb, &set); - } - } - } + for (ConstIterator it = _files.constBegin(); it != _files.constEnd(); ++it) + (*it)->search(rect, set); } QList POI::points(const Path &path) const diff --git a/src/data/poi.h b/src/data/poi.h index 0da9fcb4..3f7083c6 100644 --- a/src/data/poi.h +++ b/src/data/poi.h @@ -44,8 +44,7 @@ private: public: File(int start, int end, const QVector &data); - const POITree &tree() const {return _tree;} - bool isEnabled() const {return _enabled;} + void search(const RectC &rect, QSet &set) const; void enable(bool enable) {_enabled = enable;} private: