Exemple #1
0
        public KdTreeNode <TKey, TValue>[] RadialSearch(TKey[] center, TKey radius, int count)
        {
            var nearestNeighbours = new NearestNeighbourList <KdTreeNode <TKey, TValue>, TKey>(count);

            this.AddNearestNeighbours(this.root,
                                      center,
                                      HyperRect <TKey> .Infinite(this.dimensions),
                                      0,
                                      nearestNeighbours,
                                      (Number <TKey>)radius * radius);

            count = nearestNeighbours.Count;

            var neighbourArray = new KdTreeNode <TKey, TValue> [count];

            for (var index = 0; index < count; index++)
            {
                neighbourArray[count - index - 1] = nearestNeighbours.RemoveFurtherest();
            }

            return(neighbourArray);
        }
Exemple #2
0
        public KdTreeNode <TKey, TValue>[] GetNearestNeighbours(TKey[] point, int count)
        {
            if (count > Count)
            {
                count = Count;
            }

            if (count < 0)
            {
                throw new ArgumentException("Number of neighbors cannot be negative");
            }

            if (count == 0)
            {
                return(new KdTreeNode <TKey, TValue> [0]);
            }

            var neighbours = new KdTreeNode <TKey, TValue> [count];

            var nearestNeighbours = new NearestNeighbourList <KdTreeNode <TKey, TValue>, TKey>(count);

            var rect = HyperRect <TKey> .Infinite(dimensions);

            AddNearestNeighbours(root, point, rect, 0, nearestNeighbours, Number <TKey> .MaxValue);

            count = nearestNeighbours.Count;

            var neighbourArray = new KdTreeNode <TKey, TValue> [count];

            for (var index = 0; index < count; index++)
            {
                neighbourArray[count - index - 1] = nearestNeighbours.RemoveFurtherest();
            }

            return(neighbourArray);
        }