Example #1
0
 public QuadTree(Vector2 mapSize, GetTreePosition positionFunc)
 {
     this.mapSize = mapSize;
     this.positionFunc = positionFunc;
     leafDictionary = new LeafDictionary(this);
     Rectangle mapRectangle = new Rectangle(0, 0, (int)Math.Ceiling(mapSize.X), (int)Math.Ceiling(mapSize.Y));
     root = new InternalNode(true, null, mapRectangle, leafDictionary, this.positionFunc);
 }
Example #2
0
 public Node(InternalNode parent, Rectangle mapSpace, LeafDictionary leafDictionary, GetTreePosition positionFunc)
 {
     id = nextI++;
     this.parent = parent;
     this.leafDictionary = leafDictionary;
     this.mapSpace = mapSpace;
     this.positionFunc = positionFunc;
 }
        public InternalNode(Boolean root, InternalNode parent, Rectangle mapSpace, LeafDictionary leafDictionary, GetTreePosition positionFunc)
            : base(parent, mapSpace, leafDictionary, positionFunc)
        {
            this.root = root;
            int halfWidth = mapSpace.Width / 2;
            int halfHeight = mapSpace.Height / 2;

            Rectangle swRectangle = new Rectangle(mapSpace.X, mapSpace.Y, halfWidth, halfHeight);
            Rectangle seRectangle = new Rectangle(mapSpace.X + halfWidth, mapSpace.Y, mapSpace.Width - halfWidth, halfHeight);
            Rectangle nwRectangle = new Rectangle(mapSpace.X, mapSpace.Y + halfHeight, halfWidth, mapSpace.Height - halfHeight);
            Rectangle neRectangle = new Rectangle(mapSpace.X + halfWidth, mapSpace.Y + halfHeight, mapSpace.Width - halfWidth, mapSpace.Height - halfHeight);

            Node nw = new Leaf(this, nwRectangle, leafDictionary, positionFunc);
            Node ne = new Leaf(this, neRectangle, leafDictionary, positionFunc);
            Node sw = new Leaf(this, swRectangle, leafDictionary, positionFunc);
            Node se = new Leaf(this, seRectangle, leafDictionary, positionFunc);
            children.Add(nw);
            children.Add(ne);
            children.Add(sw);
            children.Add(se);
        }
Example #4
0
 public Leaf(InternalNode parent, Rectangle mapSpace, LeafDictionary leafDictionary, GetTreePosition positionFunc)
     : base(parent, mapSpace, leafDictionary, positionFunc)
 {
     unitList = new GameObjectListManager();
 }