Review fixes.

This commit is contained in:
Vladimir Byko-Ianko 2018-06-19 12:55:27 +03:00 committed by mpimenov
parent 32243b1e5a
commit 360fdd2db0
3 changed files with 46 additions and 80 deletions

View file

@ -59,8 +59,6 @@ location::GpsInfo LinearExtrapolation(location::GpsInfo const & gpsInfo1,
my::clamp(e.Extrapolate(gpsInfo1.m_longitude, gpsInfo2.m_longitude), -180.0, 180.0);
result.m_latitude =
my::clamp(e.Extrapolate(gpsInfo1.m_latitude, gpsInfo2.m_latitude), -90.0, 90.0);
result.m_horizontalAccuracy =
e.Extrapolate(gpsInfo1.m_horizontalAccuracy, gpsInfo2.m_horizontalAccuracy);
result.m_altitude = e.Extrapolate(gpsInfo1.m_altitude, gpsInfo2.m_altitude);
// @TODO(bykoianko) Now |result.m_bearing| == |gpsInfo2.m_bearing|.
@ -96,7 +94,7 @@ bool AreCoordsGoodForExtrapolation(location::GpsInfo const & info1, location::Gp
// |maxDistForAllExtrapolationsM| is maximum possible distance from |info2| to
// all extrapolated points in any cases.
double const maxDistForAllExtrapolationsM =
kMaxExtrapolationSpeedMPS / kMaxExtrapolationTimeSeconds;
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

View file

@ -266,11 +266,11 @@ int main(int argc, char * argv[])
m2::PointD const extrapolatedMerc =
MercatorBounds::FromLatLon(extrapolated.m_latitude, extrapolated.m_longitude);
// To generate |posSquare| the method below requires the size of half square in meters.
// This constant is chosen based on maximum value of GpsInfo::m_horizontalAccuracy
double const kHalfSquareSide = 100.0;
// |kHalfSquareSide| is chosen based on maximum value of GpsInfo::m_horizontalAccuracy
// which is used calculation of projection in production code.
m2::RectD const posSquare = MercatorBounds::MetresToXY(
extrapolated.m_longitude, extrapolated.m_latitude, 100.0 /* half square in meters */);
extrapolated.m_longitude, extrapolated.m_latitude, kHalfSquareSide);
// One is deducted from polyline size because in GetClosestProjectionInInterval()
// is used segment indices but not point indices.
auto const & iter = followedPoly.GetClosestProjectionInInterval(

View file

@ -25,155 +25,123 @@ void TestGpsInfo(GpsInfo const & tested, GpsInfo const & expected)
TEST(my::AlmostEqualAbs(tested.m_speed, expected.m_speed, kEpsilon), ());
}
GpsInfo GetGpsInfo(double timestampS, double lat, double lon)
GpsInfo GetGpsInfo(double timestampS, double lat, double lon, double altitude, double speed)
{
return GpsInfo{EAppleNative,
timestampS,
lat,
lon,
10.0 /* m_horizontalAccuracy */,
1.0 /* m_altitude */,
altitude,
10.0 /* m_verticalAccuracy */,
0.0 /* m_bearing */,
10.0 /* m_speed */};
speed};
}
UNIT_TEST(LinearExtrapolation)
{
GpsInfo const loc1 = {EAppleNative,
0.0 /* m_timestamp in seconds */,
1.0 /* m_latitude */,
1.0 /* m_longitude */,
10.0 /* m_horizontalAccuracy */,
1.0 /* m_altitude */,
10.0 /* m_verticalAccuracy */,
0.0 /* m_bearing */,
10.0 /* m_speed */};
GpsInfo const loc2 = {EAppleNative,
1.0 /* m_timestamp in seconds */,
1.01 /* m_latitude */,
1.01 /* m_longitude */,
11.0 /* m_horizontalAccuracy */,
2.0 /* m_altitude */,
10.0 /* m_verticalAccuracy */,
1.0 /* m_bearing */,
12.0 /* m_speed */};
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestampS */, 1.0 /* m_latitude */, 1.0 /* m_longitude */,
1.0 /* m_altitude */, 10.0 /* m_speed */);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestampS */, 1.01 /* m_latitude */, 1.01 /* m_longitude */,
2.0 /* m_altitude */, 12.0 /* m_speed */);
// 0 ms after |point2|.
TestGpsInfo(LinearExtrapolation(loc1, loc2, 0 /* timeAfterPoint2Ms */), loc2);
// 100 ms after |point2|.
{
GpsInfo const expected = {EAppleNative,
1.1 /* m_timestamp */,
1.011 /* m_latitude */,
1.011 /* m_longitude */,
11.1 /* m_horizontalAccuracy */,
2.1 /* m_altitude */,
10.0 /* m_verticalAccuracy */,
1.0 /* m_bearing */,
12.2 /* m_speed */};
GpsInfo const expected = GetGpsInfo(1.1 /* timestampS */, 1.011 /* m_latitude */,
1.011 /* m_longitude */, 2.1 /* m_altitude */, 12.2 /* m_speed */);
TestGpsInfo(LinearExtrapolation(loc1, loc2, 100 /* timeAfterPoint2Ms */), expected);
}
// 200 ms after |point2|.
{
GpsInfo const expected = {EAppleNative,
1.2 /* m_timestamp */,
1.012 /* m_latitude */,
1.012 /* m_longitude */,
11.2 /* m_horizontalAccuracy */,
2.2 /* m_altitude */,
10.0 /* m_verticalAccuracy */,
1.0 /* m_bearing */,
12.4 /* m_speed */};
GpsInfo const expected = GetGpsInfo(1.2 /* timestampS */, 1.012 /* m_latitude */,
1.012 /* m_longitude */, 2.2 /* m_altitude */, 12.4 /* m_speed */);
TestGpsInfo(LinearExtrapolation(loc1, loc2, 200 /* timeAfterPoint2Ms */), expected);
}
// 1000 ms after |point2|.
{
GpsInfo const expected = {EAppleNative,
2.0 /* m_timestamp */,
1.02 /* m_latitude */,
1.02 /* m_longitude */,
12.0 /* m_horizontalAccuracy */,
3.0 /* m_altitude */,
10.0 /* m_verticalAccuracy */,
1.0 /* m_bearing */,
14.0 /* m_speed */};
GpsInfo const expected = GetGpsInfo(2.0 /* timestampS */, 1.02 /* m_latitude */,
1.02 /* m_longitude */, 3.0 /* m_altitude */, 14.0 /* m_speed */);
TestGpsInfo(LinearExtrapolation(loc1, loc2, 1000 /* timeAfterPoint2Ms */), expected);
}
}
UNIT_TEST(AreCoordsGoodForExtrapolation)
{
double constexpr kAltitude = 1.0;
double constexpr kSpeed = 10.0;
{
GpsInfo loc1;
GpsInfo loc2;
TEST(!AreCoordsGoodForExtrapolation(loc1, loc2), ("Locations are not valid."));
}
{
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 10.0 /* lat */, 179.999999 /* lon */);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, 10.0 /* lat */, -179.999999 /* lon */);
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 10.0 /* lat */, 179.999999 /* lon */, kAltitude, kSpeed);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, 10.0 /* lat */, -179.999999 /* lon */, kAltitude, kSpeed);
TEST(!AreCoordsGoodForExtrapolation(loc1, loc2), ("Crossing meridian 180."));
}
{
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 10.0 /* lat */, 179.999997 /* lon */);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, 10.0 /* lat */, 179.999999 /* lon */);
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 10.0 /* lat */, 179.999997 /* lon */, kAltitude, kSpeed);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, 10.0 /* lat */, 179.999999 /* lon */, kAltitude, kSpeed);
TEST(!AreCoordsGoodForExtrapolation(loc1, loc2), ("Near meridian 180."));
}
{
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 10.0 /* lat */, 179.999997 /* lon */);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, 10.0 /* lat */, 179.999998 /* lon */);
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 10.0 /* lat */, 179.999995 /* lon */, kAltitude, kSpeed);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, 10.0 /* lat */, 179.999996 /* lon */, kAltitude, kSpeed);
TEST(AreCoordsGoodForExtrapolation(loc1, loc2), ("Near meridian 180 but ok."));
}
{
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 10.0 /* lat */, -179.999997 /* lon */);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, 10.0 /* lat */, -179.999999 /* lon */);
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 10.0 /* lat */, -179.999997 /* lon */, kAltitude, kSpeed);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, 10.0 /* lat */, -179.999999 /* lon */, kAltitude, kSpeed);
TEST(!AreCoordsGoodForExtrapolation(loc1, loc2), ("Near meridian -180."));
}
{
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 89.9997 /* lat */, -10.0 /* lon */);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, 89.9999 /* lat */, -10.0 /* lon */);
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 89.9997 /* lat */, -10.0 /* lon */, kAltitude, kSpeed);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, 89.9999 /* lat */, -10.0 /* lon */, kAltitude, kSpeed);
TEST(!AreCoordsGoodForExtrapolation(loc1, loc2), ("Close to North Pole."));
}
{
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 89.9997 /* lat */, -10.0 /* lon */);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, 89.9998 /* lat */, -10.0 /* lon */);
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 89.9997 /* lat */, -10.0 /* lon */, kAltitude, kSpeed);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, 89.9998 /* lat */, -10.0 /* lon */, kAltitude, kSpeed);
TEST(AreCoordsGoodForExtrapolation(loc1, loc2), ("Close to North Pole but ok."));
}
{
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, -89.9997 /* lat */, -10.0 /* lon */);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, -89.9999 /* lat */, -10.0 /* lon */);
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, -89.9997 /* lat */, -10.0 /* lon */, kAltitude, kSpeed);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, -89.9999 /* lat */, -10.0 /* lon */, kAltitude, kSpeed);
TEST(!AreCoordsGoodForExtrapolation(loc1, loc2), ("Close to South Pole."));
}
{
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, -89.9997 /* lat */, -10.0 /* lon */);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, -89.9998 /* lat */, -10.0 /* lon */);
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, -89.9997 /* lat */, -10.0 /* lon */, kAltitude, kSpeed);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, -89.9998 /* lat */, -10.0 /* lon */, kAltitude, kSpeed);
TEST(AreCoordsGoodForExtrapolation(loc1, loc2), ("Close to South Pole but ok."));
}
{
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 10.0 /* lat */, -179.999997 /* lon */);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, 10.0 /* lat */, -179.999998 /* lon */);
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 10.0 /* lat */, -179.999995 /* lon */, kAltitude, kSpeed);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, 10.0 /* lat */, -179.999996 /* lon */, kAltitude, kSpeed);
TEST(AreCoordsGoodForExtrapolation(loc1, loc2), ("Near meridian -180 but ok."));
}
{
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 1.0 /* lat */, 10.0 /* lon */);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, 2.0 /* lat */, 10.0 /* lon */);
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 1.0 /* lat */, 10.0 /* lon */, kAltitude, kSpeed);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, 2.0 /* lat */, 10.0 /* lon */, kAltitude, kSpeed);
TEST(!AreCoordsGoodForExtrapolation(loc1, loc2), ("Locations are too far."));
}
{
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 1.0 /* lat */, 1.0 /* lon */);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, 1.0 /* lat */, 1.00001 /* lon */);
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 1.0 /* lat */, 1.0 /* lon */, kAltitude, kSpeed);
GpsInfo const loc2 = GetGpsInfo(1.0 /* timestamp */, 1.0 /* lat */, 1.00001 /* lon */, kAltitude, kSpeed);
TEST(AreCoordsGoodForExtrapolation(loc1, loc2), ("Locations are close enough."));
}
{
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 1.0 /* lat */, 1.0 /* lon */);
GpsInfo const loc2 = GetGpsInfo(0.0 /* timestamp */, 1.0 /* lat */, 1.00001 /* lon */);
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 1.0 /* lat */, 1.0 /* lon */, kAltitude, kSpeed);
GpsInfo const loc2 = GetGpsInfo(0.0 /* timestamp */, 1.0 /* lat */, 1.00001 /* lon */, kAltitude, kSpeed);
TEST(!AreCoordsGoodForExtrapolation(loc1, loc2), ("Time is the same."));
}
{
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 1.0 /* lat */, 1.0 /* lon */);
GpsInfo const loc2 = GetGpsInfo(3.0 /* timestamp */, 1.0 /* lat */, 1.00001 /* lon */);
GpsInfo const loc1 = GetGpsInfo(0.0 /* timestamp */, 1.0 /* lat */, 1.0 /* lon */, kAltitude, kSpeed);
GpsInfo const loc2 = GetGpsInfo(3.0 /* timestamp */, 1.0 /* lat */, 1.00001 /* lon */, kAltitude, kSpeed);
TEST(!AreCoordsGoodForExtrapolation(loc1, loc2), ("Too rare locations."));
}
}