Esempio n. 1
0
 public void Test_GetPerimeter_WrongDimension()
 {
     Assert.Equal(S1Angle.Zero,
                  S2.GetPerimeter(MakeIndexOrDie("0:0 # #").Shape(0)));
     Assert.Equal(S1Angle.Zero,
                  S2ShapeIndexMeasures.GetPerimeter(MakeIndexOrDie("0:0, 0:1, 1:0")));
 }
Esempio n. 2
0
    public void Test_GetPerimeter_MoreThanTwoPi()
    {
        // Make sure that GetPerimeter doesn't use S1ChordAngle, which can only
        // represent distances up to 2*Pi.
        var loop = ParsePointsOrDie("0:0, 0:90, 0:180, 90:0, 0:-90").ToArray();

        Assert2.DoubleEqual(5 * S2.M_PI_2, S2.GetPerimeter(loop).Radians);
    }
Esempio n. 3
0
    // Returns the total perimeter of all polygons in the index (including both
    // "shells" and "holes").  Returns zero if no polygons are present.
    //
    // All edges are modeled as spherical geodesics.  The result can be converted
    // to a distance on the Earth's surface (with a worst-case error of 0.562%
    // near the equator) using the functions in s2earth.h.
    public static S1Angle GetPerimeter(S2ShapeIndex index)
    {
        var perimeter = S1Angle.Zero;

        for (int i = 0; i < index.NumShapeIds(); ++i)
        {
            var shape = index.Shape(i);
            if (shape != null)
            {
                perimeter += S2.GetPerimeter(shape);
            }
        }
        return(perimeter);
    }
Esempio n. 4
0
    // For shapes of dimension 2, returns the sum of all loop perimeters on the
    // unit sphere.  Otherwise returns zero.  (See GetLength for shapes of
    // dimension 1.)
    //
    // All edges are modeled as spherical geodesics.  The result can be converted
    // to a distance on the Earth's surface (with a worst-case error of 0.562%
    // near the equator) using the functions in s2earth.h.
    public static S1Angle GetPerimeter(S2Shape shape)
    {
        if (shape.Dimension() != 2)
        {
            return(S1Angle.Zero);
        }
        var perimeter  = S1Angle.Zero;
        int num_chains = shape.NumChains();

        for (int chain_id = 0; chain_id < num_chains; ++chain_id)
        {
            GetChainVertices(shape, chain_id, out var vertices);
            perimeter += S2.GetPerimeter(vertices);
        }
        return(perimeter);
    }
Esempio n. 5
0
    public void Test_GetPerimeter_Octant()
    {
        var loop = ParsePointsOrDie("0:0, 0:90, 90:0");

        Assert2.DoubleEqual(3 * S2.M_PI_2, S2.GetPerimeter(loop.ToArray()).Radians);
    }
Esempio n. 6
0
 public void Test_GetPerimeter_Empty()
 {
     Assert.Equal(S1Angle.Zero, S2.GetPerimeter(Array.Empty <S2Point>()));
 }
Esempio n. 7
0
 public void Test_GetPerimeter_TwoLoopPolygon()
 {
     // To ensure that all edges are 1 degree long, we use degenerate loops.
     Assert.Equal(S1Angle.FromDegrees(6),
                  S2.GetPerimeter(MakeLaxPolygonOrDie("0:0, 1:0; 0:1, 0:2, 0:3")));
 }
Esempio n. 8
0
 public void Test_GetPerimeter_FullPolygon()
 {
     Assert.Equal(S1Angle.Zero, S2.GetPerimeter(MakeLaxPolygonOrDie("full")));
 }
Esempio n. 9
0
 public void Test_GetPerimeter_EmptyPolygon()
 {
     Assert.Equal(S1Angle.Zero, S2.GetPerimeter(MakeLaxPolygonOrDie("empty")));
 }