예제 #1
0
 public void Test_GetApproxArea_LargeShellAndHolePolygon()
 {
     // Make sure that GetApproxArea works well for large polygons.
     Assert2.Near(S2.GetApproxArea(MakeLaxPolygonOrDie(
                                       "0:0, 0:90, 90:0; 0:22.5, 90:0, 0:67.5")),
                  S2.M_PI_4, 1e-12);
 }
예제 #2
0
    // Like GetArea(), except that this method is faster and has more error.  The
    // additional error is at most 2.22e-15 steradians per vertex, which works out
    // to about 0.09 square meters per vertex on the Earth's surface.  For
    // example, a loop with 100 vertices has a maximum error of about 9 square
    // meters.  (The actual error is typically much smaller than this.)
    public static double GetApproxArea(S2ShapeIndex index)
    {
        double area = 0;

        for (int i = 0; i < index.NumShapeIds(); ++i)
        {
            var shape = index.Shape(i);
            if (shape != null)
            {
                area += S2.GetApproxArea(shape);
            }
        }
        return(area);
    }
예제 #3
0
    // Like GetArea(), except that this method is faster and has more error.  The
    // additional error is at most 2.22e-15 steradians per vertex, which works out
    // to about 0.09 square meters per vertex on the Earth's surface.  For
    // example, a loop with 100 vertices has a maximum error of about 9 square
    // meters.  (The actual error is typically much smaller than this.)
    public static double GetApproxArea(S2Shape shape)
    {
        if (shape.Dimension() != 2)
        {
            return(0.0);
        }

        double area       = 0;
        int    num_chains = shape.NumChains();

        for (int chain_id = 0; chain_id < num_chains; ++chain_id)
        {
            GetChainVertices(shape, chain_id, out var vertices);
            area += S2.GetApproxArea(vertices.ToList()); //todo
        }
        // Special case to ensure that full polygons are handled correctly.
        if (area <= S2.M_4_PI)
        {
            return(area);
        }
        return(area % S2.M_4_PI);
    }