Skip to content

Commit

Permalink
Wrong uphill calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-osm committed Aug 16, 2024
1 parent a906f51 commit c0fd8ee
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Sources/GPX/OAGPXTrackAnalysis.mm
Original file line number Diff line number Diff line change
Expand Up @@ -636,8 +636,7 @@ @implementation OAElevationApproximator

NSMutableArray<NSNumber *> *survived = [NSMutableArray arrayWithObject:@NO count:pointsCount];
int lastSurvived = 0;
survived[0] = @YES;
int survidedCount = 1;
int survidedCount = 0;
for (int i = 1; i < pointsCount - 1; i++)
{
double prevEle = [splitSegment get:lastSurvived].elevation;
Expand All @@ -650,14 +649,12 @@ @implementation OAElevationApproximator
survidedCount++;
}
}
survived[pointsCount - 1] = @YES;
survidedCount++;
if (survidedCount < 4)
if (survidedCount < 2)
return nil;

lastSurvived = 0;
survidedCount = 1;
for (int i = 1; i < pointsCount; i++)
survidedCount = 0;
for (int i = 1; i < pointsCount - 1; i++)
{
if (![survived[i] boolValue])
continue;
Expand All @@ -676,21 +673,25 @@ @implementation OAElevationApproximator
lastSurvived = i;
survidedCount++;
}
if (survidedCount < 4)
if (survidedCount < 2)
return nil;

survived[0] = @YES;
survived[pointsCount - 1] = @YES;
NSMutableArray<OAApproxResult *> *res = [NSMutableArray array];
int k = 0;
lastSurvived = 0;
for (int i = 0; i < pointsCount; i++)
{
if (![survived[i] boolValue] || k == survidedCount)
if (![survived[i] boolValue])
continue;

OAWptPt *point = [splitSegment get:i];
OAWptPt *lastPoint = [splitSegment get:lastSurvived];

[res addObject:[[OAApproxResult alloc] initWithDist:lastSurvived == i ? 0 : [OAMapUtils getDistance:point.position second:lastPoint.position] ele:point.elevation]];
[res addObject:[[OAApproxResult alloc] initWithDist:lastSurvived == 0
? 0 : [OAMapUtils getDistance:point.position second:lastPoint.position]
ele:point.elevation]];

k++;
lastSurvived = i;
Expand Down

0 comments on commit c0fd8ee

Please sign in to comment.