private static int TestEncodedS2PointVector(S2Point[] expected, CodingHint hint, Int64 expected_bytes) { Encoder encoder = new(); EncodedS2PointVector.EncodeS2PointVector(expected, hint, encoder); if (expected_bytes >= 0) { Assert.Equal(expected_bytes, encoder.Length()); } var decoder = encoder.Decoder(); EncodedS2PointVector actual = new(); Assert.True(actual.Init(decoder)); Assert.Equal(actual.Decode(), expected); return(encoder.Length()); }
private static void TestRoundtripEncoding(CodingHint hint) { // Ensures that the EncodedS2PointVector can be encoded and decoded without // loss. const int level = 3; var pointsArray = new S2Point[kBlockSize]; pointsArray.Fill(EncodedValueToPoint(0, level)); var pointsList = pointsArray.ToList(); pointsList.Add(EncodedValueToPoint(0x78, level)); pointsList.Add(EncodedValueToPoint(0x7a, level)); pointsList.Add(EncodedValueToPoint(0x7c, level)); pointsList.Add(EncodedValueToPoint(0x84, level)); pointsArray = pointsList.ToArray(); EncodedS2PointVector a_vector = new(); Encoder a_encoder = new(); EncodedS2PointVector b_vector = new(); Encoder b_encoder = new(); // Encode and decode from a vector<S2Point>. { EncodedS2PointVector.EncodeS2PointVector(pointsArray, hint, a_encoder); var decoder = a_encoder.Decoder(); a_vector.Init(decoder); } Assert.Equal(pointsList, a_vector.Decode()); // Encode and decode from an EncodedS2PointVector. { a_vector.Encode(b_encoder); var decoder = b_encoder.Decoder(); b_vector.Init(decoder); } Assert.Equal(pointsList, b_vector.Decode()); }
// Appends an encoded representation of the S2Shape to "encoder". Note that // the encoding does *not* include the type_tag(), so the tag will need to // be encoded separately if the shape type will be unknown at decoding time // (see s2shapeutil::EncodeTaggedShapes() and related functions). // // The encoded representation should satisfy the following: // // - It should include a version number, so that the encoding may be changed // or improved in the future. // // - If "hint" is CodingHint::FAST, the encoding should be optimized for // decoding performance. If "hint" is CodingHint::COMPACT, the encoding // should be optimized for space. // // REQUIRES: "encoder" uses the default constructor, so that its buffer // can be enlarged as necessary by calling Ensure(int). public virtual void Encode(Encoder encoder, CodingHint hint) { throw new NotImplementedException("(FATAL) Encoding not implemented for this S2Shape type"); }
// Appends an encoded representation of the S2PointVectorShape to "encoder". // // REQUIRES: "encoder" uses the default constructor, so that its buffer // can be enlarged as necessary by calling Ensure(int). public void Encode(Encoder encoder, CodingHint hint = CodingHint.COMPACT) { EncodedS2PointVector.EncodeS2PointVector(points_, hint, encoder); }
// Appends an encoded representation of the S2LaxPolylineShape to "encoder". // The coding hint is ignored, and whatever method was originally used to // encode the shape is preserved. // // REQUIRES: "encoder" uses the default constructor, so that its buffer // can be enlarged as necessary by calling Ensure(int). // // The encoding must be identical to S2LaxPolylineShape::Encode(). public void Encode(Encoder encoder, CodingHint hint) { vertices_.Encode(encoder); }