{"action":"created","comment":{"url":"https://api.github.com/repos/mapsme/omim/pulls/comments/46118147","id":46118147,"diff_hunk":"@@ -0,0 +1,304 @@\n+#include \"drape_frontend/gps_track_renderer.hpp\"\n+#include \"drape_frontend/visual_params.hpp\"\n+\n+#include \"drape/glsl_func.hpp\"\n+#include \"drape/shader_def.hpp\"\n+#include \"drape/vertex_array_buffer.hpp\"\n+\n+#include \"indexer/scales.hpp\"\n+\n+#include \"base/logging.hpp\"\n+\n+namespace df\n+{\n+\n+namespace\n+{\n+\n+int const kMinVisibleZoomLevel = 14;\n+\n+size_t const kAveragePointsCount = 512;\n+\n+float const kRadiusInPixel[] =\n+{\n+  // 1   2     3     4     5     6     7     8     9     10\n+  1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f,\n+  //11   12    13    14    15    16    17    18    19     20\n+  1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 2.0f, 2.0f, 3.0f, 4.0f, 5.0f\n+};\n+\n+double const kMinSpeed = 1.0;\n+double const kAvgSpeed = 2.0;\n+double const kMaxSpeed = 5.0;\n+dp::Color const kMinSpeedColor = dp::Color(255, 0, 0, 255);\n+dp::Color const kAvgSpeedColor = dp::Color(255, 255, 0, 255);\n+dp::Color const kMaxSpeedColor = dp::Color(0, 255, 0, 255);\n+\n+bool GpsPointsSortPredicate(GpsTrackPoint const & pt1, GpsTrackPoint const & pt2)\n+{\n+  return pt1.m_id < pt2.m_id;\n+}\n+\n+dp::Color InterpolateColors(dp::Color const & color1, dp::Color const & color2, double t)\n+{\n+  double const r = color1.GetRed() * (1.0 - t) + color2.GetRed() * t;\n+  double const g = color1.GetGreen() * (1.0 - t) + color2.GetGreen() * t;\n+  double const b = color1.GetBlue() * (1.0 - t) + color2.GetBlue() * t;\n+  double const a = color1.GetAlfa() * (1.0 - t) + color2.GetAlfa() * t;\n+  return dp::Color(r, g, b, a);\n+}\n+\n+} // namespace\n+\n+GpsTrackRenderer::GpsTrackRenderer(TRenderDataRequestFn const & dataRequestFn)\n+  : m_dataRequestFn(dataRequestFn)\n+  , m_needUpdate(false)\n+  , m_waitForRenderData(false)\n+  , m_startSpeed(0.0)\n+  , m_endSpeed(0.0)\n+  , m_startColor(kMaxSpeedColor)\n+{\n+  ASSERT(m_dataRequestFn != nullptr, ());\n+  m_points.reserve(kAveragePointsCount);\n+  m_handlesCache.reserve(8);\n+}\n+\n+float GpsTrackRenderer::CalculateRadius(ScreenBase const & screen) const\n+{\n+  double const zoomLevel = my::clamp(fabs(log(screen.GetScale()) / log(2.0)), 1.0, scales::UPPER_STYLE_SCALE + 1.0);\n+  double zoom = trunc(zoomLevel);\n+  int const index = zoom - 1.0;\n+  float const lerpCoef = zoomLevel - zoom;\n+\n+  float radius = 0.0f;\n+  if (index < scales::UPPER_STYLE_SCALE)\n+    radius = kRadiusInPixel[index] + lerpCoef * (kRadiusInPixel[index + 1] - kRadiusInPixel[index]);\n+  else\n+    radius = kRadiusInPixel[scales::UPPER_STYLE_SCALE];\n+\n+  return radius * VisualParams::Instance().GetVisualScale();\n+}\n+\n+void GpsTrackRenderer::AddRenderData(ref_ptr<dp::GpuProgramManager> mng,\n+                                     drape_ptr<GpsTrackRenderData> && renderData)\n+{\n+  drape_ptr<GpsTrackRenderData> data = move(renderData);\n+  ref_ptr<dp::GpuProgram> program = mng->GetProgram(gpu::TRACK_POINT_PROGRAM);\n+  program->Bind();\n+  data->m_bucket->GetBuffer()->Build(program);\n+  m_renderData.push_back(move(data));\n+}\n+\n+void GpsTrackRenderer::UpdatePoints(vector<GpsTrackPoint> const & toAdd, vector<uint32_t> const & toRemove)\n+{\n+  if (!toRemove.empty())\n+  {\n+    auto removePredicate = [&toRemove](GpsTrackPoint const & pt)\n+    {\n+      return find(toRemove.begin(), toRemove.end(), pt.m_id) != toRemove.end();\n+    };\n+    m_points.erase(remove_if(m_points.begin(), m_points.end(), removePredicate), m_points.end());\n+  }\n+\n+  if (!toAdd.empty())\n+  {\n+    m_points.insert(m_points.begin(), toAdd.begin(), toAdd.end());\n+    sort(m_points.begin(), m_points.end(), GpsPointsSortPredicate);\n+  }\n+\n+  m_needUpdate = true;\n+}\n+\n+double GpsTrackRenderer::CalculateTrackLength() const\n+{\n+  double len = 0.0;\n+  for (size_t i = 0; i + 1 < m_points.size(); i++)\n+    len += (m_points[i + 1].m_point - m_points[i].m_point).Length();","path":"drape_frontend/gps_track_renderer.cpp","position":116,"original_position":116,"commit_id":"45db4abb18cfce2ef379dbdd7056d9c57e122466","original_commit_id":"45db4abb18cfce2ef379dbdd7056d9c57e122466","user":{"login":"kshalnev","id":8023141,"avatar_url":"https://avatars.githubusercontent.com/u/8023141?v=3","gravatar_id":"","url":"https://api.github.com/users/kshalnev","html_url":"https://github.com/kshalnev","followers_url":"https://api.github.com/users/kshalnev/followers","following_url":"https://api.github.com/users/kshalnev/following{/other_user}","gists_url":"https://api.github.com/users/kshalnev/gists{/gist_id}","starred_url":"https://api.github.com/users/kshalnev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kshalnev/subscriptions","organizations_url":"https://api.github.com/users/kshalnev/orgs","repos_url":"https://api.github.com/users/kshalnev/repos","events_url":"https://api.github.com/users/kshalnev/events{/privacy}","received_events_url":"https://api.github.com/users/kshalnev/received_events","type":"User","site_admin":false},"body":"у нас есть функция вычисления длины по глобусу.","created_at":"2015-11-30T08:41:05Z","updated_at":"2015-11-30T08:41:05Z","html_url":"https://github.com/mapsme/omim/pull/758#discussion_r46118147","pull_request_url":"https://api.github.com/repos/mapsme/omim/pulls/758","_links":{"self":{"href":"https://api.github.com/repos/mapsme/omim/pulls/comments/46118147"},"html":{"href":"https://github.com/mapsme/omim/pull/758#discussion_r46118147"},"pull_request":{"href":"https://api.github.com/repos/mapsme/omim/pulls/758"}}},"pull_request":{"url":"https://api.github.com/repos/mapsme/omim/pulls/758","id":52068690,"html_url":"https://github.com/mapsme/omim/pull/758","diff_url":"https://github.com/mapsme/omim/pull/758.diff","patch_url":"https://github.com/mapsme/omim/pull/758.patch","issue_url":"https://api.github.com/repos/mapsme/omim/issues/758","number":758,"state":"open","locked":false,"title":"[gpstracks] GPS track visualization","user":{"login":"rokuz","id":5437220,"avatar_url":"https://avatars.githubusercontent.com/u/5437220?v=3","gravatar_id":"","url":"https://api.github.com/users/rokuz","html_url":"https://github.com/rokuz","followers_url":"https://api.github.com/users/rokuz/followers","following_url":"https://api.github.com/users/rokuz/following{/other_user}","gists_url":"https://api.github.com/users/rokuz/gists{/gist_id}","starred_url":"https://api.github.com/users/rokuz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rokuz/subscriptions","organizations_url":"https://api.github.com/users/rokuz/orgs","repos_url":"https://api.github.com/users/rokuz/repos","events_url":"https://api.github.com/users/rokuz/events{/privacy}","received_events_url":"https://api.github.com/users/rokuz/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-29T19:21:39Z","updated_at":"2015-11-30T08:41:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"583cf213fbbaa53a425418528662ae64c03b078a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/mapsme/omim/pulls/758/commits","review_comments_url":"https://api.github.com/repos/mapsme/omim/pulls/758/comments","review_comment_url":"https://api.github.com/repos/mapsme/omim/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mapsme/omim/issues/758/comments","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/45db4abb18cfce2ef379dbdd7056d9c57e122466","head":{"label":"rokuz:grstracks-rendering","ref":"grstracks-rendering","sha":"45db4abb18cfce2ef379dbdd7056d9c57e122466","user":{"login":"rokuz","id":5437220,"avatar_url":"https://avatars.githubusercontent.com/u/5437220?v=3","gravatar_id":"","url":"https://api.github.com/users/rokuz","html_url":"https://github.com/rokuz","followers_url":"https://api.github.com/users/rokuz/followers","following_url":"https://api.github.com/users/rokuz/following{/other_user}","gists_url":"https://api.github.com/users/rokuz/gists{/gist_id}","starred_url":"https://api.github.com/users/rokuz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rokuz/subscriptions","organizations_url":"https://api.github.com/users/rokuz/orgs","repos_url":"https://api.github.com/users/rokuz/repos","events_url":"https://api.github.com/users/rokuz/events{/privacy}","received_events_url":"https://api.github.com/users/rokuz/received_events","type":"User","site_admin":false},"repo":{"id":43427777,"name":"omim","full_name":"rokuz/omim","owner":{"login":"rokuz","id":5437220,"avatar_url":"https://avatars.githubusercontent.com/u/5437220?v=3","gravatar_id":"","url":"https://api.github.com/users/rokuz","html_url":"https://github.com/rokuz","followers_url":"https://api.github.com/users/rokuz/followers","following_url":"https://api.github.com/users/rokuz/following{/other_user}","gists_url":"https://api.github.com/users/rokuz/gists{/gist_id}","starred_url":"https://api.github.com/users/rokuz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rokuz/subscriptions","organizations_url":"https://api.github.com/users/rokuz/orgs","repos_url":"https://api.github.com/users/rokuz/repos","events_url":"https://api.github.com/users/rokuz/events{/privacy}","received_events_url":"https://api.github.com/users/rokuz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/rokuz/omim","description":"MAPS.ME - Offline OpenStreetMap maps for iOS/Android/Mac/Linux/Windows","fork":true,"url":"https://api.github.com/repos/rokuz/omim","forks_url":"https://api.github.com/repos/rokuz/omim/forks","keys_url":"https://api.github.com/repos/rokuz/omim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rokuz/omim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rokuz/omim/teams","hooks_url":"https://api.github.com/repos/rokuz/omim/hooks","issue_events_url":"https://api.github.com/repos/rokuz/omim/issues/events{/number}","events_url":"https://api.github.com/repos/rokuz/omim/events","assignees_url":"https://api.github.com/repos/rokuz/omim/assignees{/user}","branches_url":"https://api.github.com/repos/rokuz/omim/branches{/branch}","tags_url":"https://api.github.com/repos/rokuz/omim/tags","blobs_url":"https://api.github.com/repos/rokuz/omim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rokuz/omim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rokuz/omim/git/refs{/sha}","trees_url":"https://api.github.com/repos/rokuz/omim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rokuz/omim/statuses/{sha}","languages_url":"https://api.github.com/repos/rokuz/omim/languages","stargazers_url":"https://api.github.com/repos/rokuz/omim/stargazers","contributors_url":"https://api.github.com/repos/rokuz/omim/contributors","subscribers_url":"https://api.github.com/repos/rokuz/omim/subscribers","subscription_url":"https://api.github.com/repos/rokuz/omim/subscription","commits_url":"https://api.github.com/repos/rokuz/omim/commits{/sha}","git_commits_url":"https://api.github.com/repos/rokuz/omim/git/commits{/sha}","comments_url":"https://api.github.com/repos/rokuz/omim/comments{/number}","issue_comment_url":"https://api.github.com/repos/rokuz/omim/issues/comments{/number}","contents_url":"https://api.github.com/repos/rokuz/omim/contents/{+path}","compare_url":"https://api.github.com/repos/rokuz/omim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rokuz/omim/merges","archive_url":"https://api.github.com/repos/rokuz/omim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rokuz/omim/downloads","issues_url":"https://api.github.com/repos/rokuz/omim/issues{/number}","pulls_url":"https://api.github.com/repos/rokuz/omim/pulls{/number}","milestones_url":"https://api.github.com/repos/rokuz/omim/milestones{/number}","notifications_url":"https://api.github.com/repos/rokuz/omim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rokuz/omim/labels{/name}","releases_url":"https://api.github.com/repos/rokuz/omim/releases{/id}","created_at":"2015-09-30T10:51:34Z","updated_at":"2015-09-30T10:53:43Z","pushed_at":"2015-11-29T19:20:32Z","git_url":"git://github.com/rokuz/omim.git","ssh_url":"git@github.com:rokuz/omim.git","clone_url":"https://github.com/rokuz/omim.git","svn_url":"https://github.com/rokuz/omim","homepage":null,"size":1896241,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mapsme:gpstracks","ref":"gpstracks","sha":"91dce0f19d2fde51ece1a5f3993be9959a73277c","user":{"login":"mapsme","id":14185141,"avatar_url":"https://avatars.githubusercontent.com/u/14185141?v=3","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"repo":{"id":42798033,"name":"omim","full_name":"mapsme/omim","owner":{"login":"mapsme","id":14185141,"avatar_url":"https://avatars.githubusercontent.com/u/14185141?v=3","gravatar_id":"","url":"https://api.github.com/users/mapsme","html_url":"https://github.com/mapsme","followers_url":"https://api.github.com/users/mapsme/followers","following_url":"https://api.github.com/users/mapsme/following{/other_user}","gists_url":"https://api.github.com/users/mapsme/gists{/gist_id}","starred_url":"https://api.github.com/users/mapsme/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mapsme/subscriptions","organizations_url":"https://api.github.com/users/mapsme/orgs","repos_url":"https://api.github.com/users/mapsme/repos","events_url":"https://api.github.com/users/mapsme/events{/privacy}","received_events_url":"https://api.github.com/users/mapsme/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mapsme/omim","description":"MAPS.ME - Offline OpenStreetMap maps for iOS/Android/Mac/Linux/Windows","fork":false,"url":"https://api.github.com/repos/mapsme/omim","forks_url":"https://api.github.com/repos/mapsme/omim/forks","keys_url":"https://api.github.com/repos/mapsme/omim/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mapsme/omim/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mapsme/omim/teams","hooks_url":"https://api.github.com/repos/mapsme/omim/hooks","issue_events_url":"https://api.github.com/repos/mapsme/omim/issues/events{/number}","events_url":"https://api.github.com/repos/mapsme/omim/events","assignees_url":"https://api.github.com/repos/mapsme/omim/assignees{/user}","branches_url":"https://api.github.com/repos/mapsme/omim/branches{/branch}","tags_url":"https://api.github.com/repos/mapsme/omim/tags","blobs_url":"https://api.github.com/repos/mapsme/omim/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mapsme/omim/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mapsme/omim/git/refs{/sha}","trees_url":"https://api.github.com/repos/mapsme/omim/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mapsme/omim/statuses/{sha}","languages_url":"https://api.github.com/repos/mapsme/omim/languages","stargazers_url":"https://api.github.com/repos/mapsme/omim/stargazers","contributors_url":"https://api.github.com/repos/mapsme/omim/contributors","subscribers_url":"https://api.github.com/repos/mapsme/omim/subscribers","subscription_url":"https://api.github.com/repos/mapsme/omim/subscription","commits_url":"https://api.github.com/repos/mapsme/omim/commits{/sha}","git_commits_url":"https://api.github.com/repos/mapsme/omim/git/commits{/sha}","comments_url":"https://api.github.com/repos/mapsme/omim/comments{/number}","issue_comment_url":"https://api.github.com/repos/mapsme/omim/issues/comments{/number}","contents_url":"https://api.github.com/repos/mapsme/omim/contents/{+path}","compare_url":"https://api.github.com/repos/mapsme/omim/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mapsme/omim/merges","archive_url":"https://api.github.com/repos/mapsme/omim/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mapsme/omim/downloads","issues_url":"https://api.github.com/repos/mapsme/omim/issues{/number}","pulls_url":"https://api.github.com/repos/mapsme/omim/pulls{/number}","milestones_url":"https://api.github.com/repos/mapsme/omim/milestones{/number}","notifications_url":"https://api.github.com/repos/mapsme/omim/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mapsme/omim/labels{/name}","releases_url":"https://api.github.com/repos/mapsme/omim/releases{/id}","created_at":"2015-09-20T02:57:13Z","updated_at":"2015-11-29T18:18:04Z","pushed_at":"2015-11-29T19:21:40Z","git_url":"git://github.com/mapsme/omim.git","ssh_url":"git@github.com:mapsme/omim.git","clone_url":"https://github.com/mapsme/omim.git","svn_url":"https://github.com/mapsme/omim","homepage":null,"size":1902533,"stargazers_count":1498,"watchers_count":1498,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":180,"mirror_url":null,"open_issues_count":67,"forks":180,"open_issues":67,"watchers":1498,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mapsme/omim/pulls/758"},"html":{"href":"https://github.com/mapsme/omim/pull/758"},"issue":{"href":"https://api.github.com/repos/mapsme/omim/issues/758"},"comments":{"href":"https://api.github.com/repos/mapsme/omim/issues/758/comments"},"review_comments":{"href":"https://api.github.com/repos/mapsme/omim/pulls/758/comments"},"review_comment":{"href":"https://api.github.com/repos/mapsme/omim/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mapsme/omim/pulls/758/commits"},"statuses":{"href":"https://api.github.com/repos/mapsme/omim/statuses/45db4abb18cfce2ef379dbdd7056d9c57e122466"}}}}