Exemplo n.º 1
0
        public Point GeneratePointWithin(Boundary boundary)
        {
            var x = boundary.Center.X + (2 * (_random.NextDouble() - 0.5) * boundary.HalfWidth);
            var y = boundary.Center.Y + (2 * (_random.NextDouble() - 0.5) * boundary.HalfHeight);

            return new Point(x, y);
        }
Exemplo n.º 2
0
        public Boundary GenerateIntersectingBoundary(Boundary boundary)
        {
            var center = GeneratePointWithin(boundary);
            var halfWidth = boundary.HalfWidth * 0.05 * (_random.NextDouble() + 0.0001);
            var halfHeight = boundary.HalfWidth * 0.05 * (_random.NextDouble() + 0.0001);

            return new Boundary(center, halfWidth, halfHeight);
        }
Exemplo n.º 3
0
        public List<Point> GeneratePointsWithin(Boundary boundary, int quantity)
        {
            var points = new List<Point>(quantity);

            for (var i = 0; i < quantity; i++)
                points.Add(GeneratePointWithin(boundary));

            return points;
        }
Exemplo n.º 4
0
        public List<Boundary> GenerateIntersectingBoundaries(Boundary boundary, int quantity)
        {
            var boundaries = new List<Boundary>();

            for (var i = 0; i < quantity; i++)
                boundaries.Add(GenerateIntersectingBoundary(boundary));

            return boundaries;
        }
Exemplo n.º 5
0
        public ISpatialIndex BuildIndex(IQueryable<ISpatialDocument> documents)
        {
            if (!documents.Any()) return new EmptySpatialIndex();

            var mercator = new Boundary(new Point(0, 0), 180, 90);
            var quadTree = new QuadTree<SpatialDocument>(mercator);

            foreach (var doc in documents)
            {
                quadTree.Insert(new SpatialDocument(doc));
            }

            var index = new SpatialIndex(quadTree);

            return index;
        }
Exemplo n.º 6
0
        private Boundary GetSearchArea(KnnQuery query)
        {
            var top = query.Coordinate.Add(query.MaxDistance, 0);
            var bottom = query.Coordinate.Add(-query.MaxDistance, 0);
            var right = query.Coordinate.Add(0, query.MaxDistance);
            var left = query.Coordinate.Add(0, -query.MaxDistance);

            var halfLatitude = (top.Latitude - bottom.Latitude) / 2;
            var halfLongitude = (right.Longitude - left.Longitude) / 2;

            var center = new Point(left.Longitude + halfLongitude, bottom.Latitude + halfLatitude);
            var searchArea = new Boundary(center, halfLongitude, halfLatitude);

            // TODO: consider borders. search might need to be split into two.

            return searchArea;
        }
Exemplo n.º 7
0
 public bool Intersects(Boundary other)
 {
     return this.Left <= other.Right && this.Right >= other.Left &&
            this.Bottom <= other.Top && this.Top >= other.Bottom;
 }