2016-09-19 00:55:03 +02:00
|
|
|
#ifndef GRAPH_H
|
|
|
|
#define GRAPH_H
|
|
|
|
|
2019-02-11 23:28:08 +01:00
|
|
|
#include <QList>
|
2016-09-19 00:55:03 +02:00
|
|
|
#include <QVector>
|
2016-11-05 20:00:14 +01:00
|
|
|
#include <QDebug>
|
2016-09-19 23:35:04 +02:00
|
|
|
#include <cmath>
|
2016-09-19 00:55:03 +02:00
|
|
|
|
2016-09-19 23:35:04 +02:00
|
|
|
enum GraphType {Distance, Time};
|
|
|
|
|
|
|
|
class GraphPoint
|
2016-09-19 00:55:03 +02:00
|
|
|
{
|
|
|
|
public:
|
2016-09-19 23:35:04 +02:00
|
|
|
GraphPoint(qreal s = NAN, qreal t = NAN, qreal y = NAN)
|
|
|
|
: _s(s), _t(t), _y(y) {}
|
|
|
|
|
|
|
|
qreal s() const {return _s;}
|
|
|
|
qreal t() const {return _t;}
|
|
|
|
qreal y() const {return _y;}
|
2016-10-12 20:38:18 +02:00
|
|
|
qreal x(GraphType type) const {return (type == Distance) ? _s : _t;}
|
2016-09-19 00:55:03 +02:00
|
|
|
|
2016-09-19 23:35:04 +02:00
|
|
|
void setS(qreal s) {_s = s;}
|
|
|
|
void setT(qreal t) {_t = t;}
|
|
|
|
void setY(qreal y) {_y = y;}
|
|
|
|
|
|
|
|
private:
|
|
|
|
qreal _s;
|
|
|
|
qreal _t;
|
|
|
|
qreal _y;
|
2016-09-19 00:55:03 +02:00
|
|
|
};
|
|
|
|
|
2016-11-05 20:00:14 +01:00
|
|
|
Q_DECLARE_TYPEINFO(GraphPoint, Q_PRIMITIVE_TYPE);
|
2017-11-26 18:54:03 +01:00
|
|
|
|
2018-02-13 23:03:18 +01:00
|
|
|
#ifndef QT_NO_DEBUG
|
2017-11-26 18:54:03 +01:00
|
|
|
inline QDebug operator<<(QDebug dbg, const GraphPoint &point)
|
|
|
|
{
|
|
|
|
dbg.nospace() << "GraphPoint(" << point.s() << ", " << point.t() << ", "
|
|
|
|
<< point.y() << ")";
|
|
|
|
return dbg.space();
|
|
|
|
}
|
2018-02-13 23:03:18 +01:00
|
|
|
#endif // QT_NO_DEBUG
|
2016-11-05 20:00:14 +01:00
|
|
|
|
2019-02-11 23:28:08 +01:00
|
|
|
typedef QVector<GraphPoint> GraphSegment;
|
|
|
|
|
|
|
|
class Graph : public QList<GraphSegment>
|
2019-01-31 01:46:53 +01:00
|
|
|
{
|
|
|
|
public:
|
2019-02-11 23:28:08 +01:00
|
|
|
bool isValid() const
|
|
|
|
{
|
|
|
|
if (isEmpty())
|
|
|
|
return false;
|
|
|
|
for (int i = 0; i < size(); i++)
|
|
|
|
if (at(i).size() < 2)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
bool hasTime() const
|
|
|
|
{
|
|
|
|
for (int i = 0; i < size(); i++) {
|
|
|
|
const GraphSegment &segment = at(i);
|
|
|
|
for (int j = 0; j < segment.size(); j++)
|
|
|
|
if (std::isnan(segment.at(j).t()))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2019-01-31 01:46:53 +01:00
|
|
|
};
|
2016-09-19 23:35:04 +02:00
|
|
|
|
2016-09-19 00:55:03 +02:00
|
|
|
#endif // GRAPH_H
|