//constructor
 public Node(T V, MiniTree <T> l, MiniTree <T> r, Boolean s)
 {
     Vector  = V;
     left    = l;
     right   = r;
     sortage = s;
 }
예제 #2
0
	//constructor
	public Node(T xval, T yval, MiniTree<T> l, MiniTree<T> r)
	{
		Xvalue = xval;
		Yvalue = yval;
		left = l;
		right = r;
	}
예제 #3
0
//Call this with nextLevelSortedOnX =true!
static MiniTree<float> insertIntoKD(float[] XY, bool nextLevelSortedOnX, MiniTree<float> root)
{
	//If the root is empty we cant do squat.	
	if(root.isEmpty() == false)
	{
		//We are in a level that is sorted by X values.
		if(nextLevelSortedOnX == true)
		{
			//Node already present!
			if (XY [0] == root.getXValue() && XY [1] == root.getYValue()) 
			{
				Console.WriteLine("Node already there!");
				return root;
			}	
			//Node to be inserted has bigger X value, so we look in the right tree.
			else if(XY[0] > root.getXValue())
			{
				return new Node<float>(XY[0], XY[1], root.getLeftMTree(), insertIntoKD(XY, false, root.getRightMTree()));
			}
			//Node to be inserted has smaller X value, so we look in the right tree.
			else 
			{
				return new Node<float>(XY[0], XY[1], insertIntoKD(XY, false, root.getLeftMTree()), root.getRightMTree());
			}
		}
		//Next level sorted on Y
		else
		{
			//Node already present!
			if (XY [0] == root.getXValue() && XY [1] == root.getYValue()) 
			{
				Console.WriteLine("Node already there!");
				return root;
			}	
			//Node to be inserted has bigger Y value, so we look in the right tree.
			else if(XY[1] > root.getYValue())
			{
				//TODO: ANDERE TREE MOET OOK INGEVULD WORDEN!
				return new Node<float>(XY[0], XY[1], root.getLeftMTree(), insertIntoKD(XY, false, root.getRightMTree()));
			}
			//Node to be inserted has smaller Y value, so we look in the left tree.
			else 
			{
				return new Node<float>(XY[0], XY[1], insertIntoKD(XY, false, root.getLeftMTree()), root.getRightMTree());
			}
		}
	}
	else
		return root;
}
예제 #4
0
static bool findNode(float[] XY, bool nextLevelSortedOnX, MiniTree<float> root)
{
	//If the root is empty we cant do squat.	
	if(root.isEmpty() == false)
	{
		//We are in a level that is sorted by X values.
		if(nextLevelSortedOnX == true)
		{
			//Node found!
			if (XY [0] == root.getXValue() && XY [1] == root.getYValue()) 
			{
				Console.WriteLine("Node found!");
				return true;
			}	
			//Node has bigger X value, so we look in the right tree.
			else if(XY[0] > root.getXValue())
			{
				return findNode(XY, false, root.getRightMTree());
			}
			//Node has smaller X value, so we look in the right tree.
			else 
			{
				return findNode(XY, false, root.getLeftMTree());
			}
		}
		//Next level sorted on Y
		else
		{
			//Node found!
			if (XY [0] == root.getXValue() && XY [1] == root.getYValue()) 
			{
				Console.WriteLine("Node already there!");
				return true;
			}	
			//Node has bigger Y value, so we look in the right tree.
			else if(XY[1] > root.getYValue())
			{
				return findNode(XY, true, root.getRightMTree());
			}
			//Node thas smaller Y value, so we look in the left tree.
			else 
			{
				return findNode(XY, true, root.getLeftMTree());
			}
		}
	}
	else
		return false;
}
        //Call this with isParentX =true!
        static MiniTree <Vector2> insertIntoKD(Vector2 Vector, MiniTree <Vector2> root, bool isParentX)
        {
            if (root.isEmpty())
            {
                if (isParentX)
                {
                    return(new Node <Vector2>(Vector, new EmptyNode <Vector2>(), new EmptyNode <Vector2>(), false));
                }
                else
                {
                    return(new Node <Vector2>(Vector, new EmptyNode <Vector2>(), new EmptyNode <Vector2>(), true));
                }
            }
            if (root.sortedOnX())
            {
                if (root.getVector() == Vector)
                {
                    return(root);
                }

                if (Vector.X < root.getVector().X)
                {
                    return(new Node <Vector2>(root.getVector(), insertIntoKD(Vector, root.getLeftMTree(), root.sortedOnX()), root.getRightMTree(), true));
                }
                else
                {
                    return(new Node <Vector2>(root.getVector(), root.getLeftMTree(), insertIntoKD(Vector, root.getRightMTree(), root.sortedOnX()), true));
                }
            }
            else
            {
                if (root.getVector() == Vector)
                {
                    return(root);
                }

                if (Vector.Y < root.getVector().Y)
                {
                    return(new Node <Vector2>(root.getVector(), insertIntoKD(Vector, root.getLeftMTree(), root.sortedOnX()), root.getRightMTree(), false));
                }
                else
                {
                    return(new Node <Vector2>(root.getVector(), root.getLeftMTree(), insertIntoKD(Vector, root.getRightMTree(), root.sortedOnX()), false));
                }
            }
        }
예제 #6
0
        /// <summary>
        /// 递归生成加载子节点
        /// add by lpl
        /// 2019-1-8
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        public List <MiniTree> CreateChild(string Id)
        {
            var listLawManger = new LawMangerBll().QueryList(new LawMangerEntity()
            {
                ParentId = Id
            });

            List <MiniTree> listTree = new List <MiniTree>();

            foreach (var list in listLawManger)
            {
                MiniTree rooTree = new MiniTree();
                rooTree.id       = list.Id;
                rooTree.ParentId = list.ParentId;
                rooTree.text     = list.Name;
                rooTree.children = CreateChild(rooTree.id);
                listTree.Add(rooTree);
            }
            return(listTree);
        }
        //Rangesearch
        static void rangeSearch(MiniTree <Vector2> root, Vector2 houseVector, float radius, List <Vector2> returnList)
        {
            if (root.isEmpty() == false)
            {
                if (root.sortedOnX() == true)
                {
                    if (Math.Abs(houseVector.X - root.getVector().X) <= radius)
                    {
                        //Euclidean check for good measure (haha)
                        if (Vector2.Distance(root.getVector(), houseVector) <= radius)
                        {
                            returnList.Add(root.getVector());
                        }

                        //Be thorough and searche the rest too
                        rangeSearch(root.getLeftMTree(), houseVector, radius, returnList);
                        rangeSearch(root.getRightMTree(), houseVector, radius, returnList);
                    }
                    else if (root.getVector().X >= (houseVector.X + radius))
                    {
                        Debug.WriteLine(root.getVector().X + " is bigger than " + (houseVector.X + radius) + " so we go left");
                        rangeSearch(root.getLeftMTree(), houseVector, radius, returnList);
                    }
                    else if (root.getVector().X <= (houseVector.X - radius))
                    {
                        Debug.WriteLine(root.getVector().X + " is smaller than " + (houseVector.X + radius) + " so we go right");
                        rangeSearch(root.getRightMTree(), houseVector, radius, returnList);
                    }
                    else
                    {
                        Debug.WriteLine("Not a single matching node found");
                    }
                }
                else
                {
                    if (Math.Abs(houseVector.Y - root.getVector().Y) <= radius)
                    {
                        //Euclidean check for good measure (haha)
                        if (Vector2.Distance(root.getVector(), houseVector) <= radius)
                        {
                            returnList.Add(root.getVector());
                        }

                        //Be thorough and searche the rest too
                        rangeSearch(root.getLeftMTree(), houseVector, radius, returnList);
                        rangeSearch(root.getRightMTree(), houseVector, radius, returnList);
                    }
                    else if (root.getVector().Y > (houseVector.Y + radius))
                    {
                        Debug.WriteLine(root.getVector().Y + " is bigger than " + (houseVector.Y + radius) + " so we go left");
                        rangeSearch(root.getLeftMTree(), houseVector, radius, returnList);
                    }
                    else if (root.getVector().Y < (houseVector.Y - radius))
                    {
                        Debug.WriteLine(root.getVector().Y + " is smaller than " + (houseVector.Y + radius) + " so we go right");
                        rangeSearch(root.getRightMTree(), houseVector, radius, returnList);
                    }
                    else
                    {
                        Debug.WriteLine("Not a single matching node found");
                    }
                }
            }
            else
            {
                Debug.WriteLine("Empty tree");
            }
        }