コード例 #1
0
        public override void Insert(T objct, object bounding)
        {
            if (bounding is Common.Bounding.NonfittableBounding)        // add to special list and return
            {
                nonfittableObjects.Add(objct, (Common.Bounding.NonfittableBounding)bounding);
                return;
            }

            if (root == null)
            {
                InitFromInsert(bounding);
            }
            else if (!root.Fits(bounding))
            {
                // create new levels
                do
                {
                    root = new Node(this, null, root, bounding);
                    if (root.DebugReturnDepth > 10)
                    {
                        throw new Exception("Quadtree grew too large");
                    }
                } while (!root.Fits(bounding));
            }

            Node n = root.FindFit(bounding);

            n.Insert(objct, bounding);
            objectToNode[objct] = n;
        }
コード例 #2
0
        public override void Move(T objct, object newBounding)
        {
            Node sn;

            if (objectToNode.TryGetValue(objct, out sn))
            {
                Node n = sn;
                //n.objct_to_boundings[objct] = newBounding;
                //while (n.parent != null && SpatialRelation.Relation(BBToRectangleF(n.bounding), newBounding) != RSpatialRelation.BInsideA)
                //    n = n.parent;
                while (SpatialRelation.Relation(BBToRectangleF(n.bounding), newBounding) != RSpatialRelation.BInsideA)
                {
                    if (n.parent == null)
                    {
                        break;
                    }
                    n = n.parent;
                }

                if (n.parent == null)
                {
                    while (!root.Fits(newBounding))
                    {
                        root = new Node(this, null, root, newBounding);

                        if (root.DebugReturnDepth > 10)
                        {
                            throw new Exception("Quadtree grew too large");
                        }
                    }
                }

                n = n.FindFitDown(newBounding);

                if (n == sn)
                {
                    sn.objct_to_boundings[objct] = newBounding;
                    return;
                }

                sn.Remove(objct);
                n.Insert(objct, newBounding);
                objectToNode[objct] = n;
            }
            else if (nonfittableObjects.ContainsKey(objct))
            {
                nonfittableObjects[objct] = (Common.Bounding.NonfittableBounding)newBounding;
            }
            else
            {
                throw new KeyNotFoundException("No such element in quadtree.");
            }
        }