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());
    }
示例#3
0
 // 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);
 }