mirror of
https://github.com/GoldenCheetah/GoldenCheetah.git
synced 2026-04-15 05:32:21 +00:00
Fixes for interpolation and gpx file load
Interpolation math fixes: Slope and interpolation behave correctly when ride point location doesnt change. In gpx read: do not open same file twice with different read flags.
This commit is contained in:
committed by
Ale Martinez
parent
c179419feb
commit
d52fb5a68f
@@ -321,14 +321,15 @@ geolocation GeoPointInterpolator::Location(double distance, double &slope)
|
||||
double rise = l1.Alt() - l0.Alt();
|
||||
|
||||
// Tangent vector's magnitude is velocity in terms of distance spline.
|
||||
// Will be unit vector when distance spline has constant rate.
|
||||
// Will be unit vector when distance spline has constant rate. Can have
|
||||
// zero length when processing points without motion.
|
||||
double hyp = tangentVector.magnitude();
|
||||
|
||||
// Compute adjacent speed.
|
||||
double run = sqrt(fabs((hyp * hyp) - (rise * rise)));
|
||||
double adj = fabs((hyp * hyp) - (rise * rise));
|
||||
|
||||
// Gradient.
|
||||
slope = run ? rise / run : 0;
|
||||
slope = (adj > 0.) ? rise / sqrt(adj) : 0.;
|
||||
|
||||
// No matter what we still don't permit slopes above 40%.
|
||||
slope = std::min(slope, .4);
|
||||
|
||||
@@ -752,7 +752,7 @@ public:
|
||||
// Remove frame speed from tangent vector.
|
||||
double frameSpeed = m_DistanceWindow.FrameSpeed(bracketRatio);
|
||||
double tangentSpeed = tangentVector.magnitude();
|
||||
double correctionScale = frameSpeed / (tangentSpeed * tangentSpeed);
|
||||
double correctionScale = tangentSpeed ? (frameSpeed / (tangentSpeed * tangentSpeed)) : 1.;
|
||||
|
||||
// This rescale converts tangent vector into a unit vector
|
||||
// WRT parametric route velocity.
|
||||
|
||||
@@ -720,20 +720,16 @@ void ErgFile::parseGpx()
|
||||
|
||||
QFile gpxFile(filename);
|
||||
|
||||
// open the file
|
||||
if (gpxFile.open(QIODevice::ReadOnly | QIODevice::Text) == false) {
|
||||
// check file exists
|
||||
if (!gpxFile.exists()) {
|
||||
valid = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Instantiate ride
|
||||
//RideFile *RideFileFactory::openRideFile(Context *context, QFile &file,
|
||||
// QStringList &errors, QList<RideFile*> *rideList) const
|
||||
|
||||
// instantiate ride
|
||||
QStringList errors_;
|
||||
RideFile* ride = RideFileFactory::instance().openRideFile(context, gpxFile, errors_);
|
||||
if (ride == NULL)
|
||||
{
|
||||
if (ride == NULL) {
|
||||
valid = false;
|
||||
return;
|
||||
}
|
||||
@@ -742,6 +738,7 @@ void ErgFile::parseGpx()
|
||||
bool fHasKm = ride->areDataPresent()->km;
|
||||
bool fHasLat = ride->areDataPresent()->lat;
|
||||
bool fHasLon = ride->areDataPresent()->lon;
|
||||
bool fHasGPS = fHasLat && fHasLon;
|
||||
bool fHasAlt = ride->areDataPresent()->alt;
|
||||
bool fHasSlope = ride->areDataPresent()->slope;
|
||||
|
||||
@@ -787,15 +784,20 @@ void ErgFile::parseGpx()
|
||||
double km1 = nextPoint->km;
|
||||
double alt1 = nextPoint->alt / 1000;
|
||||
|
||||
slope = 100 * (alt1 - alt0) / (km1 - km0);
|
||||
double rise = alt1 - alt0;
|
||||
double h = km1 - km0;
|
||||
|
||||
slope = 100 * (rise / (sqrt(h * h - rise * rise)));
|
||||
}
|
||||
|
||||
add.x = 1000 * point->km; // record distance in meters
|
||||
add.y = alt;
|
||||
add.val = slope;
|
||||
|
||||
if (fHasLat) add.lat = point->lat;
|
||||
if (fHasLon) add.lon = point->lon;
|
||||
if (fHasGPS) {
|
||||
add.lat = point->lat;
|
||||
add.lon = point->lon;
|
||||
}
|
||||
|
||||
if (add.y > MaxWatts) MaxWatts = add.y;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user