Esempio n. 1
0
        public KDNode Split(CityLayout element)
        {
            // Create the node that is a perfect fit for the element and place at top right of current node
            KDNode fitnode = new KDNode(X, Y, element.LayoutSize.x, element.LayoutSize.z);

            fitnode.Element = element;

            // Split current Node Horizontally then verically based on fitnode
            Left  = new KDNode(X, Y, Width, fitnode.Height);
            Right = new KDNode(X, Y + fitnode.Height, Width, Height - fitnode.Height);

            // Add fitnode as child to Left and split vertically
            Left.Left  = fitnode;
            Left.Right = new KDNode(X + fitnode.Width, Y, Width - fitnode.Width, fitnode.Height);

            return(fitnode);
        }
Esempio n. 2
0
        public List <KDNode> AvailableNodes(CityLayout child)
        {
            List <KDNode> available = new List <KDNode>();

            if (Left != null)
            {
                available.AddRange(Left.AvailableNodes(child));
            }
            if (Right != null)
            {
                available.AddRange(Right.AvailableNodes(child));
            }

            if (Available(child))
            {
                available.Add(this);
            }

            return(available);
        }
Esempio n. 3
0
 public bool Available(CityLayout element)
 {
     // KDnode is available only if it will fit the element and it doesn't already have an occupying element or any child elements
     return(WillFit(element) && Element == null && Left == null && Right == null);
 }
Esempio n. 4
0
 public bool IsPerfectFit(CityLayout element)
 {
     // Is a perfect fit if element scale.x equals width and scale.y equals height
     return(element.LayoutSize.x == Width && element.LayoutSize.z == Height);
 }
Esempio n. 5
0
 public bool WillFit(CityLayout element)
 {
     //An element will fit the node if it's X and Z sizes are less than width and height
     return(element.LayoutSize.x <= Width && element.LayoutSize.z <= Height);
 }