Beispiel #1
0
        // helper: get the right rectangle of node inside parent's rect
        private static Hyperrectangle rightRect(Hyperrectangle hyperrect, KDTreeNode <T> node)
        {
            //var rect = hyperrect.ToRectangle();
            //return (node.Axis != 0 ?
            //    Rectangle.FromLTRB(rect.Left, (int)node.Position[1], rect.Right, rect.Bottom) :
            //    Rectangle.FromLTRB((int)node.Position[0], rect.Top, rect.Right, rect.Bottom)).ToHyperrectangle();
            Hyperrectangle copy = new Hyperrectangle((double[])hyperrect.Min.Clone(), (double[])hyperrect.Max.Clone());

            copy.Min[node.Axis] = node.Position[node.Axis];
            return(copy);
        }
Beispiel #2
0
        private IList <KDTreeNode <T> > getNodesInsideRegion(KDTreeNode <T> node, Hyperrectangle region, Hyperrectangle subRegion)
        {
            var result = new List <KDTreeNode <T> >();

            if (node != null && region.IntersectsWith(subRegion))
            {
                if (region.Contains(node.Position))
                {
                    result.Add(node);
                }

                result.AddRange(getNodesInsideRegion(node.Left, region, leftRect(subRegion, node)));
                result.AddRange(getNodesInsideRegion(node.Right, region, rightRect(subRegion, node)));
            }

            return(result);
        }
Beispiel #3
0
 /// <summary>
 ///   Retrieves a list of all points inside a given region.
 /// </summary>
 ///
 /// <param name="region">The region.</param>
 ///
 /// <returns>A list of all nodes contained in the region.</returns>
 ///
 public IList <KDTreeNode <T> > GetNodesInsideRegion(Hyperrectangle region)
 {
     return(getNodesInsideRegion(this.Root, region, region));
 }