Commit 977db8f9 authored by Volker Krause's avatar Volker Krause
Browse files

Add path section direction computation

parent f217e480
Pipeline #74081 passed with stage
in 18 seconds
......@@ -10,6 +10,8 @@
#include "../geo/geojson_p.h"
#include "location.h"
#include <QLineF>
using namespace KPublicTransport;
namespace KPublicTransport {
......@@ -38,6 +40,16 @@ int PathSection::distance() const
return dist;
}
int PathSection::direction() const
{
const auto p1 = startPoint();
const auto p2 = endPoint();
if (d->path.size() < 2 || p1 == p2) {
return -1;
}
return static_cast<int>(450 - QLineF(p1.x(), -p1.y(), p2.x(), -p2.y()).angle()) % 360;
}
QPointF PathSection::startPoint() const
{
return d->path.empty() ? QPointF() : d->path.constFirst();
......
......@@ -33,10 +33,16 @@ class KPUBLICTRANSPORT_EXPORT PathSection
/** The length of this path section in meters. */
Q_PROPERTY(int distance READ distance STORED false)
/** The overall direction of this section in degree. */
Q_PROPERTY(int direction READ direction STORED false)
public:
/** Length of this path section in meters. */
int distance() const;
/** The overall direction of this section in degree.
* @returns 0-359 for valid results, -1 for sections with no direction (e.g. points).
*/
int direction() const;
/** First point on the path of this section. */
QPointF startPoint() const;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment