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

            AddNearestNeighbours(
                root,
                center,
                HyperRect <TKey> .Infinite(dimensions, typeMath),
                0,
                nearestNeighbours,
                typeMath.Multiply(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);
        }
Esempio n. 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, typeMath);

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

            AddNearestNeighbours(root, point, rect, 0, nearestNeighbours, typeMath.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);
        }