Delta incoding for points at transit.

This commit is contained in:
Vladimir Byko-Ianko 2017-10-05 15:45:58 +03:00 committed by Roman Kuznetsov
parent b4da9c4155
commit 84f95f89d8
2 changed files with 15 additions and 5 deletions

View file

@ -49,6 +49,7 @@ void SerializeObject(my::Json const & root, string const & key, Serializer<FileW
DeserializerFromJson deserializer(root.get());
deserializer(items, key.c_str());
serializer.ResetCache();
serializer(items);
}
} // namespace

View file

@ -2,6 +2,8 @@
#include "routing_common/transit_types.hpp"
#include "indexer/geometry_coding.hpp"
#include "geometry/point2d.hpp"
#include "coding/point_to_integer.hpp"
@ -60,8 +62,8 @@ public:
void operator()(m2::PointD const & p, char const * /* name */ = nullptr)
{
m2::PointU const pointU = PointD2PointU(p, POINT_COORD_BITS);
WriteVarUint(m_sink, pointU.x);
WriteVarUint(m_sink, pointU.y);
WriteVarUint(m_sink, EncodeDelta(pointU, m_lastEncodedPoint));
m_lastEncodedPoint = pointU;
}
template <typename T>
@ -79,8 +81,12 @@ public:
t.Visit(*this);
}
/// \note This method should be called beforw serializing every table.
void ResetCache() { m_lastEncodedPoint = m2::PointD(); }
private:
Sink & m_sink;
m2::PointU m_lastEncodedPoint;
};
template <typename Source>
@ -110,10 +116,9 @@ public:
void operator()(m2::PointD & p, char const * /* name */ = nullptr)
{
m2::PointU pointU;
pointU.x = ReadVarUint<uint32_t, Source>(m_source);
pointU.y = ReadVarUint<uint32_t, Source>(m_source);
m2::PointU pointU = DecodeDelta(ReadVarUint<uint64_t, Source>(m_source), m_lastDecodedPoint);
p = PointU2PointD(pointU, POINT_COORD_BITS);
m_lastDecodedPoint = pointU;
}
template <typename T>
@ -131,8 +136,12 @@ public:
t.Visit(*this);
}
/// \note This method should be called beforw deserializing every table.
void ResetCache() { m_lastDecodedPoint = m2::PointD(); }
private:
Source & m_source;
m2::PointU m_lastDecodedPoint;
};
} // namespace transit
} // namespace routing