/// <summary> /// Removes the node. /// </summary> /// <param name="node">Node.</param> public void RemoveNode(SpatialFruitNode node) { if (!System.Object.ReferenceEquals(node, null)) { Nodes.Remove(node); } }
public bool AddNode(SpatialFruitNode node) { if (!System.Object.ReferenceEquals(node, null)) { return(QTree.AddNode(node)); } return(false); }
public void RemoveNode(SpatialFruitNode node) { if (!System.Object.ReferenceEquals(node, null)) { QuadTree tree = GetTreeByID(node.SpatialNodeID); if (!System.Object.ReferenceEquals(tree, null)) { tree.RemoveNode(node); } } }
public void HandleNodePosChanged(SpatialFruitNode node) { QuadTree tree = GetTreeByID(node.SpatialNodeID); if (!System.Object.ReferenceEquals(tree, null)) { if (!tree.IsNodeInrange(ref node)) { tree.RemoveNode(node); AddNode(node); } } }
/// <summary> /// Adds the node. /// </summary> /// <returns><c>true</c>, if node was added, /// <c>false</c> otherwise.</returns> /// <param name="node">Node.</param> public bool AddNode(SpatialFruitNode node) { if (!System.Object.ReferenceEquals(node, null) && IsNodeInrange(ref node)) { if (NotShouldDivide() && !IsSubOpened) { Nodes.Add(node); node.SpatialNodeID = ID; CurNodeCount++; //TinyLogger.Instance.DebugLog( //String.Format("$ add leaf node {0}, {1}, " + //"count: {2}, MaxCapacity {3}", //node.Position.x, node.Position.y, //CurNodeCount, MaxCapacity)); //TinyLogger.Instance.DebugLog( //String.Format("$ in leaf range {0}" + //", {1}, {2}, {3}, {4}", //Boundary.X, //Boundary.Y, //Boundary.Width, //Boundary.Height, //Nodes.Count)); return(true); } if (!IsSubOpened) { SubDivide(); for (int j = 0; j < Nodes.Count; j++) { var qtnode = Nodes[j]; for (var i = 0; i < SubTrees.Count; i++) { var result = SubTrees[i].AddNode(qtnode); if (result) { //TinyLogger.Instance.DebugLog( //String.Format("$$$ add leaf node pos {0}, {1}", //qtnode.Position.x, qtnode.Position.y)); //TinyLogger.Instance.DebugLog( //String.Format("$$$ add leaf range {0}, " + //"{1}, {2}, {3}, {4}", //SubTrees[i].Boundary.X, //SubTrees[i].Boundary.Y, //SubTrees[i].Boundary.Width, //SubTrees[i].Boundary.Height, //SubTrees[i].Nodes.Count)); break; } } } Nodes.Clear(); CurNodeCount = 0; } for (var i = 0; i < SubTrees.Count; i++) { if (SubTrees[i].AddNode(node)) { return(true); } } } return(false); }
/// <summary> /// Ises the node inrange. /// </summary> /// <returns><c>true</c>, if node inrange was ised, /// <c>false</c> otherwise.</returns> /// <param name="node">Node.</param> public bool IsNodeInrange(ref SpatialFruitNode node) { return(Boundbox.Contains(node.Position)); //return Boundary.ContainPoint(ref node.Position); }