Exemplo n.º 1
0
        private KdTreeNode <TKey, TValue>[] RadialSearch(TKey[] center, TKey radius, NearestNeighbourList <KdTreeNode <TKey, TValue>, TKey> nearestNeighbours)
        {
            AddNearestNeighbours(
                root,
                center,
                HyperRect <TKey> .Infinite(dimensions, typeMath),
                0,
                nearestNeighbours,
                typeMath.Multiply(radius, radius));

            var 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);
        }
Exemplo 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, typeMath);

            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);
        }