Exemplo n.º 1
0
    // Overwrites "vertices" with the vertices of the given edge chain of "shape".
    // If dimension == 1, the chain will have (chain.length + 1) vertices, and
    // otherwise it will have (chain.length) vertices.
    //
    // This is a low-level helper method used in the implementations of some of
    // the methods above.
    public static void GetChainVertices(S2Shape shape, int chain_id, out S2Point[] vertices)
    {
        S2Shape.Chain chain        = shape.GetChain(chain_id);
        int           num_vertices = chain.Length + (shape.Dimension() == 1 ? 1 : 0);
        int           e            = 0;
        var           verts        = new List <S2Point>();

        if ((num_vertices & 1) != 0)
        {
            verts.Add(shape.ChainEdge(chain_id, e++).V0);
        }
        for (; e < num_vertices; e += 2)
        {
            var edge = shape.ChainEdge(chain_id, e);
            verts.Add(edge.V0);
            verts.Add(edge.V1);
        }

        vertices = verts.ToArray();
    }
Exemplo n.º 2
0
 /// <summary>
 /// Verifies that all methods of the two S2Shapes return identical results,
 /// except for id() and type_tag().
 /// </summary>
 public static void ExpectEqual(S2Shape a, S2Shape b)
 {
     Assert.True(a.NumEdges() == b.NumEdges());
     for (int i = 0; i < a.NumEdges(); ++i)
     {
         Assert.Equal(a.GetEdge(i), b.GetEdge(i));
         Assert.True(a.GetChainPosition(i) == b.GetChainPosition(i));
     }
     Assert.True(a.Dimension() == b.Dimension());
     Assert.True(a.GetReferencePoint() == b.GetReferencePoint());
     Assert.True(a.NumChains() == b.NumChains());
     for (int i = 0; i < a.NumChains(); ++i)
     {
         Assert.True(a.GetChain(i) == b.GetChain(i));
         int chain_length = a.GetChain(i).Length;
         for (int j = 0; j < chain_length; ++j)
         {
             Assert.True(a.ChainEdge(i, j) == b.ChainEdge(i, j));
         }
     }
 }