review fixes

This commit is contained in:
ExMix 2014-09-30 12:44:44 +03:00 committed by Alex Zolotarev
parent 6b1eb715ee
commit 41f1c2a11a
5 changed files with 35 additions and 41 deletions

View file

@ -404,7 +404,10 @@ namespace
{
Track track(m_points);
track.SetName(m_name);
track.SetColor(m_trackColor);
Track::TrackOutline trackOutline { 5.0f, m_trackColor };
track.AddOutline(&trackOutline, 1);
/// @todo Add description, style, timestamp
m_category.AddTrack(track);
}
@ -749,7 +752,7 @@ void BookmarkCategory::SaveToKML(ostream & s)
s << "</name>\n";
s << "<Style><LineStyle>";
graphics::Color const & col = track->GetColor();
graphics::Color const & col = track->GetMainColor();
s << "<color>"
<< NumToHex(col.a)
<< NumToHex(col.b)
@ -758,7 +761,7 @@ void BookmarkCategory::SaveToKML(ostream & s)
s << "</color>\n";
s << "<width>"
<< track->GetWidth();
<< track->GetMainWidth();
s << "</width>\n";
s << "</LineStyle></Style>\n";

View file

@ -1885,15 +1885,14 @@ void Framework::InsertRoute(routing::Route const & route)
else
cat->ClearTracks();
float visScale = GetVisualScale();
float const visScale = GetVisualScale();
Track track(route.GetPoly());
track.SetName(route.GetName());
track.SetColor(graphics::Color(0x73, 0xCC,0xFF, 0xFF));
track.SetWidth(6.0f * visScale);
Track::TrackOutline outlines[]
{
{ 6.0f * visScale, graphics::Color(0x73, 0xCC,0xFF, 0xFF) },
{ 12.0f * visScale, graphics::Color(0x40, 0xB9, 0xFF, 0xFF) },
{ 16.0f * visScale, graphics::Color::White() }
};

View file

@ -664,7 +664,7 @@ UNIT_TEST(TrackParsingTest_1)
Track const * track = cat->GetTrack(i);
TEST_EQUAL(names[i], track->GetName(), ());
TEST(AlmostEqual(track->GetLengthMeters(), length[i]), (track->GetLengthMeters(), length[i]));
TEST_EQUAL(col[i], track->GetColor(), ());
TEST_EQUAL(col[i], track->GetMainColor(), ());
}
}
@ -678,6 +678,6 @@ UNIT_TEST(TrackParsingTest_2)
TEST_EQUAL(cat->GetTracksCount(), 1, ());
Track const * track = cat->GetTrack(0);
TEST_EQUAL(track->GetName(), "XY", ());
TEST_EQUAL(track->GetColor(), graphics::Color(57, 255, 32, 255), ());
TEST_EQUAL(track->GetMainColor(), graphics::Color(57, 255, 32, 255), ());
}

View file

@ -27,18 +27,30 @@ Track * Track::CreatePersistent()
return p;
}
float Track::GetMainWidth() const
{
ASSERT(!m_outlines.empty(), ());
return m_outlines.back().m_lineWidth;
}
const graphics::Color & Track::GetMainColor() const
{
ASSERT(!m_outlines.empty(), ());
return m_outlines.back().m_color;
}
void Track::DeleteDisplayList() const
{
if (m_dList)
{
delete m_dList;
m_dList = 0;
m_dList = nullptr;
}
}
void Track::AddOutline(TrackOutline const * outline, int arraySize)
void Track::AddOutline(TrackOutline const * outline, size_t arraySize)
{
m_outlines.reserve(arraySize);
m_outlines.reserve(m_outlines.size() + arraySize);
for_each(outline, outline + arraySize, MakeBackInsertFunctor(m_outlines));
sort(m_outlines.begin(), m_outlines.end(), [](TrackOutline const & l, TrackOutline const & r)
{
@ -81,9 +93,6 @@ void Track::CreateDisplayList(graphics::Screen * dlScreen, MatrixT const & matri
dlScreen->beginFrame();
dlScreen->setDisplayList(m_dList);
graphics::Pen::Info info(m_color, m_width);
uint32_t resId = dlScreen->mapInfo(info);
typedef buffer_vector<m2::PointD, 32> PointContainerT;
size_t const count = m_polyline.GetSize();
@ -92,10 +101,10 @@ void Track::CreateDisplayList(graphics::Screen * dlScreen, MatrixT const & matri
PointContainerT pts2;
pts2.reserve(count);
SimplifyDP(pts1.begin(), pts1.end(), math::sqr(m_width),
SimplifyDP(pts1.begin(), pts1.end(), math::sqr(GetMainWidth()),
m2::DistanceToLineSquare<m2::PointD>(), MakeBackInsertFunctor(pts2));
double baseDepth = graphics::tracksOutlineDepth - 10 * m_outlines.size();
double baseDepth = graphics::tracksDepth - 10 * m_outlines.size();
for (TrackOutline const & outline : m_outlines)
{
graphics::Pen::Info const outlineInfo(outline.m_color, outline.m_lineWidth);
@ -104,8 +113,6 @@ void Track::CreateDisplayList(graphics::Screen * dlScreen, MatrixT const & matri
baseDepth += 10;
}
dlScreen->drawPath(pts2.data(), pts2.size(), 0, resId, graphics::tracksDepth);
if (!m_beginSymbols.empty() || !m_endSymbols.empty())
{
m2::PointD pivot = pts2.front();
@ -151,8 +158,6 @@ double Track::GetShortestSquareDistance(m2::PointD const & point) const
void Track::Swap(Track & rhs)
{
swap(m_isVisible, rhs.m_isVisible);
swap(m_width, rhs.m_width);
swap(m_color, rhs.m_color);
swap(m_rect, rhs.m_rect);
swap(m_outlines, rhs.m_outlines);
swap(m_beginSymbols, rhs.m_beginSymbols);

View file

@ -20,21 +20,14 @@ class Track : private noncopyable
typedef math::Matrix<double, 3, 3> MatrixT;
public:
Track() {}
~Track();
typedef m2::PolylineD PolylineD;
Track()
: m_isVisible(true), m_width(5),
m_color(graphics::Color::fromARGB(0xFFFF0000)),
m_dList(0)
{}
explicit Track(PolylineD const & polyline)
: m_isVisible(true), m_width(5),
m_color(graphics::Color::fromARGB(0xFFFF0000)),
m_polyline(polyline),
m_dList(0)
: m_isVisible(true),
m_polyline(polyline)
{
ASSERT_GREATER(polyline.GetSize(), 1, ());
@ -43,6 +36,8 @@ public:
/// @note Move semantics is used here.
Track * CreatePersistent();
float GetMainWidth() const;
graphics::Color const & GetMainColor() const;
void Draw(graphics::Screen * pScreen, MatrixT const & matrix) const;
void CreateDisplayList(graphics::Screen * dlScreen, MatrixT const & matrix) const;
@ -54,19 +49,13 @@ public:
bool IsVisible() const { return m_isVisible; }
void SetVisible(bool visible) { m_isVisible = visible; }
float GetWidth() const { return m_width; }
void SetWidth(float width) { m_width = width; }
graphics::Color const & GetColor() const { return m_color; }
void SetColor(graphics::Color const & color) { m_color = color; }
struct TrackOutline
{
float m_lineWidth;
graphics::Color m_color;
};
void AddOutline(TrackOutline const * outline, int arraySize);
void AddOutline(TrackOutline const * outline, size_t arraySize);
string const & GetName() const { return m_name; }
void SetName(string const & name) { m_name = name; }
@ -84,10 +73,8 @@ public:
void Swap(Track & rhs);
private:
bool m_isVisible;
bool m_isVisible = false;
string m_name;
float m_width;
graphics::Color m_color;
vector<TrackOutline> m_outlines;
@ -106,5 +93,5 @@ private:
PolylineD m_polyline;
m2::RectD m_rect;
mutable graphics::DisplayList * m_dList;
mutable graphics::DisplayList * m_dList = nullptr;
};