mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 13:23:59 +00:00
Format all C++ and Java code via clang-format
Signed-off-by: Konstantin Pastbin <konstantin.pastbin@gmail.com>
This commit is contained in:
@@ -23,15 +23,13 @@ class LinearExtrapolator
|
||||
{
|
||||
public:
|
||||
LinearExtrapolator(uint64_t timeBetweenMs, uint64_t timeAfterMs)
|
||||
: m_timeBetweenMs(timeBetweenMs), m_timeAfterMs(timeAfterMs)
|
||||
: m_timeBetweenMs(timeBetweenMs)
|
||||
, m_timeAfterMs(timeAfterMs)
|
||||
{
|
||||
CHECK_NOT_EQUAL(m_timeBetweenMs, 0, ());
|
||||
}
|
||||
|
||||
double Extrapolate(double x1, double x2) const
|
||||
{
|
||||
return x2 + ((x2 - x1) / m_timeBetweenMs) * m_timeAfterMs;
|
||||
}
|
||||
double Extrapolate(double x1, double x2) const { return x2 + ((x2 - x1) / m_timeBetweenMs) * m_timeAfterMs; }
|
||||
|
||||
private:
|
||||
uint64_t m_timeBetweenMs;
|
||||
@@ -43,8 +41,7 @@ namespace extrapolation
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
location::GpsInfo LinearExtrapolation(location::GpsInfo const & gpsInfo1,
|
||||
location::GpsInfo const & gpsInfo2,
|
||||
location::GpsInfo LinearExtrapolation(location::GpsInfo const & gpsInfo1, location::GpsInfo const & gpsInfo2,
|
||||
uint64_t timeAfterPoint2Ms)
|
||||
{
|
||||
if (gpsInfo2.m_timestamp <= gpsInfo1.m_timestamp)
|
||||
@@ -53,8 +50,7 @@ location::GpsInfo LinearExtrapolation(location::GpsInfo const & gpsInfo1,
|
||||
return gpsInfo2;
|
||||
}
|
||||
|
||||
auto const timeBetweenPointsMs =
|
||||
static_cast<uint64_t>((gpsInfo2.m_timestamp - gpsInfo1.m_timestamp) * 1000);
|
||||
auto const timeBetweenPointsMs = static_cast<uint64_t>((gpsInfo2.m_timestamp - gpsInfo1.m_timestamp) * 1000);
|
||||
if (timeBetweenPointsMs == 0)
|
||||
return gpsInfo2;
|
||||
|
||||
@@ -62,10 +58,8 @@ location::GpsInfo LinearExtrapolation(location::GpsInfo const & gpsInfo1,
|
||||
LinearExtrapolator const e(timeBetweenPointsMs, timeAfterPoint2Ms);
|
||||
|
||||
result.m_timestamp += static_cast<double>(timeAfterPoint2Ms) / 1000.0;
|
||||
result.m_longitude =
|
||||
math::Clamp(e.Extrapolate(gpsInfo1.m_longitude, gpsInfo2.m_longitude), -180.0, 180.0);
|
||||
result.m_latitude =
|
||||
math::Clamp(e.Extrapolate(gpsInfo1.m_latitude, gpsInfo2.m_latitude), -90.0, 90.0);
|
||||
result.m_longitude = math::Clamp(e.Extrapolate(gpsInfo1.m_longitude, gpsInfo2.m_longitude), -180.0, 180.0);
|
||||
result.m_latitude = math::Clamp(e.Extrapolate(gpsInfo1.m_latitude, gpsInfo2.m_latitude), -90.0, 90.0);
|
||||
result.m_altitude = e.Extrapolate(gpsInfo1.m_altitude, gpsInfo2.m_altitude);
|
||||
|
||||
// @TODO(bykoianko) Now |result.m_bearing| == |gpsInfo2.m_bearing|.
|
||||
@@ -86,9 +80,7 @@ bool AreCoordsGoodForExtrapolation(location::GpsInfo const & info1, location::Gp
|
||||
if (!info1.IsValid() || !info2.IsValid())
|
||||
return false;
|
||||
|
||||
double const distM =
|
||||
ms::DistanceOnEarth(info1.m_latitude, info1.m_longitude,
|
||||
info2.m_latitude, info2.m_longitude);
|
||||
double const distM = ms::DistanceOnEarth(info1.m_latitude, info1.m_longitude, info2.m_latitude, info2.m_longitude);
|
||||
|
||||
double const timeS = info2.m_timestamp - info1.m_timestamp;
|
||||
if (timeS <= 0.0)
|
||||
@@ -96,24 +88,21 @@ bool AreCoordsGoodForExtrapolation(location::GpsInfo const & info1, location::Gp
|
||||
|
||||
// |maxDistAfterExtrapolationM| is maximum possible distance from |info2| to
|
||||
// the furthest extrapolated point.
|
||||
double const maxDistAfterExtrapolationM =
|
||||
distM * (Extrapolator::kMaxExtrapolationTimeMs / 1000.0) / timeS;
|
||||
double const maxDistAfterExtrapolationM = distM * (Extrapolator::kMaxExtrapolationTimeMs / 1000.0) / timeS;
|
||||
// |maxDistForAllExtrapolationsM| is maximum possible distance from |info2| to
|
||||
// all extrapolated points in any cases.
|
||||
double const maxDistForAllExtrapolationsM =
|
||||
kMaxExtrapolationSpeedMPS * kMaxExtrapolationTimeSeconds;
|
||||
double const distLastGpsInfoToMeridian180 = ms::DistanceOnEarth(
|
||||
info2.m_latitude, info2.m_longitude, info2.m_latitude, 180.0 /* lon2Deg */);
|
||||
double const maxDistForAllExtrapolationsM = kMaxExtrapolationSpeedMPS * kMaxExtrapolationTimeSeconds;
|
||||
double const distLastGpsInfoToMeridian180 =
|
||||
ms::DistanceOnEarth(info2.m_latitude, info2.m_longitude, info2.m_latitude, 180.0 /* lon2Deg */);
|
||||
// Switching off extrapolation if |info2| are so close to meridian 180 that extrapolated
|
||||
// points may cross meridian 180 or if |info1| and |info2| are located on
|
||||
// different sides of meridian 180.
|
||||
if (distLastGpsInfoToMeridian180 < maxDistAfterExtrapolationM ||
|
||||
(distLastGpsInfoToMeridian180 < maxDistForAllExtrapolationsM &&
|
||||
info2.m_longitude * info1.m_longitude < 0.0) ||
|
||||
ms::DistanceOnEarth(info2.m_latitude, info2.m_longitude, 90.0 /* lat2Deg */,
|
||||
info2.m_longitude) < maxDistAfterExtrapolationM ||
|
||||
ms::DistanceOnEarth(info2.m_latitude, info2.m_longitude, -90.0 /* lat2Deg */,
|
||||
info2.m_longitude) < maxDistAfterExtrapolationM)
|
||||
(distLastGpsInfoToMeridian180 < maxDistForAllExtrapolationsM && info2.m_longitude * info1.m_longitude < 0.0) ||
|
||||
ms::DistanceOnEarth(info2.m_latitude, info2.m_longitude, 90.0 /* lat2Deg */, info2.m_longitude) <
|
||||
maxDistAfterExtrapolationM ||
|
||||
ms::DistanceOnEarth(info2.m_latitude, info2.m_longitude, -90.0 /* lat2Deg */, info2.m_longitude) <
|
||||
maxDistAfterExtrapolationM)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -124,13 +113,14 @@ bool AreCoordsGoodForExtrapolation(location::GpsInfo const & info1, location::Gp
|
||||
|
||||
// @TODO(bykoianko) Switching off extrapolation based on acceleration should be implemented.
|
||||
// Switching off extrapolation based on speed, distance and time.
|
||||
return distM / timeS <= kMaxExtrapolationSpeedMPS &&
|
||||
distM <= kMaxExtrapolationDistMeters && timeS <= kMaxExtrapolationTimeSeconds;
|
||||
return distM / timeS <= kMaxExtrapolationSpeedMPS && distM <= kMaxExtrapolationDistMeters &&
|
||||
timeS <= kMaxExtrapolationTimeSeconds;
|
||||
}
|
||||
|
||||
// Extrapolator ------------------------------------------------------------------------------------
|
||||
Extrapolator::Extrapolator(ExtrapolatedLocationUpdateFn const & update)
|
||||
: m_isEnabled(false), m_extrapolatedLocationUpdate(update)
|
||||
: m_isEnabled(false)
|
||||
, m_extrapolatedLocationUpdate(update)
|
||||
{
|
||||
RunTaskOnBackgroundThread(false /* delayed */);
|
||||
}
|
||||
@@ -175,10 +165,7 @@ void Extrapolator::ExtrapolatedLocationUpdate(uint64_t locationUpdateCounter)
|
||||
}
|
||||
|
||||
if (gpsInfo.IsValid())
|
||||
{
|
||||
GetPlatform().RunTask(Platform::Thread::Gui,
|
||||
[this, gpsInfo]() { m_extrapolatedLocationUpdate(gpsInfo); });
|
||||
}
|
||||
GetPlatform().RunTask(Platform::Thread::Gui, [this, gpsInfo]() { m_extrapolatedLocationUpdate(gpsInfo); });
|
||||
|
||||
{
|
||||
lock_guard<mutex> guard(m_mutex);
|
||||
@@ -201,17 +188,13 @@ void Extrapolator::RunTaskOnBackgroundThread(bool delayed)
|
||||
if (delayed)
|
||||
{
|
||||
auto constexpr period = std::chrono::milliseconds(kExtrapolationPeriodMs);
|
||||
GetPlatform().RunDelayedTask(Platform::Thread::Background, period, [this, locationUpdateCounter]
|
||||
{
|
||||
ExtrapolatedLocationUpdate(locationUpdateCounter);
|
||||
});
|
||||
GetPlatform().RunDelayedTask(Platform::Thread::Background, period,
|
||||
[this, locationUpdateCounter] { ExtrapolatedLocationUpdate(locationUpdateCounter); });
|
||||
}
|
||||
else
|
||||
{
|
||||
GetPlatform().RunTask(Platform::Thread::Background, [this, locationUpdateCounter]
|
||||
{
|
||||
ExtrapolatedLocationUpdate(locationUpdateCounter);
|
||||
});
|
||||
GetPlatform().RunTask(Platform::Thread::Background,
|
||||
[this, locationUpdateCounter] { ExtrapolatedLocationUpdate(locationUpdateCounter); });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user