Commit c30b4218 authored by Volker Krause's avatar Volker Krause
Browse files

Add helper methods for determining the stand and end points of paths

parent f36365e9
......@@ -38,6 +38,16 @@ int PathSection::distance() const
return dist;
}
QPointF PathSection::startPoint() const
{
return d->path.empty() ? QPointF() : d->path.constFirst();
}
QPointF KPublicTransport::PathSection::endPoint() const
{
return d->path.empty() ? QPointF() : d->path.constLast();
}
QJsonObject PathSection::toJson(const PathSection &section)
{
auto obj = Json::toJson(section);
......@@ -101,6 +111,16 @@ int Path::distance() const
return std::accumulate(d->sections.begin(), d->sections.end(), 0, [](int d, const auto &sec) { return d + sec.distance(); });
}
QPointF Path::startPoint() const
{
return isEmpty() ? QPointF() : d->sections.front().startPoint();
}
QPointF Path::endPoint() const
{
return isEmpty() ? QPointF() : d->sections.front().endPoint();
}
QJsonObject Path::toJson(const Path &path)
{
auto obj = Json::toJson(path);
......
......@@ -38,6 +38,11 @@ public:
/** Length of this path section in meters. */
int distance() const;
/** First point on the path of this section. */
QPointF startPoint() const;
/** Last point on the path of this section. */
QPointF endPoint() const;
/** Serializes one path section section to JSON. */
static QJsonObject toJson(const PathSection &section);
/** Serializes a vector of path sections to JSON. */
......@@ -83,6 +88,11 @@ public:
/** Length of this path in meters. */
int distance() const;
/** First point on this path. */
QPointF startPoint() const;
/** Last point on this path. */
QPointF endPoint() const;
/** Serializes one path object to JSON. */
static QJsonObject toJson(const Path &path);
/** Deserialize an object from JSON. */
......
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