-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtracklist.cpp
More file actions
36 lines (32 loc) · 828 Bytes
/
Copy pathtracklist.cpp
File metadata and controls
36 lines (32 loc) · 828 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "tracklist.h"
#include <QDebug>
#include <QDateTime>
bool TrackList::binarySearch(const QDateTime time, int &a, int &b) {
if (b < a) return false;
// qDebug() << "bs:" << time << ":" << this->at(a).time << "," << this->at(b).time;
if (b - a <= 1) {
return true;
}
if (time < this->at(a).time) {
return false;
}
if (time > this->at(b).time) {
return false;
}
int x = (a + b) / 2;
if (time >= this->at(x).time) {
a = x;
} else {
b = x;
}
return binarySearch(time, a, b);
}
TrackPoint TrackList::search(QDateTime time) {
int a = 0, b = this->size() - 1;
if (binarySearch(time, a, b)) {
return TrackPoint::interpolate(this->at(a), this->at(b), time);
} else {
TrackPoint a;
return a;
}
}