root/src/BRAINSFramework/QuadTree/QuadTreePositionItem.cs

113
1
// *******************************************//
2
// *********Credits to Kyle Schouviller*******//
3
// *******for the original implementation*****//
4
// *******************************************//
1
using System;
5
using System;
2
using Microsoft.Xna.Framework;
6
using Microsoft.Xna.Framework;
3
7
4
namespace Brains.Framework
8
namespace Brains.Framework.QuadTree
5
{
9
{
6
    /// <summary>
10
    /// <summary>
7
    /// A position item in a quadtree
11
    /// A position item in a quadtree
...
...
11
    {
15
    {
12
        public QuadTreeNode<T> node;
16
        public QuadTreeNode<T> node;
13
        internal QuadTree<T> quadTree;
17
        internal QuadTree<T> quadTree;
14
        #region Events and Event Handlers
18
        
15
19
16
        /// <summary>
20
        /// <summary>
17
        /// Handles the move event
21
        /// Handles the move event
...
...
37
            node.RemoveItem(this);
41
            node.RemoveItem(this);
38
        }
42
        }
39
43
40
        #endregion
44
        
41
45
42
        #region Properties
46
        
43
47
44
        /// <summary>
48
        /// <summary>
45
        /// The center position of this item
49
        /// The center position of this item
...
...
91
        /// <summary>
95
        /// <summary>
92
        /// The rectangle containing this item
96
        /// The rectangle containing this item
93
        /// </summary>
97
        /// </summary>
94
        private FRect rect;
98
        private RectangleF rect;
95
99
96
        /// <summary>
100
        /// <summary>
97
        /// Gets a rectangle containing this item
101
        /// Gets a rectangle containing this item
98
        /// </summary>
102
        /// </summary>
99
        public FRect Rect
103
        public RectangleF Rect
100
        {
104
        {
101
            get { return rect; }
105
            get { return rect; }
102
        }
106
        }
...
...
115
            get { return parent; }
119
            get { return parent; }
116
        }
120
        }
117
121
118
        #endregion
122
        
119
123
120
        #region Initialization
124
        
121
125
122
        /// <summary>
126
        /// <summary>
123
        /// Creates a position item in a QuadTree
127
        /// Creates a position item in a QuadTree
...
...
127
        /// <param name="size">The size of this item</param>
131
        /// <param name="size">The size of this item</param>
128
        public QuadTreePositionItem(T parent, Vector2 position, Vector2 size)
132
        public QuadTreePositionItem(T parent, Vector2 position, Vector2 size)
129
        {
133
        {
130
            this.rect = new FRect(0f, 0f, 1f, 1f);
134
            this.rect = new RectangleF(0f, 0f, 1f, 1f);
131
135
132
            this.parent = parent;
136
            this.parent = parent;
133
            this.position = position ;
137
            this.position = position ;
...
...
135
            OnMove();
139
            OnMove();
136
        }
140
        }
137
141
138
        #endregion
142
        
139
143
140
        #region Methods
144
        
141
145
142
        /// <summary>
146
        /// <summary>
143
        /// Destroys this item and removes it from the QuadTree
147
        /// Destroys this item and removes it from the QuadTree
...
...
147
            OnDestroy();
151
            OnDestroy();
148
        }
152
        }
149
153
150
        #endregion
154
        
151
    }
155
    }
152
156
153
}
157
}