Exemplo n.º 1
0
    // A ShapeEncoder that encode all standard S2Shape types, preferring
    // compact (but slower) encodings.  For example, points that have been snapped
    // to S2CellId centers will be encoded using at most 8 bytes.
    //
    // REQUIRES: "encoder" uses the default constructor, so that its buffer
    //           can be enlarged as necessary by calling Ensure(int).
    public static bool CompactEncodeShape(S2Shape shape, Encoder encoder)
    {
        var tag = shape.GetTypeTag();

        if (tag == S2Shape.TypeTag.kNoTypeTag)
        {
            System.Diagnostics.Debug.WriteLine("(DFATAL) Unsupported S2Shape type: " + tag);
            return(false);
        }
        // Update the following constant when adding new S2Shape encodings.
        System.Diagnostics.Debug.Assert(tag < S2Shape.TypeTag.kNextAvailableTypeTag);
        shape.Encode(encoder, CodingHint.COMPACT);
        return(true);
    }