示例#1
0
    public void Test_ContainsBruteForce_ConsistentWithS2Loop()
    {
        // Checks that ContainsBruteForce agrees with S2Loop.Contains().
        var loop = S2Loop.MakeRegularLoop(MakePointOrDie("89:-179"), S1Angle.FromDegrees(10), 100);

        S2Loop.Shape shape = new(loop);
        for (int i = 0; i < loop.NumVertices; ++i)
        {
            Assert.Equal(loop.Contains(loop.Vertex(i)),
                         shape.ContainsBruteForce(loop.Vertex(i)));
        }
    }
示例#2
0
        public void Test_S2ClosestEdgeQuery_EmptyTargetOptimized()
        {
            // Ensure that the optimized algorithm handles empty targets when a distance
            // limit is specified.
            MutableS2ShapeIndex index = new();

            index.Add(new S2Polygon.OwningShape(new S2Polygon(
                                                    S2Loop.MakeRegularLoop(new S2Point(1, 0, 0), S1Angle.FromRadians(0.1), 1000))));
            S2ClosestEdgeQuery query = new(index);

            query.Options_.MaxDistance = new(S1Angle.FromRadians(1e-5));
            MutableS2ShapeIndex target_index = new();

            S2ClosestEdgeQuery.ShapeIndexTarget target = new(target_index);
            Assert.Empty(query.FindClosestEdges(target));
        }
示例#3
0
    private static void TestNorthPoleLoop(S1Angle radius, int num_vertices)
    {
        // If the radius is very close to 90, then it's hard to predict whether the
        // result will be the full loop or not.
        Assert.True(Math.Abs(radius.Radians - S2.M_PI_2) >= S2.DoubleError);

        S2ConvexHullQuery query = new();
        var loop = S2Loop.MakeRegularLoop(new S2Point(0, 0, 1), radius, num_vertices);

        query.AddLoop(loop);
        var result = query.GetConvexHull();

        if (radius > S1Angle.FromRadians(S2.M_PI_2))
        {
            Assert.True(result.IsFull());
        }
        else
        {
            Assert.True(result.BoundaryEquals(loop));
        }
    }
    public void Test_S2ContainsPointQuery_GetContainingShapes()
    {
        // Also tests ShapeContains().
        int                 kNumVerticesPerLoop = 10;
        S1Angle             kMaxLoopRadius      = S2Testing.KmToAngle(10);
        S2Cap               center_cap          = new(S2Testing.RandomPoint(), kMaxLoopRadius);
        MutableS2ShapeIndex index = new();

        for (int i = 0; i < 100; ++i)
        {
            var loop = S2Loop.MakeRegularLoop(
                S2Testing.SamplePoint(center_cap),
                S2Testing.Random.RandDouble() * kMaxLoopRadius, kNumVerticesPerLoop);
            index.Add(new S2Loop.Shape(loop));
        }
        var query = index.MakeS2ContainsPointQuery();

        for (int i = 0; i < 100; ++i)
        {
            S2Point        p        = S2Testing.SamplePoint(center_cap);
            List <S2Shape> expected = new();
            foreach (var shape in index)
            {
                var loop = ((S2Loop.Shape)shape).Loop;
                if (loop.Contains(p))
                {
                    Assert.True(query.ShapeContains(shape, p));
                    expected.Add(shape);
                }
                else
                {
                    Assert.False(query.ShapeContains(shape, p));
                }
            }
            var actual = query.GetContainingShapes(p);
            Assert.Equal(expected, actual);
        }
    }
 public void AddEdges(S2Cap index_cap, int num_edges, MutableS2ShapeIndex index)
 {
     index.Add(new S2Loop.Shape(S2Loop.MakeRegularLoop(
                                    index_cap.Center, index_cap.RadiusAngle(), num_edges)));
 }