using System.Collections.Generic; using System.Linq; namespace MonoGame.Extended.Collisions.QuadTree; /// /// Data structure for the quad tree. /// Holds the entity and collision data for it. /// public class QuadtreeData { private readonly ICollisionActor _target; private readonly HashSet _parents = new(); /// /// Initialize a new instance of QuadTreeData. /// /// public QuadtreeData(ICollisionActor target) { _target = target; Bounds = _target.Bounds.BoundingRectangle; } /// /// Remove a parent node. /// /// public void RemoveParent(QuadTree parent) { _parents.Remove(parent); } /// /// Add a parent node. /// /// public void AddParent(QuadTree parent) { _parents.Add(parent); Bounds = _target.Bounds.BoundingRectangle; } /// /// Remove all parent nodes from this node. /// public void RemoveFromAllParents() { foreach (var parent in _parents.ToList()) { parent.Remove(this); } _parents.Clear(); } /// /// Gets the bounding box for collision detection. /// public RectangleF Bounds { get; set; } /// /// Gets the collision actor target. /// public ICollisionActor Target => _target; /// /// Gets or sets whether Target has had its collision handled this /// iteration. /// public bool Dirty { get; private set; } /// /// Mark node as dirty. /// public void MarkDirty() { Dirty = true; } /// /// Mark node as clean, i.e. not dirty. /// public void MarkClean() { Dirty = false; } }