diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-06-10 11:45:34 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-06-10 11:51:15 -0700 |
commit | d541c2b601a82aad7ae8e0e419b172cc32f24a84 (patch) | |
tree | fd488a7983c0e27c274541676dfedcdd62cb3c04 | |
parent | 1ee447b5a95e97f5eb409ce67b0b06464138e572 (diff) | |
download | subsurface-d541c2b601a82aad7ae8e0e419b172cc32f24a84.tar.gz |
Add helper function to determine the distance between two points
And use this to find a dive site within a certain radius of a GPS fix.
This will be used to figure out if dive sites might be the same.
This uses a new Qt5 component (Positioning) which was added in Qt5.2.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | CMakeLists.txt | 4 | ||||
-rw-r--r-- | divesite.c | 22 | ||||
-rw-r--r-- | divesite.h | 1 | ||||
-rw-r--r-- | qt-ui/globe.cpp | 8 | ||||
-rw-r--r-- | qt-ui/globe.h | 3 |
5 files changed, 36 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index c5e039185..f82ad3714 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,8 +128,8 @@ if(NOT (insource OR insourcedir)) endif() # configure Qt. -find_package(Qt5 REQUIRED COMPONENTS Core Concurrent Widgets Network WebKitWidgets PrintSupport Svg Test LinguistTools) -set(QT_LIBRARIES Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Network Qt5::WebKitWidgets Qt5::PrintSupport Qt5::Svg) +find_package(Qt5 REQUIRED COMPONENTS Core Concurrent Widgets Network WebKitWidgets PrintSupport Svg Test LinguistTools Positioning) +set(QT_LIBRARIES Qt5::Core Qt5::Concurrent Qt5::Widgets Qt5::Network Qt5::WebKitWidgets Qt5::PrintSupport Qt5::Svg Qt5::Positioning) set(QT_TEST_LIBRARIES ${QT_LIBRARIES} Qt5::Test) # Generate the ssrf-config.h every 'make' diff --git a/divesite.c b/divesite.c index fbf01bf77..3caa7b3ba 100644 --- a/divesite.c +++ b/divesite.c @@ -34,6 +34,28 @@ uint32_t get_dive_site_uuid_by_gps(degrees_t latitude, degrees_t longitude, stru return 0; } +/* this is in globe.cpp, so including the .h file is a pain */ +extern double getDistance(int lat1, int lon1, int lat2, int lon2); + +/* find the closest one, no more than distance meters away - if more than one at same distance, pick the first */ +uint32_t get_dive_site_uuid_by_gps_proximity(degrees_t latitude, degrees_t longitude, int distance, struct dive_site **dsp) +{ + int i; + int uuid = 0; + struct dive_site *ds; + double cur_distance, min_distance = distance + 0.001; + for_each_dive_site (i, ds) { + if (dive_site_has_gps_location(ds) && + (cur_distance = getDistance(ds->latitude.udeg, ds->longitude.udeg, latitude.udeg, longitude.udeg)) < min_distance) { + min_distance = cur_distance; + uuid = ds->uuid; + if (dsp) + *dsp = ds; + } + } + return uuid; +} + /* try to create a uniqe ID - fingers crossed */ static uint32_t dive_site_getUniqId() { diff --git a/divesite.h b/divesite.h index ca650259a..79adf664a 100644 --- a/divesite.h +++ b/divesite.h @@ -53,6 +53,7 @@ uint32_t create_dive_site(const char *name); uint32_t create_dive_site_with_gps(const char *name, degrees_t latitude, degrees_t longitude); uint32_t get_dive_site_uuid_by_name(const char *name, struct dive_site **dsp); uint32_t get_dive_site_uuid_by_gps(degrees_t latitude, degrees_t longitude, struct dive_site **dsp); +uint32_t get_dive_site_uuid_by_gps_proximity(degrees_t latitude, degrees_t longitude, int distance, struct dive_site **dsp); bool dive_site_is_empty(struct dive_site *ds); #ifdef __cplusplus diff --git a/qt-ui/globe.cpp b/qt-ui/globe.cpp index b8e0ec87e..76d48b7ba 100644 --- a/qt-ui/globe.cpp +++ b/qt-ui/globe.cpp @@ -1,4 +1,5 @@ #include "globe.h" +#include <QGeoCoordinate> #ifndef NO_MARBLE #include "mainwindow.h" #include "helpers.h" @@ -392,3 +393,10 @@ void GlobeGPS::reload() { } #endif + +extern "C" double getDistance(int lat1, int lon1, int lat2, int lon2) +{ + QGeoCoordinate c1(lat1 / 1000000.0, lon1 / 1000000.0); + QGeoCoordinate c2(lat2 / 1000000.0, lon2 / 1000000.0); + return c1.distanceTo(c2); +} diff --git a/qt-ui/globe.h b/qt-ui/globe.h index 903b9f89c..1791e0ff3 100644 --- a/qt-ui/globe.h +++ b/qt-ui/globe.h @@ -74,4 +74,7 @@ slots: }; #endif // NO_MARBLE + +extern "C" double getDistance(int lat1, int lon1, int lat2, int lon2); + #endif // GLOBE_H |