forked from organicmaps/organicmaps
[transit] Fix color-picking of 'text' color variations.
This commit is contained in:
parent
a5ed725c26
commit
8ebca48abc
3 changed files with 38 additions and 3 deletions
|
@ -1,7 +1,6 @@
|
|||
#include "transit/world_feed/color_picker.hpp"
|
||||
|
||||
#include "drape_frontend/apply_feature_functors.hpp"
|
||||
#include "drape_frontend/color_constants.hpp"
|
||||
|
||||
#include "drape/color.hpp"
|
||||
|
||||
|
@ -27,7 +26,17 @@ double GetSquareDistance(dp::Color const & color1, dp::Color const & color2)
|
|||
|
||||
namespace transit
|
||||
{
|
||||
ColorPicker::ColorPicker() { df::LoadTransitColors(); }
|
||||
ColorPicker::ColorPicker()
|
||||
{
|
||||
df::LoadTransitColors();
|
||||
// We need only colors for route polylines, not for text. So we skip items like
|
||||
// 'transit_text_navy' and work only with items like 'transit_navy'.
|
||||
for (auto const & [name, color] : df::GetTransitClearColors())
|
||||
{
|
||||
if (name.find(df::kTransitTextPrefix) == std::string::npos)
|
||||
m_drapeClearColors.emplace(name, color);
|
||||
}
|
||||
}
|
||||
|
||||
std::string ColorPicker::GetNearestColor(std::string const & rgb)
|
||||
{
|
||||
|
@ -49,7 +58,7 @@ std::string ColorPicker::GetNearestColor(std::string const & rgb)
|
|||
dp::Color const color = df::ToDrapeColor(static_cast<uint32_t>(intColor));
|
||||
double minDist = std::numeric_limits<double>::max();
|
||||
|
||||
for (auto const & [name, transitColor] : df::GetTransitClearColors())
|
||||
for (auto const & [name, transitColor] : m_drapeClearColors)
|
||||
{
|
||||
if (double const dist = GetSquareDistance(color, transitColor); dist < minDist)
|
||||
{
|
||||
|
@ -57,6 +66,7 @@ std::string ColorPicker::GetNearestColor(std::string const & rgb)
|
|||
nearestColor = name;
|
||||
}
|
||||
}
|
||||
|
||||
if (nearestColor.find(df::kTransitColorPrefix + df::kTransitLinePrefix) == 0)
|
||||
{
|
||||
nearestColor =
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "drape_frontend/color_constants.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
|
@ -13,5 +16,6 @@ public:
|
|||
|
||||
private:
|
||||
std::unordered_map<std::string, std::string> m_colorsToNames;
|
||||
std::map<std::string, dp::Color> m_drapeClearColors;
|
||||
};
|
||||
} // namespace transit
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
#include "testing/testing.hpp"
|
||||
|
||||
#include "transit/world_feed/color_picker.hpp"
|
||||
#include "transit/world_feed/date_time_helpers.hpp"
|
||||
#include "transit/world_feed/feed_helpers.hpp"
|
||||
|
||||
#include "platform/platform.hpp"
|
||||
|
||||
#include "base/assert.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
|
@ -309,4 +312,22 @@ UNIT_TEST(Transit_GTFS_ProjectStopToLine_NearCircle)
|
|||
TestPlanFact(14, true, PrepareNearestPointOnTrack(point_E, 12 /* startIndex */, shape));
|
||||
TestPlanFact(20, true, PrepareNearestPointOnTrack(point_F, 14 /* startIndex */, shape));
|
||||
}
|
||||
|
||||
UNIT_TEST(Transit_ColorPicker)
|
||||
{
|
||||
auto const & options = GetTestingOptions();
|
||||
GetPlatform().SetResourceDir(options.m_resourcePath);
|
||||
|
||||
ColorPicker colorPicker;
|
||||
|
||||
// We check that we don't match with the 'text' colors subset. This is the color of transit
|
||||
// text lime_light and we expect not to pick it.
|
||||
TEST_EQUAL(colorPicker.GetNearestColor("827717"), "lime_dark", ());
|
||||
|
||||
// We check the default color for invalid input.
|
||||
TEST_EQUAL(colorPicker.GetNearestColor("94141230"), "default", ());
|
||||
|
||||
// We check that we really find nearest colors. This input is really close to pink light.
|
||||
TEST_EQUAL(colorPicker.GetNearestColor("d18aa2"), "pink_light", ());
|
||||
}
|
||||
} // namespace
|
||||
|
|
Loading…
Add table
Reference in a new issue