diff --git a/CMakeLists.txt b/CMakeLists.txt index 55ac322d9..2193b851b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ include(CheckIncludeFile) include(gbversion.cmake) project(gpsbabel LANGUAGES C CXX VERSION ${GB.VERSION}) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED True) # Do this after we set up common variables but before creating other diff --git a/defs.h b/defs.h index 85465104c..df3e8c3aa 100644 --- a/defs.h +++ b/defs.h @@ -19,7 +19,6 @@ #ifndef DEFS_H_INCLUDED_ #define DEFS_H_INCLUDED_ -#include // for M_PI #include // for NULL, nullptr_t, size_t #include // for int32_t, uint32_t #include // for NULL, fprintf, FILE, stdout @@ -36,7 +35,6 @@ #include // for QString #include // for QStringView #include // for QTextCodec -#include // for QVector #include // for CaseInsensitive #include // for QForeachContainer, qMakeForeachContainer, foreach, qint64 @@ -50,12 +48,6 @@ #define CSTR(qstr) ((qstr).toUtf8().constData()) #define CSTRc(qstr) ((qstr).toLatin1().constData()) -/* - * Amazingly, this constant is not specified in the standard... - */ -#ifndef M_PI -# define M_PI 3.14159265358979323846 -#endif /* * The constants marked "exact in decimal notation" may be more accurately @@ -235,17 +227,11 @@ class UrlList : public QList class wp_flags { public: - wp_flags() : - shortname_is_synthetic(0), - fmt_use(0), - is_split(0), - new_trkseg(0), - marked_for_deletion(0) {} - unsigned int shortname_is_synthetic:1; - unsigned int fmt_use:2; /* lightweight "extra data" */ - unsigned int is_split:1; /* the waypoint represents a split */ - unsigned int new_trkseg:1; /* True if first in new trkseg. */ - unsigned int marked_for_deletion:1; /* True if schedulded for deletion. */ + unsigned int shortname_is_synthetic:1{0}; + unsigned int fmt_use:2{0}; /* lightweight "extra data" */ + unsigned int is_split:1{0}; /* the waypoint represents a split */ + unsigned int new_trkseg:1{0}; /* True if first in new trkseg. */ + unsigned int marked_for_deletion:1{0}; /* True if schedulded for deletion. */ }; /* @@ -275,21 +261,14 @@ class Waypoint class op_flags { public: - op_flags() : - temperature(false), - proximity(false), - course(false), - speed(false), - geoidheight(false), - depth(false) {} - bool temperature:1; /* temperature field is set */ - bool proximity:1; /* proximity field is set */ - bool course:1; /* course field is set */ - bool speed:1; /* speed field is set */ - bool geoidheight:1; /* geoidheight field is set */ - bool depth:1; /* depth field is set */ + bool temperature:1{false}; /* temperature field is set */ + bool proximity:1{false}; /* proximity field is set */ + bool course:1{false}; /* course field is set */ + bool speed:1{false}; /* speed field is set */ + bool geoidheight:1{false}; /* geoidheight field is set */ + bool depth:1{false}; /* depth field is set */ /* !ToDo! - unsigned int altitude:1; /+ altitude field is set +/ + unsigned int altitude:1{false}; /+ altitude field is set +/ ... and hdop,pdop,vdop,fix,sat,heartrate,cadence,power, odometer_distance */ diff --git a/garmin.cc b/garmin.cc index d676e33df..7c20fc836 100644 --- a/garmin.cc +++ b/garmin.cc @@ -1010,7 +1010,7 @@ GarminFormat::route_write() for (int i = 0; i < n; i++) { GPS_Way_Del(&tx_routelist[i]); } - + xfree(tx_routelist); } diff --git a/garmin_fs.h b/garmin_fs.h index 00c16074b..5ed17e9ae 100644 --- a/garmin_fs.h +++ b/garmin_fs.h @@ -50,48 +50,26 @@ struct garmin_ilink_t { struct garmin_fs_flags_t { public: - garmin_fs_flags_t() : - icon(0), - wpt_class(0), - display(0), - category(0), - city(0), - state(0), - facility(0), - cc(0), - cross_road(0), - addr(0), - country(0), - phone_nr(0), - phone_nr2(0), - fax_nr(0), - postal_code(0), - email(0), - duration(0) -#ifdef GMSD_EXPERIMENTAL - , subclass(0) -#endif - {} - - unsigned int icon:1; - unsigned int wpt_class:1; - unsigned int display:1; - unsigned int category:1; - unsigned int city:1; - unsigned int state:1; - unsigned int facility:1; - unsigned int cc:1; - unsigned int cross_road:1; - unsigned int addr:1; - unsigned int country:1; - unsigned int phone_nr:1; - unsigned int phone_nr2:1; - unsigned int fax_nr:1; - unsigned int postal_code:1; - unsigned int email:1; - unsigned int duration:1; + + unsigned int icon:1{0}; + unsigned int wpt_class:1{0}; + unsigned int display:1{0}; + unsigned int category:1{0}; + unsigned int city:1{0}; + unsigned int state:1{0}; + unsigned int facility:1{0}; + unsigned int cc:1{0}; + unsigned int cross_road:1{0}; + unsigned int addr:1{0}; + unsigned int country:1{0}; + unsigned int phone_nr:1{0}; + unsigned int phone_nr2:1{0}; + unsigned int fax_nr:1{0}; + unsigned int postal_code:1{0}; + unsigned int email:1{0}; + unsigned int duration:1{0}; #ifdef GMSD_EXPERIMENTAL - unsigned int subclass:1; + unsigned int subclass:1{0}; #endif }; diff --git a/geocache.h b/geocache.h index e53cc7193..a2d73d294 100644 --- a/geocache.h +++ b/geocache.h @@ -79,22 +79,6 @@ class Geocache QString utf_string; }; - /* Special Member Functions */ - - Geocache() : - id(0), - type(type_t::gt_unknown), - container(container_t::gc_unknown), - diff(0), - terr(0), - is_archived(status_t::gs_unknown), - is_available(status_t::gs_unknown), - is_memberonly(status_t::gs_unknown), - has_customcoords(status_t::gs_unknown), - placer_id(0), - favorite_points(0) - {} - /* Member Functions */ void set_type(const QString& type_name); @@ -105,22 +89,22 @@ class Geocache /* Data Members */ - long long id; /* The decimal cache number */ - type_t type:5; - container_t container:4; - unsigned int diff:6; /* (multiplied by ten internally) */ - unsigned int terr:6; /* (likewise) */ - status_t is_archived:2; - status_t is_available:2; - status_t is_memberonly:2; - status_t has_customcoords:2; + long long id{0}; /* The decimal cache number */ + type_t type:5{type_t::gt_unknown}; + container_t container:4{container_t::gc_unknown}; + unsigned int diff:6{0}; /* (multiplied by ten internally) */ + unsigned int terr:6{0}; /* (likewise) */ + status_t is_archived:2{status_t::gs_unknown}; + status_t is_available:2{status_t::gs_unknown}; + status_t is_memberonly:2{status_t::gs_unknown}; + status_t has_customcoords:2{status_t::gs_unknown}; gpsbabel::DateTime last_found; QString placer; /* Placer name */ - int placer_id; /* Placer id */ + int placer_id{0}; /* Placer id */ QString hint; /* all these UTF8, XML entities removed, May be not HTML. */ UtfString desc_short; UtfString desc_long; - int favorite_points; + int favorite_points{0}; QString personal_note; private: diff --git a/googletakeout.h b/googletakeout.h index 4754366ca..3d805562a 100644 --- a/googletakeout.h +++ b/googletakeout.h @@ -120,7 +120,7 @@ class GoogleTakeoutFormat : public Format }; /* Member Functions */ - + static void takeout_fatal(const QString& message); static void takeout_warning(const QString& message); static Waypoint* takeout_waypoint(int lat_e7, int lon_e7, const QString* shortname, const QString* description, const QString* start_str); diff --git a/grtcirc.cc b/grtcirc.cc index 94ea141f9..b4d80d7c0 100644 --- a/grtcirc.cc +++ b/grtcirc.cc @@ -26,6 +26,7 @@ #include #include #include +#include #include static constexpr double EARTH_RAD = 6378137.0; @@ -276,7 +277,7 @@ double linedistprj(double lat1, double lon1, } } else { /* lp is 0 when 3 is 90 degrees from the great circle */ - return M_PI / 2; + return std::numbers::pi / 2; } } else { /* la is 0 when 1 and 2 are either the same point or 180 degrees apart */ diff --git a/grtcirc.h b/grtcirc.h index 70641f183..821eccef4 100644 --- a/grtcirc.h +++ b/grtcirc.h @@ -22,6 +22,8 @@ #ifndef GRTCIRC_H #define GRTCIRC_H +#include // for inv_pi + double gcdist(double lat1, double lon1, double lat2, double lon2); double heading(double lat1, double lon1, double lat2, double lon2); double heading_true_degrees(double lat1, double lon1, double lat2, double lon2); @@ -45,7 +47,7 @@ void linepart(double lat1, double lon1, double* reslat, double* reslon); /* Degrees to radians */ -constexpr double kDegreesPerRadian = 180.0 / M_PI; +constexpr double kDegreesPerRadian = 180.0 * std::numbers::inv_pi; constexpr double DEG(double x) { return x * kDegreesPerRadian; } /* Radians to degrees */ diff --git a/humminbird.cc b/humminbird.cc index ea3f2f3a8..d4a597b26 100644 --- a/humminbird.cc +++ b/humminbird.cc @@ -25,9 +25,10 @@ #include // for CaseInsensitive #include // for qRound -#include // for atan, tan, M_PI, log, sinh +#include // for atan, tan, log, sinh #include // for snprintf, SEEK_SET #include // for strncpy, memcpy, memset +#include // for inv_pi, pi #include "defs.h" // for Waypoint, be_read32, be_read16, be_write32, fatal, xfree, be_write16, route_head, xcalloc, track_add_wpt, xstrndup #include "mkshort.h" // for MakeShort @@ -61,7 +62,7 @@ Still, they're useful in the code as a plain signature. #define WPT_MAGIC2 0x02030024L // New for 2013. No visible diff?! #define RTE_MAGIC 0x03030088L -#define EAST_SCALE 20038297.0 /* this is i1924_equ_axis*M_PI */ +#define EAST_SCALE 20038297.0 /* this is i1924_equ_axis*pi */ #define i1924_equ_axis 6378388.0 #define i1924_polar_axis 6356911.946 @@ -173,9 +174,9 @@ HumminbirdBase::geodetic_to_geocentric_hwr(const double gd_lat) { constexpr double cos_ae = 0.9966349016452; constexpr double cos2_ae = cos_ae * cos_ae; - const double gdr = gd_lat *M_PI / 180.0; + const double gdr = gd_lat * std::numbers::pi / 180.0; - return atan(cos2_ae * tan(gdr)) * 180.0/M_PI; + return atan(cos2_ae * tan(gdr)) * 180.0 * std::numbers::inv_pi; } /* Takes a latitude in degrees, @@ -185,9 +186,9 @@ HumminbirdBase::geocentric_to_geodetic_hwr(const double gc_lat) { constexpr double cos_ae = 0.9966349016452; constexpr double cos2_ae = cos_ae * cos_ae; - const double gcr = gc_lat *M_PI / 180.0; + const double gcr = gc_lat * std::numbers::pi / 180.0; - return atan(tan(gcr)/cos2_ae) * 180.0/M_PI; + return atan(tan(gcr)/cos2_ae) * 180.0 * std::numbers::inv_pi; } /* Takes a projected "north" value, returns latitude in degrees. */ @@ -196,15 +197,15 @@ HumminbirdBase::gudermannian_i1924(const double x) { const double norm_x = x/i1924_equ_axis; - return atan(sinh(norm_x)) * 180.0/M_PI; + return atan(sinh(norm_x)) * 180.0 * std::numbers::inv_pi; } /* Takes latitude in degrees, returns projected "north" value. */ double HumminbirdBase::inverse_gudermannian_i1924(const double x) { - const double x_r = x/180.0 * M_PI; - const double guder = log(tan(M_PI/4.0 + x_r/2.0)); + const double x_r = x/180.0 * std::numbers::pi; + const double guder = log(tan(std::numbers::pi/4.0 + x_r/2.0)); return guder * i1924_equ_axis; } diff --git a/jeeps/gpsmath.h b/jeeps/gpsmath.h index e4adcfb0e..dadd2863f 100644 --- a/jeeps/gpsmath.h +++ b/jeeps/gpsmath.h @@ -3,11 +3,12 @@ #include // for int32_t #include // for time_t +#include // for pi #include // for QString -constexpr double GPS_PI = 3.14159265358979323846; +constexpr double GPS_PI = std::numbers::pi; double GPS_Math_Deg_To_Rad(double v); diff --git a/lowranceusr.cc b/lowranceusr.cc index 92f533a18..8e38e6f8a 100644 --- a/lowranceusr.cc +++ b/lowranceusr.cc @@ -88,11 +88,12 @@ #include "lowranceusr.h" #include // for PRId64 -#include // for M_PI, round, atan, exp, log, tan +#include // for round, atan, exp, log, tan #include // for printf, sprintf, SEEK_CUR #include // for int64_t #include // for abs #include // for strcmp, strlen +#include // for pi #include // for as_const #include // for QByteArray @@ -377,7 +378,7 @@ LowranceusrFormat::lon_mm_to_deg(double x) double LowranceusrFormat::lat_mm_to_deg(double x) { - return (2.0 * atan(exp(x / SEMIMINOR)) - M_PI / 2.0) / DEGREESTORADIANS; + return (2.0 * atan(exp(x / SEMIMINOR)) - std::numbers::pi / 2.0) / DEGREESTORADIANS; } long @@ -389,7 +390,7 @@ LowranceusrFormat::lon_deg_to_mm(double x) long LowranceusrFormat::lat_deg_to_mm(double x) { - return round(SEMIMINOR * log(tan((x * DEGREESTORADIANS + M_PI / 2.0) / 2.0))); + return round(SEMIMINOR * log(tan((x * DEGREESTORADIANS + std::numbers::pi / 2.0) / 2.0))); } void diff --git a/lowranceusr.h b/lowranceusr.h index 98c21ef69..ee54fc46d 100644 --- a/lowranceusr.h +++ b/lowranceusr.h @@ -87,8 +87,9 @@ #ifndef LOWRANCEUSR_H_INCLUDED_ #define LOWRANCEUSR_H_INCLUDED_ -#include // for M_PI, round, atan, exp, log, tan +#include // for round, atan, exp, log, tan #include // for int64_t +#include // for pi #include // for QList #include // for QString @@ -378,7 +379,7 @@ class LowranceusrFormat : public Format static constexpr int MAXUSRSTRINGSIZE = 256; static constexpr double SEMIMINOR = 6356752.3142; - static constexpr double DEGREESTORADIANS = M_PI/180.0; + static constexpr double DEGREESTORADIANS = std::numbers::pi/180.0; static constexpr int MAX_TRAIL_POINTS = 9999; static constexpr double UNKNOWN_USR_ALTITUDE = METERS_TO_FEET(-10000); /* -10000ft is how the unit stores unknown */ static constexpr int64_t base_time_secs = 946706400; /* Jan 1, 2000 00:00:00 */ diff --git a/main.cc b/main.cc index 7667c1af9..9e62fde52 100644 --- a/main.cc +++ b/main.cc @@ -742,8 +742,8 @@ main(int argc, char* argv[]) #error This version of Qt is not supported. #endif -#if defined(_MSC_VER) && (_MSC_VER < 1920) /* MSVC 2017 or earlier */ -#error MSVC 2017 and earlier are not supported. Please use MSVC 2019 or MSVC 2022. +#if defined(_MSC_VER) && (_MSC_VER < 1920) /* Visual Studio 2017 or earlier */ +#error Visual Studio 2017 and earlier are not supported. Please use Visual Studio 2019 or 2022. #endif if constexpr (DEBUG_LOCALE) { diff --git a/precompiled_headers.h b/precompiled_headers.h index 47705c843..bcf1b63b0 100644 --- a/precompiled_headers.h +++ b/precompiled_headers.h @@ -21,12 +21,12 @@ #if defined __cplusplus #include // for sort, stable_sort -#include // for M_PI #include // for va_list #include // for NULL, nullptr_t, size_t #include // for int32_t, uint32_t #include // for NULL, fprintf, FILE, stdout #include // for time_t +#include // for inv_pi, pi #include // for optional #include // for move diff --git a/skytraq.cc b/skytraq.cc index 180547cbd..f6df657af 100644 --- a/skytraq.cc +++ b/skytraq.cc @@ -24,11 +24,12 @@ */ #include // for isprint -#include // for cos, sin, atan2, pow, sqrt, M_PI +#include // for cos, sin, atan2, pow, sqrt #include // for va_end, va_list, va_start #include // for sscanf, snprintf, vprintf, SEEK_SET #include // for free #include // for memset +#include // for inv_pi, pi #include // for QByteArray #include // for QChar @@ -581,8 +582,8 @@ SkytraqBase::ECEF_to_LLA(double x, double y, long z, double* lat, double* lon, d /* height above ellipsoid (in meters): */ *alt = AP/cos(*lat) - CA/sqrt(1 - CE2 * pow(sin(*lat), 2)); - *lat = *lat /M_PI*180; - *lon = *lon /M_PI*180; + *lat = *lat * std::numbers::inv_pi * 180; + *lon = *lon * std::numbers::inv_pi * 180; } void @@ -1322,8 +1323,8 @@ void MinihomerFormat::lla2ecef(double lat, double lng, double alt, double* ecef_ long double a = 6378137.0; long double esqr = 6.69437999014e-3; - long double llat = lat*M_PI/180; - long double llng = lng*M_PI/180; + long double llat = lat * std::numbers::pi / 180; + long double llng = lng * std::numbers::pi / 180; long double lalt = alt; long double s = sin(llat); diff --git a/src/core/nvector.cc b/src/core/nvector.cc index a35efc691..f6e8ad894 100644 --- a/src/core/nvector.cc +++ b/src/core/nvector.cc @@ -20,14 +20,13 @@ // https://en.wikipedia.org/wiki/N-vector // http://www.navlab.net/Publications/A_Nonsingular_Horizontal_Position_Representation.pdf -#include -#include -#include -#include -#include +#include "src/core/nvector.h" -#include "nvector.h" -#include "vector3d.h" +#include // for DBL_EPSILON +#include // for sqrt, atan2, cos, nan, sin, cbrt +#include // for pair + +#include "src/core/vector3d.h" // for Vector3D namespace gpsbabel { @@ -401,7 +400,7 @@ double NVector::crossTrackDistance(const NVector& n_EA_E, const NVector& n_EB_E, { Vector3D c_E = crossProduct(n_EA_E, n_EB_E).normalize(); double result = fabs((atan2(crossProduct(c_E, n_EX_E).norm(), - dotProduct(c_E, n_EX_E)) - M_PI/2.0)) * MEAN_EARTH_RADIUS_METERS; + dotProduct(c_E, n_EX_E)) - std::numbers::pi/2.0)) * MEAN_EARTH_RADIUS_METERS; return result; } #else diff --git a/src/core/nvector.h b/src/core/nvector.h index 4cd7b820f..03d4c7f6f 100644 --- a/src/core/nvector.h +++ b/src/core/nvector.h @@ -20,8 +20,10 @@ #ifndef NVECTOR_H #define NVECTOR_H -#include "defs.h" -#include "vector3d.h" +#include // for pi +#include // for pair + +#include "src/core/vector3d.h" // for Vector3D namespace gpsbabel { @@ -42,7 +44,7 @@ constexpr double WGS84_ASPECT_RATIO = 1.0 - WGS84_FLATTENING; // b/a constexpr double WGS84_SEMI_MINOR_AXIS_METERS = WGS84_SEMI_MAJOR_AXIS_METERS * WGS84_ASPECT_RATIO; // b constexpr double WGS84_ECCENTRICITY_SQUARED = 1.0 - (WGS84_ASPECT_RATIO * WGS84_ASPECT_RATIO); -constexpr double kRadiansPerDegree = M_PI/180.0; +constexpr double kRadiansPerDegree = std::numbers::pi / 180.0; constexpr double kDegreesPerRadian = 1.0/kRadiansPerDegree; class PVector;