コード例 #1
0
ファイル: RTree.cs プロジェクト: tedd/RTree
        private void contains(Rectangle r, intproc v)
        {
            // find all rectangles in the tree that are contained by the passed rectangle
            // written to be non-recursive (should model other searches on this?)

            parents.Clear();
            parents.Push(rootNodeId);

            parentsEntry.Clear();
            parentsEntry.Push(-1);

            // TODO: possible shortcut here - could test for intersection with the
            // MBR of the root node. If no intersection, return immediately.

            while (parents.Count > 0)
            {
                Node <T> n          = getNode(parents.Peek());
                int      startIndex = parentsEntry.Peek() + 1;

                if (!n.isLeaf())
                {
                    // go through every entry in the index Node<T> to check
                    // if it intersects the passed rectangle. If so, it
                    // could contain entries that are contained.
                    bool intersects = false;
                    for (int i = startIndex; i < n.entryCount; i++)
                    {
                        if (r.intersects(n.entries[i]))
                        {
                            parents.Push(n.ids[i]);
                            parentsEntry.Pop();
                            parentsEntry.Push(i); // this becomes the start index when the child has been searched
                            parentsEntry.Push(-1);
                            intersects = true;
                            break; // ie go to next iteration of while()
                        }
                    }
                    if (intersects)
                    {
                        continue;
                    }
                }
                else
                {
                    // go through every entry in the leaf to check if
                    // it is contained by the passed rectangle
                    for (int i = 0; i < n.entryCount; i++)
                    {
                        if (r.contains(n.entries[i]))
                        {
                            v(n.ids[i]);
                        }
                    }
                }
                parents.Pop();
                parentsEntry.Pop();
            }
        }
コード例 #2
0
ファイル: RTree.cs プロジェクト: vildar82/AcadLib
        private void Nearest(Point p, intproc v, double furthestDistance)
        {
            var rootNode = GetNode(rootNodeId);

            Nearest(p, rootNode, furthestDistance);

            foreach (var id in nearestIds)
                v(id);
            nearestIds.Clear();
        }
コード例 #3
0
ファイル: RTree.cs プロジェクト: CaseyYang/Academics
        private void nearest(Point p, intproc v, float furthestDistance)
        {
            Node <T> rootNode = getNode(rootNodeId);

            nearest(p, rootNode, furthestDistance);
            foreach (int id in nearestIds)
            {
                v(id);
            }
            nearestIds.Clear();
        }
コード例 #4
0
        private void nearest(SubSequence p, intproc v, double furthestDistance)
        {
            Node <T> rootNode = getNode(rootNodeId);

            nearest(p, rootNode, furthestDistance);

            foreach (int id in nearestIds)
            {
                v(id);
            }
            nearestIds.Clear();
        }
コード例 #5
0
        private void contains(Rectangle r, intproc v)
        {
            // find all rectangles in the tree that are contained by the passed rectangle
            parents.Clear();
            parents.Push(rootNodeId);

            parentsEntry.Clear();
            parentsEntry.Push(-1);

            while (parents.Count > 0)
            {
                Node <T> n          = getNode(parents.Peek());
                int      startIndex = parentsEntry.Peek() + 1;

                if (!n.isLeaf())
                {
                    // go through every entry in the index Node<T> to check
                    // if it intersects the passed rectangle. If so, it
                    // could contain entries that are contained.
                    bool intersects = false;
                    for (int i = startIndex; i < n.entryCount; i++)
                    {
                        if (r.intersects(n.entries[i]))
                        {
                            parents.Push(n.ids[i]);
                            parentsEntry.Pop();
                            parentsEntry.Push(i); // this becomes the start index when the child has been searched
                            parentsEntry.Push(-1);
                            intersects = true;
                            break; // ie go to next iteration of while()
                        }
                    }
                    if (intersects)
                    {
                        continue;
                    }
                }
                else
                {
                    // go through every entry in the leaf to check if
                    // it is contained by the passed rectangle
                    for (int i = 0; i < n.entryCount; i++)
                    {
                        if (r.contains(n.entries[i]))
                        {
                            v(n.ids[i]);
                        }
                    }
                }
                parents.Pop();
                parentsEntry.Pop();
            }
        }
コード例 #6
0
 /// <summary>
 /// Recursively searches the tree for all intersecting entries.
 /// Immediately calls execute() on the passed IntProcedure when
 /// a matching entry is found.
 /// [x] TODO rewrite this to be non-recursive? Make sure it
 /// doesn't slow it down.
 /// </summary>
 /// <param name="r"></param>
 /// <param name="v"></param>
 /// <param name="n"></param>
 private void intersects(Rectangle r, intproc v, Node <T> n)
 {
     for (int i = 0; i < n.entryCount; i++)
     {
         if (r.intersects(n.entries[i]))
         {
             if (n.isLeaf())
             {
                 v(n.ids[i]);
             }
             else
             {
                 Node <T> childNode = getNode(n.ids[i]);
                 intersects(r, v, childNode);
             }
         }
     }
 }
コード例 #7
0
ファイル: RTree.cs プロジェクト: vildar82/AcadLib
 /// <summary>
 /// Recursively searches the tree for all intersecting entries.
 /// Immediately calls execute() on the passed IntProcedure when
 /// a matching entry is found.
 /// [x] TODO rewrite this to be non-recursive? Make sure it
 /// doesn't slow it down.
 /// </summary>
 /// <param name="r"></param>
 /// <param name="v"></param>
 /// <param name="n"></param>
 private void Intersects(Rectangle r, intproc v, [NotNull] Node<T> n)
 {
     for (var i = 0; i < n.entryCount; i++)
     {
         if (r.Intersects(n.entries[i]))
         {
             if (n.IsLeaf())
             {
                 v(n.ids[i]);
             }
             else
             {
                 var childNode = GetNode(n.ids[i]);
                 Intersects(r, v, childNode);
             }
         }
     }
 }
コード例 #8
0
 void Intersects(RBox box, intproc v, Node n)
 {
     for (int i = 0; i < n.entryCount; i++)
     {
         if (box.Intersects(n.entries[i]))
         {
             if (n.level == 1)
             {
                 v(n.ids[i]);
             }
             else
             {
                 Node childNode = nodeMap[n.ids[i]];
                 Intersects(box, v, childNode);
             }
         }
     }
 }
コード例 #9
0
        private void intersects(Rectangle r, intproc v)
        {
            Node <T> rootNode = getNode(rootNodeId);

            intersects(r, v, rootNode);
        }
コード例 #10
0
ファイル: RTree.cs プロジェクト: vildar82/AcadLib
 private void Intersects(Rectangle r, intproc v)
 {
     var rootNode = GetNode(rootNodeId);
     Intersects(r, v, rootNode);
 }
コード例 #11
0
        void Intersects(RBox box, intproc v)
        {
            Node rootNode = nodeMap[rootNodeId];

            Intersects(box, v, rootNode);
        }