Beispiel #1
0
		public QuadTreeNode CreateNewRoot(QuadTreeNode currentRoot)
		{
			var bounds = currentRoot.Bounds;
			int startRow = bounds.Start.Row;
			int startCol = bounds.Start.Column;
			int halfCol = bounds.ColumnsCount ;
			int halfRow = bounds.RowsCount;
			var Depth = currentRoot.Depth;
			var QuadTree = currentRoot.QuadTree;
			
			var newRoot = new QuadTreeNode(
				new Range(startRow, startCol, halfCol * 2, halfRow * 2),
				currentRoot.Depth, currentRoot.QuadTree);
			
			
			newRoot.Nodes.Add(currentRoot);
			newRoot.Nodes.Add(new QuadTreeNode(Range.From(
				new Position(startRow, startCol + halfCol),
				halfRow, halfCol), Depth, QuadTree));
			newRoot.Nodes.Add(new QuadTreeNode(Range.From(
				new Position(startRow + halfRow, startCol),
				halfRow, halfCol), Depth, QuadTree));
			newRoot.Nodes.Add(new QuadTreeNode(Range.From(
				new Position(startRow + halfRow, startCol + halfCol),
				halfRow, halfCol), Depth, QuadTree));
			return newRoot;
		}
Beispiel #2
0
        /// <summary>
        /// Get the colour for a QuadTreeNode from the hash table or else create a new colour
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        Color GetColor(QuadTreeNode<Item> node)
        {
            if (m_dictionary.ContainsKey(node))
                return m_dictionary[node];

            Color color = Utility.RandomColor;
            m_dictionary.Add(node, color);
            return color;
        }
		public void CreateNotProportionateNodes()
		{
			var node = new QuadTreeNode(new Range(1, 1, 1000, 100));
			var divider = new ProportioanteSizeNodeDivider();
			divider.CreateSubNodes(node);
			Assert.AreEqual(2, node.Nodes.Count);
			Assert.AreEqual(new Range(1, 1, 500, 100), node.Nodes[0].Bounds);
			Assert.AreEqual(new Range(501, 1, 1000, 100), node.Nodes[1].Bounds);
		}
Beispiel #4
0
		public void CreateSubNodes(QuadTreeNode parentNode)
		{
			// the smallest subnode has an area
			if ((parentNode.Bounds.ColumnsCount * parentNode.Bounds.RowsCount) <= 10)
				return;
			
			if (IsProportionate(parentNode) == false)
				CreateNotProportionate(parentNode);
			else
				CreateProportionate(parentNode);
		}
Beispiel #5
0
		private void CreateNotProportionate(QuadTreeNode parentNode)
		{
			var m_bounds = parentNode.Bounds;
			int startRow = m_bounds.Start.Row;
			int startCol = m_bounds.Start.Column;
			int halfCol = m_bounds.ColumnsCount;
			int halfRow = (m_bounds.RowsCount/ 2);

			var Depth = parentNode.Depth;
			var QuadTree = parentNode.QuadTree;
			
			parentNode.Nodes.Add(new QuadTreeNode(Range.From(m_bounds.Start, halfRow, halfCol), Depth, QuadTree));
			parentNode.Nodes.Add(new QuadTreeNode(Range.From(
				new Position(startRow + halfRow, startCol),
				halfRow, halfCol), Depth, QuadTree));
		}
        private void CreateProportionate(QuadTreeNode parentNode)
        {
            var m_bounds = parentNode.Bounds;
            int startRow = m_bounds.Start.Row;
            int startCol = m_bounds.Start.Column;
            int halfCol  = (m_bounds.ColumnsCount / 2);
            int halfRow  = (m_bounds.RowsCount / 2);

            var Depth    = parentNode.Depth;
            var QuadTree = parentNode.QuadTree;

            parentNode.Nodes.Add(new QuadTreeNode(Range.From(m_bounds.Start, halfRow, halfCol), Depth, QuadTree));
            parentNode.Nodes.Add(new QuadTreeNode(Range.From(
                                                      new Position(startRow, startCol + halfCol),
                                                      halfRow, halfCol), Depth, QuadTree));
            parentNode.Nodes.Add(new QuadTreeNode(Range.From(
                                                      new Position(startRow + halfRow, startCol),
                                                      halfRow, halfCol), Depth, QuadTree));
            parentNode.Nodes.Add(new QuadTreeNode(Range.From(
                                                      new Position(startRow + halfRow, startCol + halfCol),
                                                      halfRow, halfCol), Depth, QuadTree));
        }
Beispiel #7
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="rectangle"></param>
		public QuadTree(Range rectangle)
		{
			m_rectangle = rectangle;
			m_root = new QuadTreeNode(m_rectangle, 0, this);
			QuadTreeNodeDivider = new ProportioanteSizeNodeDivider();
		}
Beispiel #8
0
 public QuadTreeNode CreateNewRoot(QuadTreeNode currentRoot)
 {
     return(new ProportioanteSizeNodeDivider().CreateNewRoot(currentRoot));
 }
		public void IsProportionateTrue()
		{
			var node = new QuadTreeNode(new Range(0, 0, 1000, 500));
			var divider = new ProportioanteSizeNodeDivider();
			Assert.AreEqual(true, divider.IsProportionate(node));
		}
Beispiel #10
0
		/// <summary>
		/// Double ocuppied space by adding one more root level node.
		/// Current root will go under the new root
		/// </summary>
		public void Grow()
		{
			this.m_root = this.QuadTreeNodeDivider.CreateNewRoot(m_root);
			this.m_rectangle = m_root.Bounds;
		}
Beispiel #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="rectangle"></param>
 public QuadTree(RectangleF rectangle)
 {
     m_rectangle = rectangle;
     m_root      = new QuadTreeNode <T>(m_rectangle);
 }
Beispiel #12
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="rectangle"></param>
 public QuadTree(Range rectangle)
 {
     m_rectangle         = rectangle;
     m_root              = new QuadTreeNode(m_rectangle, 0, this);
     QuadTreeNodeDivider = new ProportioanteSizeNodeDivider();
 }
Beispiel #13
0
 public QuadTree(Rectangle bound)
 {
     m_rectangle = bound;
     m_root      = new QuadTreeNode(m_rectangle);
 }
Beispiel #14
0
		public QuadTreeNode CreateNewRoot(QuadTreeNode currentRoot)
		{
			return new ProportioanteSizeNodeDivider().CreateNewRoot(currentRoot);
		}
Beispiel #15
0
 /// <summary>
 /// Double ocuppied space by adding one more root level node.
 /// Current root will go under the new root
 /// </summary>
 public void Grow()
 {
     this.m_root      = this.QuadTreeNodeDivider.CreateNewRoot(m_root);
     this.m_rectangle = m_root.Bounds;
 }
Beispiel #16
0
		public bool IsProportionate(QuadTreeNode node)
		{
			if (node.Bounds.ColumnsCount * 2 < node.Bounds.RowsCount)
				return false;
			return true;
		}
Beispiel #17
0
		public void CreateSubNodes(QuadTreeNode parentNode)
		{
			var m_bounds = parentNode.Bounds;
			// the smallest subnode has an area
			if ((parentNode.Bounds.ColumnsCount * parentNode.Bounds.RowsCount) <= 10)
				return;

			int startRow = m_bounds.Start.Row;
			int startCol = m_bounds.Start.Column;
			int halfCol = (m_bounds.ColumnsCount / 2);
			int halfRow = (m_bounds.RowsCount/ 2);

			var Depth = parentNode.Depth;
			var QuadTree = parentNode.QuadTree;
			
			parentNode.Nodes.Add(new QuadTreeNode(Range.From(m_bounds.Start, halfRow, halfCol), Depth, QuadTree));
			parentNode.Nodes.Add(new QuadTreeNode(Range.From(
				new Position(startRow, startCol + halfCol),
				halfRow, halfCol), Depth, QuadTree));
			parentNode.Nodes.Add(new QuadTreeNode(Range.From(
				new Position(startRow + halfRow, startCol),
				halfRow, halfCol), Depth, QuadTree));
			parentNode.Nodes.Add(new QuadTreeNode(Range.From(
				new Position(startRow + halfRow, startCol + halfCol),
				halfRow, halfCol), Depth, QuadTree));
		}