Ejemplo n.º 1
0
 // Constructs a region representing all points within the given radius of
 // any point in the given S2ShapeIndex.
 public S2ShapeIndexBufferedRegion(S2ShapeIndex index, S1ChordAngle radius)
 {
     Radius            = radius;
     radius_successor_ = radius.Successor();
     query_            = new S2ClosestEdgeQuery(index);
     query_.Options_.IncludeInteriors = (true);
 }
Ejemplo n.º 2
0
 // Use "query" to find the closest edge(s) to the given target.  Verify that
 // the results satisfy the search criteria.
 private static void GetClosestEdges(Target target,
                                     S2ClosestEdgeQuery query,
                                     List <Result> edges)
 {
     query.FindClosestEdges(target, edges);
     Assert.True(edges.Count <= query.Options_.MaxResults);
     if (query.Options_.MaxDistance ==
         Distance.Infinity)
     {
         int min_expected = Math.Min(query.Options_.MaxResults,
                                     query.Index().GetCountEdges());
         if (!query.Options_.IncludeInteriors)
         {
             // We can predict exactly how many edges should be returned.
             Assert.Equal(min_expected, edges.Count);
         }
         else
         {
             // All edges should be returned, and possibly some shape interiors.
             Assert.True(min_expected <= edges.Count);
         }
     }
     foreach (var edge in edges)
     {
         // Check that the edge satisfies the max_distance() condition.
         Assert.True(edge.Distance < query.Options_.MaxDistance);
     }
 }
Ejemplo n.º 3
0
        private static Result TestFindClosestEdges(Target target, S2ClosestEdgeQuery query)
        {
            List <Result> expected = new(), actual = new();

            query.Options_.UseBruteForce = (true);
            GetClosestEdges(target, query, expected);
            query.Options_.UseBruteForce = (false);
            GetClosestEdges(target, query, actual);
            Assert.True(TestingDistance.CheckDistanceResults(ConvertResults(expected),
                                                             ConvertResults(actual),
                                                             query.Options_.MaxResults,
                                                             query.Options_.MaxDistance,
                                                             query.Options_.MaxError));

            if (!expected.Any())
            {
                return(new Result());
            }

            // Note that when options.max_error() > 0, expected[0].distance() may not
            // be the minimum distance.  It is never larger by more than max_error(),
            // but the actual value also depends on max_results().
            //
            // Here we verify that GetDistance() and IsDistanceLess() return results
            // that are consistent with the max_error() setting.
            var max_error    = query.Options_.MaxError;
            var min_distance = expected[0].Distance;

            Assert.True(query.GetDistance(target) <= min_distance + max_error);

            // Test IsDistanceLess().
            Assert.False(query.IsDistanceLess(target, min_distance - max_error));
            Assert.True(query.IsConservativeDistanceLessOrEqual(target, min_distance));

            // Return the closest edge result so that we can also test Project.
            return(expected[0]);
        }