1+ using Quadtree . Items ;
2+ using System . Collections . Generic ;
3+ using UnityEngine ;
4+
5+ namespace Quadtree
6+ {
7+ /// <summary>
8+ /// Mandatory interface of any single quad tree node.
9+ /// </summary>
10+ public interface INode < TItem , TNode >
11+ where TItem : IItem < TItem , TNode >
12+ where TNode : INode < TItem , TNode >
13+ {
14+ /// <summary>
15+ /// Bounds of this tree node.
16+ /// </summary>
17+ Bounds Bounds { get ; set ; }
18+
19+ /// <summary>
20+ /// Root of the whole tree.
21+ /// </summary>
22+ IQuadtreeRoot < TItem , TNode > TreeRoot { get ; set ; }
23+
24+ /// <summary>
25+ /// Reference to parent tree node.
26+ /// </summary>
27+ /// <remarks>
28+ /// Is <c>null</c> for root node of the tree.
29+ /// </remarks>
30+ TNode ParentNode { get ; set ; }
31+
32+ /// <summary>
33+ /// Child nodes of this node.
34+ /// </summary>
35+ IList < TNode > SubNodes { get ; set ; }
36+
37+ /// <summary>
38+ /// Verifies whether provided boundaries (<paramref name="bounds"/>) are fully contained within the boundaries of the node.
39+ /// </summary>
40+ ///
41+ /// <param name="bounds">Boundaries of an object</param>
42+ /// <returns><c>True</c> if object is fully contained within the node, <c>False</c> otherwise</returns>
43+ bool Contains ( Bounds bounds ) ;
44+
45+ /// <summary>
46+ /// Calculates relative internal position of the provided bounds (<paramref name="bounds"/>) within the node.
47+ /// </summary>
48+ /// <remarks>
49+ /// The method expects the boundaries to be fully contained within the node.
50+ /// </remarks>
51+ ///
52+ /// <param name="bounds">Boundaries contained within the node</param>
53+ /// <returns>Relative internal position</returns>
54+ IntraLocation Location ( Bounds bounds ) ;
55+
56+ /// <summary>
57+ /// Inserts item (<paramref name="item"/>) into the smallest node possible in the subtree.
58+ /// </summary>
59+ /// <remarks>
60+ /// The method expects item boundaries to be fully contained within the node.
61+ /// </remarks>
62+ ///
63+ /// <param name="item">Item to be inserted</param>
64+ void Insert ( TItem item ) ;
65+
66+ /// <summary>
67+ /// Removes the provided item (<paramref name="item"/>) from the node and its subtree.
68+ /// </summary>
69+ ///
70+ /// <param name="item">Item to be removed from the tree</param>
71+ void Remove ( TItem item ) ;
72+
73+ /// <summary>
74+ /// Checks whether the node and recursively all its subnodes are empty.
75+ /// </summary>
76+ ///
77+ /// <returns><c>True</c> if node and all its subnodes are empty, <c>False</c> otherwise</returns>
78+ bool IsEmpty ( ) ;
79+
80+ /// <summary>
81+ /// Updates provided item's (<paramref name="item"/>) location within the tree.
82+ /// </summary>
83+ ///
84+ /// <param name="item">Item which's location is to be updated</param>
85+ /// <param name="forceInsertionEvaluation"><c>True</c> forces tree to re-insert the item</param>
86+ /// <param name="hasOriginallyContainedItem"><c>True</c> only for the first called node</param>
87+ void Update ( TItem item , bool forceInsertionEvaluation = true , bool hasOriginallyContainedItem = true ) ;
88+
89+ /// <summary>
90+ /// Finds items (<paramref name="items"/>) located within provided boundaries (<paramref name="bounds"/>).
91+ /// </summary>
92+ ///
93+ /// <param name="bounds">Boundaries to look for items within</param>
94+ /// <param name="items">Output list for found items</param>
95+ void FindAndAddItems ( Bounds bounds , ref IList < TItem > items ) ;
96+
97+ /// <summary>
98+ /// Adds all items of this node and its sub-nodes to the provided list of items (<paramref name="items"/>).
99+ /// If boundaries (<paramref name="bounds"/>) are provided then only items intersecting with them will be added.
100+ /// </summary>
101+ ///
102+ /// <param name="items">Output list for found items</param>
103+ /// <param name="bounds">Boundaries to look for items within</param>
104+ void AddItems ( ref IList < TItem > items , Bounds ? bounds = null ) ;
105+
106+ /// <summary>
107+ /// Removes any existing items from the node and removes all of its sub-nodes.
108+ /// </summary>
109+ void Clear ( ) ;
110+
111+ /// <summary>
112+ /// Displays boundaries of this node and all its sub-nodes and optinally a current number of contained items if <paramref name="displayNumberOfItems"/> is <c>True</c>.
113+ /// </summary>
114+ ///
115+ /// <param name="displayNumberOfItems"><c>True</c> if number of node's items should be displayed</param>
116+ void DrawBounds ( bool displayNumberOfItems = false ) ;
117+ }
118+ }
0 commit comments