コード例 #1
0
 private QuadLeaf(QuadLeaf <T> parent, double x, double y, double width, double height)
 {
     X      = x;
     Y      = y;
     Width  = width;
     Height = height;
 }
コード例 #2
0
        // private
        private void ReculculateNodeList()
        {
            if (boundsChanged)
            {
                root = new QuadLeaf <T>(0.0d, 0.0d, width, height);
                removedSet.Clear();

                foreach (T node in objects)
                {
                    changedSet.Remove(node);
                    addedSet.Remove(node);
                    root.Add(node);
                }
            }
            else
            {
                foreach (T node in addedSet)
                {
                    root.Add(node);
                    addedSet.Remove(node);
                }
                foreach (T node in changedSet)
                {
                    root.Move(node);
                    changedSet.Remove(node);
                }
                foreach (T node in removedSet)
                {
                    root.Remove(node);
                    removedSet.Remove(node);
                }
            }
        }
コード例 #3
0
        private void TrySubdivide()
        {
            if (objects.Count < 4)
            {
                return;
            }

            double newWidth  = Width / 2.0d;
            double newHeight = Height / 2.0d;

            if (newWidth <= 1.0d || newHeight <= 1.0d)
            {
                return;
            }

            double midX = Width / 2.0d;
            double midY = Height / 2.0d;

            bool containsAny = false;

            foreach (T node in objects)
            {
                // Top left
                if (ContainsRect(X, Y, newWidth, newHeight, node.X, node.Y, node.Width, node.Height))
                {
                    containsAny = true;
                    break;
                }
                // Top right
                if (ContainsRect(midX, Y, newWidth, newHeight, node.X, node.Y, node.Width, node.Height))
                {
                    containsAny = true;
                    break;
                }
                // Bottom left
                if (ContainsRect(X, midY, newWidth, newHeight, node.X, node.Y, node.Width, node.Height))
                {
                    containsAny = true;
                    break;
                }
                // Bottom right
                if (ContainsRect(midX, midY, newWidth, newHeight, node.X, node.Y, node.Width, node.Height))
                {
                    containsAny = true;
                    break;
                }
            }

            if (containsAny)
            {
                leafs[0] = new QuadLeaf <T>(this, X, Y, newWidth, newHeight);
                leafs[1] = new QuadLeaf <T>(this, midX, Y, newWidth, newHeight);
                leafs[2] = new QuadLeaf <T>(this, X, midY, newWidth, newHeight);
                leafs[3] = new QuadLeaf <T>(this, midX, midY, newWidth, newHeight);
            }
        }
コード例 #4
0
        // constructor
        public QuadTree(double width, double height)
        {
            if (double.IsNaN(width) || double.IsInfinity(width))
            {
                throw new NotFiniteNumberException(width);
            }
            if (width <= 0.0d)
            {
                throw new ArgumentOutOfRangeException("width");
            }
            if (double.IsNaN(height) || double.IsInfinity(height))
            {
                throw new NotFiniteNumberException(width);
            }
            if (height <= 0.0d)
            {
                throw new ArgumentOutOfRangeException("height");
            }

            root        = new QuadLeaf <T>(0.0d, 0.0d, width, height);
            this.width  = width;
            this.height = height;
        }