-
Notifications
You must be signed in to change notification settings - Fork 9
/
time_axis.cpp
37 lines (30 loc) · 878 Bytes
/
time_axis.cpp
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
36
37
#include "time_axis.h"
TimeAxis::TimeAxis(TimeRange range, float min, float max) {
begin = range.begin;
end = range.end;
minimum = min;
maximum = max;
}
TimeAxis::TimeAxis(QDateTime begin, QDateTime end, float min, float max) {
this->begin = begin;
this->end = end;
minimum = min;
maximum = max;
}
float TimeAxis::timeToCoord(QDateTime time) const {
float level = (float)(time.toTime_t() - begin.toTime_t()) / (float)(end.toTime_t() - begin.toTime_t());
return (level * (maximum - minimum)) + minimum;
}
QDateTime TimeAxis::coordToTime(float coord) const {
float level = (coord - minimum) / (maximum - minimum);
return begin.addSecs((float)(end.toTime_t() - begin.toTime_t()) * level);
}
float TimeAxis::getMaxCoord() const {
return maximum;
}
QDateTime TimeAxis::getMinTime() const {
return begin;
}
QDateTime TimeAxis::getMaxTime() const {
return end;
}