summaryrefslogtreecommitdiffstats
path: root/core/units.h
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2018-10-20 14:12:15 -0400
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2018-10-21 19:55:09 +0300
commit28e3413ff66552f392fecee25068d634cdfe59fc (patch)
tree5fe303d1e7dc1c371e13b534b85c232e29aea884 /core/units.h
parentc9869406301ff72f76b399097f0845fc1102ced1 (diff)
downloadsubsurface-28e3413ff66552f392fecee25068d634cdfe59fc.tar.gz
Add 'location_t' data structure
Instead of having people treat latitude and longitude as separate things, just add a 'location_t' data structure that contains both. Almost all cases want to always act on them together. This is really just prep-work for adding a few more locations that we track: I want to add a entry/exit location to each dive (independent of the dive site) because of how the Garmin Descent gives us the information (and hopefully, some day, other dive computers too). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'core/units.h')
-rw-r--r--core/units.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/core/units.h b/core/units.h
index 6e9fe50d9..0e2c2b2e3 100644
--- a/core/units.h
+++ b/core/units.h
@@ -134,6 +134,29 @@ typedef struct
int udeg;
} degrees_t;
+typedef struct pos {
+ degrees_t lat, lon;
+} location_t;
+
+static inline bool has_location(const location_t *loc)
+{
+ return loc->lat.udeg || loc->lon.udeg;
+}
+
+static inline bool same_location(const location_t *a, const location_t *b)
+{
+ return (a->lat.udeg == b->lat.udeg) && (a->lon.udeg == b->lon.udeg);
+}
+
+static inline location_t create_location(double lat, double lon)
+{
+ location_t location = {
+ { (int) lrint(lat * 1000000) },
+ { (int) lrint(lon * 1000000) }
+ };
+ return location;
+}
+
static inline double udeg_to_radians(int udeg)
{
return (udeg * M_PI) / (1000000.0 * 180.0);