From 3a850b6f8a2c30bbcb3fed8cb61a2aed3d150615 Mon Sep 17 00:00:00 2001 From: Maxim Pimenov Date: Wed, 11 Apr 2018 14:53:00 +0300 Subject: [PATCH] Review fixes. --- coding/geometry_coding.hpp | 30 -------------------------- indexer/cities_boundaries_serdes.hpp | 32 ++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/coding/geometry_coding.hpp b/coding/geometry_coding.hpp index 86d06cb094..d54e37ffe8 100644 --- a/coding/geometry_coding.hpp +++ b/coding/geometry_coding.hpp @@ -45,25 +45,6 @@ void EncodePointDelta(Sink & sink, m2::PointU const & curr, m2::PointU const & n WriteVarInt(sink, dy); } -// Writes the difference of two 2d vectors to sink. The vector |next| -// must have both its coordinates greater than or equal to those -// of |curr|. While this condition is unlikely when encoding polylines, -// the function may be useful when encoding rectangles, in particular -// bounding boxes of shapes. -template -void EncodePositivePointDelta(Sink & sink, 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(sink, dx); - WriteVarUint(sink, dy); -} - // Reads the encoded difference from |source| and returns the // point equal to |base| + difference. template @@ -74,17 +55,6 @@ m2::PointU DecodePointDelta(Source & source, m2::PointU const & base) return m2::PointU(base.x + dx, base.y + dy); } -// Reads the encoded difference from |source| and returns the -// point equal to |base| + difference. It is guaranteed that -// both coordinates of difference are non-negative. -template -m2::PointU DecodePositivePointDelta(Source & source, m2::PointU const & base) -{ - auto const dx = ReadVarUint(source); - auto const dy = ReadVarUint(source); - return m2::PointU(base.x + dx, base.y + dy); -} - /// Predict next point for polyline with given previous points (p1, p2). m2::PointU PredictPointInPolyline(m2::PointU const & maxPoint, m2::PointU const & p1, m2::PointU const & p2); diff --git a/indexer/cities_boundaries_serdes.hpp b/indexer/cities_boundaries_serdes.hpp index b5c2cb0dc9..406683f94b 100644 --- a/indexer/cities_boundaries_serdes.hpp +++ b/indexer/cities_boundaries_serdes.hpp @@ -58,7 +58,7 @@ public: auto const max = ToU(bbox.Max()); (*this)(min); - coding::EncodePositivePointDelta(m_sink, min, max); + EncodeNonNegativePointDelta(min, max); } void operator()(m2::CalipersBox const & cbox) @@ -131,6 +131,24 @@ public: return us; } + // Writes the difference of two 2d vectors to |m_sink|. The vector |next| + // must have both its coordinates greater than or equal to those + // of |curr|. While this condition is unlikely when encoding polylines, + // this method may be useful when encoding rectangles, in particular + // bounding boxes of shapes. + void EncodeNonNegativePointDelta(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; @@ -198,7 +216,7 @@ public: { m2::PointU min; (*this)(min); - auto const max = coding::DecodePositivePointDelta(m_source, min); + auto const max = DecodeNonNegativePointDelta(min); bbox = m2::BoundingBox(); bbox.Add(FromU(min)); @@ -254,6 +272,16 @@ public: return ps; } + // Reads the encoded difference from |m_source| and returns the + // point equal to |base| + difference. It is guaranteed that + // both coordinates of difference are non-negative. + m2::PointU DecodeNonNegativePointDelta(m2::PointU const & base) + { + auto const dx = ReadVarUint(m_source); + auto const dy = ReadVarUint(m_source); + return m2::PointU(base.x + dx, base.y + dy); + } + Source & m_source; serial::GeometryCodingParams const m_params; m2::PointU m_last;