forked from organicmaps/organicmaps-tmp
Do avoid copy-paste. Add assertions.
This commit is contained in:
parent
cf43af3886
commit
6b51c154e2
4 changed files with 52 additions and 70 deletions
|
@ -3,17 +3,8 @@
|
|||
#include "feature_info.hpp"
|
||||
#include "drawer.hpp"
|
||||
|
||||
//#include "../platform/preferred_languages.hpp"
|
||||
|
||||
//#include "../geometry/screenbase.hpp"
|
||||
//#include "../geometry/rect_intersect.hpp"
|
||||
|
||||
//#include "../indexer/feature_visibility.hpp"
|
||||
//#include "../indexer/drawing_rules.hpp"
|
||||
//#include "../indexer/feature_data.hpp"
|
||||
#include "../indexer/feature_impl.hpp"
|
||||
|
||||
//#include "../std/bind.hpp"
|
||||
|
||||
namespace fwork
|
||||
{
|
||||
|
@ -137,6 +128,15 @@ namespace fwork
|
|||
{
|
||||
isExist = true;
|
||||
assign_path(fi, fun);
|
||||
|
||||
#ifdef DEBUG
|
||||
if (fi.m_pathes.size() == 1)
|
||||
{
|
||||
double const offset = fi.m_pathes.front().GetOffset();
|
||||
for (size_t i = 0; i < fi.m_styler.m_offsets.size(); ++i)
|
||||
ASSERT_LESS_OR_EQUAL(offset, fi.m_styler.m_offsets[i], ());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -27,17 +27,13 @@ namespace gp
|
|||
m_exist = false;
|
||||
}
|
||||
|
||||
get_path_intervals::params::params()
|
||||
: m_intervals(0)
|
||||
{}
|
||||
|
||||
get_path_intervals::get_path_intervals(params const & p)
|
||||
interval_params::interval_params(params const & p)
|
||||
: base_t(p),
|
||||
m_hasPrevPt(false),
|
||||
m_intervals(p.m_intervals),
|
||||
m_isFirst(true),
|
||||
m_length(0)
|
||||
{}
|
||||
m_length(0.0),
|
||||
m_hasPrevPt(false)
|
||||
{
|
||||
}
|
||||
|
||||
void get_path_intervals::operator()(m2::PointD const & pt)
|
||||
{
|
||||
|
@ -46,22 +42,21 @@ namespace gp
|
|||
m2::PointD prev = m_prev;
|
||||
m2::PointD cur = pt;
|
||||
|
||||
double segLen = cur.Length(prev);
|
||||
double const segLen = cur.Length(prev);
|
||||
|
||||
if (m2::Intersect(base_t::m_rect, prev, cur))
|
||||
{
|
||||
double clipStart = prev.Length(m_prev) + m_length;
|
||||
double clipEnd = cur.Length(m_prev) + m_length;
|
||||
|
||||
if (m_isFirst)
|
||||
if (m_intervals->empty())
|
||||
{
|
||||
m_intervals->push_back(clipStart);
|
||||
m_intervals->push_back(clipEnd);
|
||||
m_isFirst = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fabs(m_intervals->back() - clipStart) < 1.0E-12)
|
||||
if (my::AlmostEqual(m_intervals->back(), clipStart))
|
||||
m_intervals->back() = clipEnd;
|
||||
else
|
||||
{
|
||||
|
@ -83,47 +78,30 @@ namespace gp
|
|||
|
||||
bool get_path_intervals::IsExist() const
|
||||
{
|
||||
return !m_isFirst;
|
||||
return !m_intervals->empty();
|
||||
}
|
||||
|
||||
cut_path_intervals::params::params() : m_intervals(0)
|
||||
{}
|
||||
|
||||
cut_path_intervals::cut_path_intervals(params const & p)
|
||||
: base_t(p),
|
||||
m_length(0),
|
||||
m_isInside(false),
|
||||
m_hasPrevPt(false),
|
||||
m_intervals(p.m_intervals),
|
||||
m_pos(0)
|
||||
{}
|
||||
|
||||
void cut_path_intervals::operator()(m2::PointD const & pt)
|
||||
{
|
||||
if (m_hasPrevPt)
|
||||
{
|
||||
double segLen = pt.Length(m_prev);
|
||||
double const segLen = pt.Length(m_prev);
|
||||
|
||||
while (true)
|
||||
for (; m_pos != m_intervals->size(); m_pos += 2)
|
||||
{
|
||||
m2::PointD dir = (pt - m_prev) / segLen;
|
||||
|
||||
if (m_pos == m_intervals->size())
|
||||
double const start = (*m_intervals)[m_pos];
|
||||
if (start >= m_length + segLen)
|
||||
break;
|
||||
|
||||
double start = (*m_intervals)[m_pos];
|
||||
double end = (*m_intervals)[m_pos + 1];
|
||||
|
||||
if (start > m_length + segLen)
|
||||
break;
|
||||
m2::PointD const dir = (pt - m_prev) / segLen;
|
||||
|
||||
if (start >= m_length)
|
||||
{
|
||||
m_points.push_back(PathInfo(start));
|
||||
push_point(m_prev + dir * (start - m_length));
|
||||
m_isInside = true;
|
||||
}
|
||||
|
||||
double const end = (*m_intervals)[m_pos+1];
|
||||
if (end >= m_length + segLen)
|
||||
{
|
||||
push_point(pt);
|
||||
|
@ -133,10 +111,11 @@ namespace gp
|
|||
if (end < m_length + segLen)
|
||||
{
|
||||
push_point(m_prev + dir * (end - m_length));
|
||||
m_isInside = false;
|
||||
#ifdef DEBUG
|
||||
double const len = m_points.back().GetLength();
|
||||
ASSERT_LESS_OR_EQUAL ( fabs(len - (end - start)), 1.0E-4, (len, end - start) );
|
||||
#endif
|
||||
}
|
||||
|
||||
m_pos += 2;
|
||||
}
|
||||
|
||||
m_prev = pt;
|
||||
|
|
|
@ -167,52 +167,44 @@ namespace gp
|
|||
|
||||
void push_point(m2::PointD const & pt)
|
||||
{
|
||||
/// @todo Filter for equal points.
|
||||
m_points.back().push_back(this->convert_point(pt));
|
||||
}
|
||||
};
|
||||
|
||||
struct get_path_intervals : public geometry_base<di::PathInfo, base_screen>
|
||||
struct interval_params : public geometry_base<di::PathInfo, base_screen>
|
||||
{
|
||||
typedef geometry_base<di::PathInfo, base_screen> base_t;
|
||||
|
||||
buffer_vector<double, 16> * m_intervals;
|
||||
|
||||
bool m_hasPrevPt;
|
||||
m2::PointD m_prev;
|
||||
bool m_isFirst;
|
||||
double m_length;
|
||||
bool m_hasPrevPt;
|
||||
|
||||
struct params : base_t::params
|
||||
{
|
||||
buffer_vector<double, 16> * m_intervals;
|
||||
params();
|
||||
params() : m_intervals(0) {}
|
||||
};
|
||||
|
||||
get_path_intervals(params const & p);
|
||||
interval_params(params const & p);
|
||||
};
|
||||
|
||||
struct get_path_intervals : public interval_params
|
||||
{
|
||||
get_path_intervals(params const & p) : interval_params(p) {}
|
||||
|
||||
void operator() (m2::PointD const & pt);
|
||||
|
||||
bool IsExist() const;
|
||||
};
|
||||
|
||||
struct cut_path_intervals : public geometry_base<di::PathInfo, base_screen>
|
||||
struct cut_path_intervals : public interval_params
|
||||
{
|
||||
typedef geometry_base<di::PathInfo, base_screen> base_t;
|
||||
size_t m_pos;
|
||||
|
||||
struct params : base_t::params
|
||||
{
|
||||
buffer_vector<double, 16> * m_intervals;
|
||||
params();
|
||||
};
|
||||
|
||||
double m_length;
|
||||
bool m_isInside;
|
||||
bool m_hasPrevPt;
|
||||
m2::PointD m_prev;
|
||||
buffer_vector<double, 16> * m_intervals;
|
||||
unsigned m_pos;
|
||||
|
||||
cut_path_intervals(params const & p);
|
||||
cut_path_intervals(params const & p) : interval_params(p), m_pos(0) {}
|
||||
|
||||
void operator() (m2::PointD const & p);
|
||||
|
||||
|
|
|
@ -40,6 +40,17 @@ namespace di
|
|||
return m_fullL;
|
||||
}
|
||||
|
||||
double GetLength() const
|
||||
{
|
||||
double sum = 0.0;
|
||||
for (size_t i = 1; i < m_path.size(); ++i)
|
||||
{
|
||||
double const l = m_path[i-1].Length(m_path[i]);
|
||||
sum += l;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
double GetOffset() const
|
||||
{
|
||||
ASSERT ( m_offset >= 0.0, (m_offset) );
|
||||
|
|
Loading…
Add table
Reference in a new issue