diff options
author | ExMix <rahuba.youri@mapswithme.com> | 2014-08-06 14:49:39 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 02:23:57 +0300 |
commit | 34a3eb755724523a94ae7f5d12186bb0a2211e1c (patch) | |
tree | e5d55f65a79bd52a38db228e0734c02f94654fb4 /geometry/spline.cpp | |
parent | d6883a363a0cccdb226cac8c9a707622024887d5 (diff) |
[drape] use shared spline for almost all line based features
Diffstat (limited to 'geometry/spline.cpp')
-rw-r--r-- | geometry/spline.cpp | 64 |
1 files changed, 55 insertions, 9 deletions
diff --git a/geometry/spline.cpp b/geometry/spline.cpp index ef6f9b6e07..b5e085206b 100644 --- a/geometry/spline.cpp +++ b/geometry/spline.cpp @@ -1,9 +1,13 @@ #include "spline.hpp" +#include "../base/logging.hpp" + +#include "../std/numeric.hpp" + namespace m2 { -Spline::Spline(vector<PointF> const & path) : m_lengthAll(0.0f) +Spline::Spline(vector<PointF> const & path) { ASSERT(path.size() > 1, ("Wrong path size!")); m_position.assign(path.begin(), path.end()); @@ -16,13 +20,20 @@ Spline::Spline(vector<PointF> const & path) : m_lengthAll(0.0f) m_direction[i] = path[i+1] - path[i]; m_length[i] = m_direction[i].Length(); m_direction[i] = m_direction[i].Normalize(); - m_lengthAll += m_length[i]; } } void Spline::AddPoint(PointF const & pt) { - if(m_position.empty()) + /// TODO remove this check when fix generator. + /// Now we have line objects with zero length segments + if (!IsEmpty() && (pt - m_position.back()).IsAlmostZero()) + { + LOG(LDEBUG, ("Found seqment with zero lenth (the ended points are same)")); + return; + } + + if(IsEmpty()) m_position.push_back(pt); else { @@ -30,15 +41,23 @@ void Spline::AddPoint(PointF const & pt) m_position.push_back(pt); m_length.push_back(dir.Length()); m_direction.push_back(dir.Normalize()); - m_lengthAll += m_length.back(); } } +bool Spline::IsEmpty() const +{ + return m_position.empty(); +} + +bool Spline::IsValid() const +{ + return m_position.size() > 1; +} + Spline const & Spline::operator = (Spline const & spl) { if(&spl != this) { - m_lengthAll = spl.m_lengthAll; m_position = spl.m_position; m_direction = spl.m_direction; m_length = spl.m_length; @@ -46,15 +65,20 @@ Spline const & Spline::operator = (Spline const & spl) return *this; } +float Spline::GetLength() const +{ + return accumulate(m_length.begin(), m_length.end(), 0.0f); +} + Spline::iterator::iterator() : m_checker(false) , m_spl(NULL) , m_index(0) , m_dist(0) {} -void Spline::iterator::Attach(Spline const & S) +void Spline::iterator::Attach(Spline const & spl) { - m_spl = &S; + m_spl = &spl; m_index = 0; m_dist = 0; m_checker = false; @@ -105,9 +129,19 @@ SharedSpline const & SharedSpline::operator= (SharedSpline const & spl) return *this; } -float SharedSpline::GetLength() const +bool SharedSpline::IsNull() const { - return m_spline->GetLength(); + return m_spline == NULL; +} + +void SharedSpline::Reset(Spline * spline) +{ + m_spline.reset(spline); +} + +void SharedSpline::Reset(vector<PointF> const & path) +{ + m_spline.reset(new Spline(path)); } Spline::iterator SharedSpline::CreateIterator() @@ -117,5 +151,17 @@ Spline::iterator SharedSpline::CreateIterator() return result; } +Spline * SharedSpline::operator->() +{ + ASSERT(!IsNull(), ()); + return m_spline.get(); +} + +Spline const * SharedSpline::operator->() const +{ + ASSERT(!IsNull(), ()); + return m_spline.get(); +} + } |