示例#1
0
        private Dictionary <PartitionNode <T>, SpatialObj <T> > FindNearestRectToPoint(Point p, PartitionNode <T> node)
        {
            Dictionary <PartitionNode <T>, SpatialObj <T> > answer_dict     = new Dictionary <PartitionNode <T>, SpatialObj <T> >();
            SimplePriorityQueue <PartitionNode <T> >        searching_nodes = new SimplePriorityQueue <PartitionNode <T> >();

            searching_nodes.Enqueue(node, 0);

            SpatialObj <T>    answer      = default(SpatialObj <T>);
            PartitionNode <T> answer_node = null;
            bool used = false;

            double min_distance_sq = rootNode.GetMaxDistance();

            while (searching_nodes.Count > 0)
            {
                PartitionNode <T> current_node = searching_nodes.Dequeue();
                Dictionary <SpatialObj <T>, double> nearest_rect = current_node.GetNearestRectangle(p);
                if (nearest_rect.Count > 0)
                {
                    foreach (KeyValuePair <SpatialObj <T>, double> entry in nearest_rect)
                    {
                        if (entry.Value <= min_distance_sq || entry.Value < Statics.EPSILON)
                        {
                            min_distance_sq = entry.Value;
                            answer          = entry.Key;
                            answer_node     = current_node;
                            used            = false;
                            if (min_distance_sq < Statics.EPSILON)
                            {
                                answer_dict.Add(answer_node, answer);
                                used = true;
                            }
                        }
                    }
                }
                if (current_node.HasChildren())
                {
                    foreach (PartitionNode <T> child in current_node.GetChildren())
                    {
                        double field_dist = child.GetDistanceToPointSq(p);
                        if (field_dist <= min_distance_sq)
                        {
                            searching_nodes.Enqueue(child, (float)field_dist);
                        }
                    }
                }
            }
            if (!used)
            {
                answer_dict.Add(answer_node, answer);
            }
            return(answer_dict);
        }