diff options
author | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2016-08-12 13:01:35 +0300 |
---|---|---|
committer | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2016-08-23 15:47:43 +0300 |
commit | 2810f6b92636d738b244dbcb681ce647dbafc23f (patch) | |
tree | 86ecf02297f4a7028698d2f75ae8fe941e553ac0 /geometry | |
parent | 135a12cd030a8bf0c62caaae621bc625a8ff1be1 (diff) |
Refactored routing rendering
Diffstat (limited to 'geometry')
-rw-r--r-- | geometry/polyline2d.hpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/geometry/polyline2d.hpp b/geometry/polyline2d.hpp index d10c1cccf5..681a4e811b 100644 --- a/geometry/polyline2d.hpp +++ b/geometry/polyline2d.hpp @@ -89,6 +89,26 @@ public: return m_points[idx]; } + Point<T> GetPointByDistance(T distance) const + { + if (distance < 0) + return m_points.front(); + + T dist = 0; + for (size_t i = 1; i < m_points.size(); ++i) + { + T const oldDist = dist; + dist += m_points[i - 1].Length(m_points[i]); + if (distance <= dist) + { + T const t = (distance - oldDist) / (dist - oldDist); + return m_points[i - 1] * (1 - t) + m_points[i] * t; + } + } + + return m_points.back(); + } + vector<Point<T> > const & GetPoints() const { return m_points; } friend string DebugPrint(PolylineT<T> const & p) |