From 80d54bda585896f72b66fafd5515d11767eb8315 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20T=C5=AFma?= Date: Sun, 21 Mar 2021 21:04:26 +0100 Subject: [PATCH] Code cleanup --- src/data/poi.cpp | 72 +++++++++++++++++++++++++----------------------- src/data/poi.h | 3 +- 2 files changed, 38 insertions(+), 37 deletions(-) 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: