Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[transit] GTFS producer with unit tests.
- Loading branch information
1 parent
f93b110
commit 3bda740
Showing
16 changed files
with
3,119 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
project(world_feed) | ||
|
||
set(SRC | ||
color_picker.cpp | ||
color_picker.hpp | ||
date_time_helpers.cpp | ||
date_time_helpers.hpp | ||
feed_helpers.cpp | ||
feed_helpers.hpp | ||
world_feed.cpp | ||
world_feed.hpp | ||
) | ||
|
||
omim_add_library(${PROJECT_NAME} ${SRC}) | ||
|
||
omim_link_libraries( | ||
${PROJECT_NAME} | ||
drape_frontend | ||
shaders | ||
routing | ||
mwm_diff | ||
bsdiff | ||
tracking | ||
traffic | ||
routing_common | ||
transit | ||
descriptions | ||
ugc | ||
drape | ||
partners_api | ||
web_api | ||
local_ads | ||
kml | ||
editor | ||
indexer | ||
metrics | ||
platform | ||
geometry | ||
coding | ||
base | ||
freetype | ||
expat | ||
icu | ||
agg | ||
jansson | ||
protobuf | ||
stats_client | ||
minizip | ||
succinct | ||
pugixml | ||
oauthcpp | ||
opening_hours | ||
stb_image | ||
sdf_image | ||
vulkan_wrapper | ||
${Qt5Widgets_LIBRARIES} | ||
${Qt5Network_LIBRARIES} | ||
${LIBZ} | ||
) | ||
|
||
if (PLATFORM_LINUX) | ||
omim_link_libraries( | ||
${PROJECT_NAME} | ||
dl | ||
) | ||
endif() | ||
|
||
link_opengl(${PROJECT_NAME}) | ||
link_qt5_core(${PROJECT_NAME}) | ||
link_qt5_network(${PROJECT_NAME}) | ||
|
||
omim_add_test_subdirectory(world_feed_tests) | ||
add_subdirectory(gtfs_converter) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "transit/world_feed/color_picker.hpp" | ||
|
||
#include "drape_frontend/apply_feature_functors.hpp" | ||
#include "drape_frontend/color_constants.hpp" | ||
|
||
#include "drape/color.hpp" | ||
|
||
#include "base/string_utils.hpp" | ||
|
||
#include <limits> | ||
#include <tuple> | ||
|
||
namespace | ||
{ | ||
std::tuple<double, double, double> GetColors(dp::Color const & color) | ||
{ | ||
return {color.GetRedF(), color.GetGreenF(), color.GetBlueF()}; | ||
} | ||
|
||
double GetSquareDistance(dp::Color const & color1, dp::Color const & color2) | ||
{ | ||
auto [r1, g1, b1] = GetColors(color1); | ||
auto [r2, g2, b2] = GetColors(color2); | ||
return (r1 - r2) * (r1 - r2) + (g1 - g2) * (g1 - g2) + (b1 - b2) * (b1 - b2); | ||
} | ||
} // namespace | ||
|
||
namespace transit | ||
{ | ||
ColorPicker::ColorPicker() { df::LoadTransitColors(); } | ||
|
||
std::string ColorPicker::GetNearestColor(std::string const & rgb) | ||
{ | ||
static std::string const kDefaultColor = "default"; | ||
if (rgb.empty()) | ||
return kDefaultColor; | ||
|
||
auto [it, inserted] = m_colorsToNames.emplace(rgb, kDefaultColor); | ||
if (!inserted) | ||
return it->second; | ||
|
||
std::string nearestColor = kDefaultColor; | ||
|
||
unsigned int intColor; | ||
// We do not need to add to the cache invalid color, so we just return. | ||
if (!strings::to_uint(rgb, intColor, 16)) | ||
return nearestColor; | ||
|
||
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()) | ||
{ | ||
if (double const dist = GetSquareDistance(color, transitColor); dist < minDist) | ||
{ | ||
minDist = dist; | ||
nearestColor = name; | ||
} | ||
} | ||
if (nearestColor.find(df::kTransitColorPrefix + df::kTransitLinePrefix) == 0) | ||
{ | ||
nearestColor = | ||
nearestColor.substr(df::kTransitColorPrefix.size() + df::kTransitLinePrefix.size()); | ||
} | ||
|
||
it->second = nearestColor; | ||
return nearestColor; | ||
} | ||
} // namespace transit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include <unordered_map> | ||
|
||
namespace transit | ||
{ | ||
class ColorPicker | ||
{ | ||
public: | ||
ColorPicker(); | ||
std::string GetNearestColor(std::string const & rgb); | ||
|
||
private: | ||
std::unordered_map<std::string, std::string> m_colorsToNames; | ||
}; | ||
} // namespace transit |
Oops, something went wrong.