diff options
author | Maxim Pimenov <m@maps.me> | 2018-04-11 13:18:54 +0300 |
---|---|---|
committer | Roman Kuznetsov <r.kuznetsow@gmail.com> | 2018-04-11 16:35:42 +0300 |
commit | 980a4db1a5e9b4fcf8686ca603bf7e185b918fd7 (patch) | |
tree | f469a9a547e46905d24e185e7c56704035914238 /indexer/cities_boundaries_serdes.hpp | |
parent | c98926252d75f25753b17a9a93c6fdd671c3bd04 (diff) |
[coding] Refactored EncodeDelta for points.
Diffstat (limited to 'indexer/cities_boundaries_serdes.hpp')
-rw-r--r-- | indexer/cities_boundaries_serdes.hpp | 53 |
1 files changed, 8 insertions, 45 deletions
diff --git a/indexer/cities_boundaries_serdes.hpp b/indexer/cities_boundaries_serdes.hpp index 3b895331b9..b5c2cb0dc9 100644 --- a/indexer/cities_boundaries_serdes.hpp +++ b/indexer/cities_boundaries_serdes.hpp @@ -48,7 +48,7 @@ public: void operator()(m2::PointU const & p) { - WriteVarUint(m_sink, coding::EncodeDelta(p, m_last)); + WriteVarUint(m_sink, coding::EncodePointDeltaAsUint(p, m_last)); m_last = p; } @@ -58,7 +58,7 @@ public: auto const max = ToU(bbox.Max()); (*this)(min); - EncodePositiveDelta(min, max); + coding::EncodePositivePointDelta(m_sink, min, max); } void operator()(m2::CalipersBox const & cbox) @@ -89,8 +89,8 @@ public: auto const us = ToU(ps); (*this)(us[0]); - EncodeDelta(us[0], us[1]); - EncodeDelta(us[0], us[3]); + coding::EncodePointDelta(m_sink, us[0], us[1]); + coding::EncodePointDelta(m_sink, us[0], us[3]); } void operator()(m2::DiamondBox const & dbox) @@ -131,29 +131,6 @@ public: return us; } - void EncodeDelta(m2::PointU const & curr, m2::PointU const & next) - { - auto const dx = base::asserted_cast<int32_t>(next.x) - - base::asserted_cast<int32_t>(curr.x); - auto const dy = base::asserted_cast<int32_t>(next.y) - - base::asserted_cast<int32_t>(curr.y); - WriteVarInt(m_sink, dx); - WriteVarInt(m_sink, dy); - } - - void EncodePositiveDelta(m2::PointU const & curr, m2::PointU const & next) - { - ASSERT_GREATER_OR_EQUAL(next.x, curr.x, ()); - ASSERT_GREATER_OR_EQUAL(next.y, curr.y, ()); - - // Paranoid checks due to possible floating point artifacts - // here. In general, next.x >= curr.x and next.y >= curr.y. - auto const dx = next.x >= curr.x ? next.x - curr.x : 0; - auto const dy = next.y >= curr.y ? next.y - curr.y : 0; - WriteVarUint(m_sink, dx); - WriteVarUint(m_sink, dy); - } - Sink & m_sink; serial::GeometryCodingParams m_params; m2::PointU m_last; @@ -213,7 +190,7 @@ public: void operator()(m2::PointU & p) { - p = coding::DecodeDelta(ReadVarUint<uint64_t>(m_source), m_last); + p = coding::DecodePointDeltaFromUint(ReadVarUint<uint64_t>(m_source), m_last); m_last = p; } @@ -221,7 +198,7 @@ public: { m2::PointU min; (*this)(min); - auto const max = min + DecodePositiveDelta(); + auto const max = coding::DecodePositivePointDelta(m_source, min); bbox = m2::BoundingBox(); bbox.Add(FromU(min)); @@ -232,8 +209,8 @@ public: { std::vector<m2::PointU> us(4); (*this)(us[0]); - us[1] = DecodeDelta(us[0]); - us[3] = DecodeDelta(us[0]); + us[1] = coding::DecodePointDelta(m_source, us[0]); + us[3] = coding::DecodePointDelta(m_source, us[0]); auto ps = FromU(us); auto const dp = ps[3] - ps[0]; @@ -277,20 +254,6 @@ public: return ps; } - m2::PointU DecodeDelta(m2::PointU const & base) - { - auto const dx = ReadVarInt<int32_t>(m_source); - auto const dy = ReadVarInt<int32_t>(m_source); - return m2::PointU(base.x + dx, base.y + dy); - } - - m2::PointU DecodePositiveDelta() - { - auto const dx = ReadVarUint<uint32_t>(m_source); - auto const dy = ReadVarUint<uint32_t>(m_source); - return m2::PointU(dx, dy); - } - Source & m_source; serial::GeometryCodingParams const m_params; m2::PointU m_last; |