diff options
author | Maxim Pimenov <m@maps.me> | 2016-10-04 19:17:18 +0300 |
---|---|---|
committer | Maxim Pimenov <m@maps.me> | 2016-10-12 14:12:05 +0300 |
commit | d08a086c592c57c8a0bb1f85233e4405dadc69de (patch) | |
tree | ff5148c8cb71d575a418bbfb7dcf8fae42b9fd76 /coding/traffic.cpp | |
parent | b624f9f227a25e0720f2a453b29edc0b80f5c259 (diff) |
[coding] Added a serialization method for traffic coords.
Diffstat (limited to 'coding/traffic.cpp')
-rw-r--r-- | coding/traffic.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/coding/traffic.cpp b/coding/traffic.cpp new file mode 100644 index 0000000000..2883a5f1f3 --- /dev/null +++ b/coding/traffic.cpp @@ -0,0 +1,27 @@ +#include "coding/traffic.hpp" + +#include "base/math.hpp" + +namespace coding +{ +// static +uint32_t const TrafficGPSEncoder::kLatestVersion = 0; +uint32_t const TrafficGPSEncoder::kCoordBits = 30; +double const TrafficGPSEncoder::kMinDeltaLat = ms::LatLon::kMinLat - ms::LatLon::kMaxLat; +double const TrafficGPSEncoder::kMaxDeltaLat = ms::LatLon::kMaxLat - ms::LatLon::kMinLat; +double const TrafficGPSEncoder::kMinDeltaLon = ms::LatLon::kMinLon - ms::LatLon::kMaxLon; +double const TrafficGPSEncoder::kMaxDeltaLon = ms::LatLon::kMaxLon - ms::LatLon::kMinLon; + +// static +uint32_t TrafficGPSEncoder::DoubleToUint32(double x, double min, double max) +{ + x = my::clamp(x, min, max); + return static_cast<uint32_t>(0.5 + (x - min) / (max - min) * ((1 << kCoordBits) - 1)); +} + +// static +double TrafficGPSEncoder::Uint32ToDouble(uint32_t x, double min, double max) +{ + return min + static_cast<double>(x) * (max - min) / ((1 << kCoordBits) - 1); +} +} // namespace coding |