/// <summary> /// Gets all items within the boundary. /// </summary> /// <param name="boundary">Boundary to check.</param> /// <returns>Collection of all items within the boundary.</returns> public virtual IList <T> Query(IQTBoundary boundary) { List <T> itemsInRange = new List <T>(4); if (Boundary == null) { return(itemsInRange); } if (!Boundary.Intersects(boundary)) { return(itemsInRange); } foreach (T item in items) { if (boundary.ContainsPoint(item)) { itemsInRange.Add(item); } } if (northWest == null) { return(itemsInRange); } itemsInRange.AddRange(northWest.Query(boundary)); itemsInRange.AddRange(northEast.Query(boundary)); itemsInRange.AddRange(southWest.Query(boundary)); itemsInRange.AddRange(southEast.Query(boundary)); return(itemsInRange); }
/// <summary> /// Checks if another boundary intersects this one. /// </summary> /// <param name="other">Boundary to check.</param> /// <returns>True if intersects, false if not.</returns> public bool Intersects(IQTBoundary other) { if (other.Max.X < Min.X) { return(false); } if (other.Min.X > Max.X) { return(false); } if (other.Max.Y < Min.Y) { return(false); } if (other.Min.Y > Max.Y) { return(false); } return(true); }
/// <summary> /// Creates a quadtree with a boundary defined by the specified <see cref="IQTBoundary"/>. /// </summary> /// <param name="boundary">Bounding area.</param> public QuadTreeNode(IQTBoundary boundary) { QT_NODE_CAPACITY = 4; Boundary = new AABB(boundary.Min, boundary.Max); items = new List <T>(); }
/// <summary> /// Creates a <see cref="QuadTree{T}"/> with a boundary defined by the specified <see cref="IQTBoundary"/>. /// </summary> /// <param name="boundary">Bounding area.</param> public QuadTree(IQTBoundary boundary) { rootTree = new QuadTreeNode <T>(boundary); itemDictionary = new Dictionary <T, XY>(new ObjectReferenceEqualityComparer <T>()); }
/// <summary> /// Gets all items within <see cref="IQTBoundary"/>. /// </summary> /// <param name="boundary">Boundary to check.</param> /// <returns>Collection of all items within <see cref="IQTBoundary"/>.</returns> public virtual IList <T> Query(IQTBoundary boundary) { return(rootTree.Query(boundary)); }