Ejemplo n.º 1
0
        private IEnumerable <GeoIndex> NaiveNearestIndexes(GeoPoint point, Distance distance)
        {
            var center = indexes.GetIndex(point);
            var length = (int)Math.Ceiling(distance / resolution) * 2;

            if (length == 0)
            {
                var index = new GeoIndex(center.X, center.Y);
                if (indexes.IsIndexValid(index))
                {
                    yield return(index);
                }
                yield break;
            }

            for (var x = center.X - length; x <= center.X + length; x++)
            {
                for (var y = center.Y - length; y <= center.Y + length; y++)
                {
                    var index = new GeoIndex(x, y);
                    if (indexes.IsIndexValid(index) && indexes.GetGeoPoint(index).GetDistance(point) <= distance)
                    {
                        yield return(index);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public IEnumerable <GeoIndex> Enumerate(GeoPoint point, Distance distance)
        {
            if (distance < Distance.FromMetres(0))
            {
                return(Enumerable.Empty <GeoIndex>());
            }

            var center = indexes.GetIndex(point);

            if (!indexes.IsIndexValid(center))
            {
                throw new ArgumentOutOfRangeException(nameof(point), $"Geo map data does not cover location {point}");
            }

            var length = Math.Max((int)Math.Floor(distance / resolution) - 1, 0);
            var right  = center.X + length;

            while (indexes.GetGeoPoint(new GeoIndex(right + 1, center.Y)).GetDistance(point) <= distance)
            {
                right++;
            }

            var left = center.X - length;

            while (indexes.GetGeoPoint(new GeoIndex(left - 1, center.Y)).GetDistance(point) <= distance)
            {
                left--;
            }

            left  = indexes.ClampX(left);
            right = indexes.ClampX(right);

            return(Enumerate(Enumerable.Range(center.X, right - center.X + 1).Reverse(), center.Y, point, distance)
                   .Concat(Enumerate(Enumerable.Range(left, center.X - left), center.Y, point, distance)));
        }
 public List <Suburb> this[GeoPoint point]
 {
     get
     {
         var index = indexes.GetIndex(point);
         if (!indexes.IsIndexValid(index))
         {
             throw new IndexOutOfRangeException(point.ToString());
         }
         return(suburbs[index.X][index.Y]);
     }
     set
     {
         var index = indexes.GetIndex(point);
         if (!indexes.IsIndexValid(index))
         {
             throw new IndexOutOfRangeException(point.ToString());
         }
         suburbs[index.X][index.Y] = value?.ToList();
     }
 }