public void Test_DecodeTaggedShapes_DecodeFromEncoded() { Encoder encoder = new(); // Make an encoded shape. Assert.True(S2ShapeUtilCoding.FastEncodeShape( new S2PointVectorShape(ParsePointsOrDie("0:0, 0:1").ToArray()), encoder)); var decoder = encoder.Decoder(); var(success, encoded_shape) = EncodedS2PointVectorShape.Init(decoder); // Encode the encoded form. Encoder reencoder = new(); Assert.True(S2ShapeUtilCoding.FastEncodeShape(encoded_shape !, reencoder)); var encoded_decoder = reencoder.Decoder(); // We can decode the shape in either full or lazy form from the same bytes. var full_shape = S2ShapeUtilCoding.FullDecodeShape(S2PointVectorShape.kTypeTag, encoded_decoder); Assert.Equal(full_shape !.GetTypeTag(), S2PointVectorShape.kTypeTag); encoded_decoder = reencoder.Decoder(); var lazy_shape = S2ShapeUtilCoding.LazyDecodeShape(S2PointVectorShape.kTypeTag, encoded_decoder); Assert.Equal(lazy_shape !.GetTypeTag(), S2PointVectorShape.kTypeTag); }
public void Test_FastEncodeShape_S2Polygon() { var polygon = MakePolygonOrDie("0:0, 0:1, 1:0"); var shape = new S2Polygon.Shape(polygon); Encoder encoder = new(); S2ShapeUtilCoding.FastEncodeShape(shape, encoder); var decoder = encoder.Decoder(); var shape2 = S2ShapeUtilCoding.FullDecodeShape(S2Shape.TypeTag.S2Polygon, decoder); Assert.True(shape.Polygon == ((S2Polygon.Shape)shape2).Polygon); }