public void QueryQuadTree() { // generate random bounds RectangleF extends; var allBounds = CreateRandomRectangles(out extends); // construct the quad tree var quadTree = new QuadTree(extends, 5, false); for (int i = 0; i < allBounds.Length; i++) quadTree.Insert(i, allBounds[i]); var queryRectangles = Enumerable.Range(0, 10000) .Select(i => CreateRandomRectangle(2f)) .ToArray(); // query the quad tree (and time it) // 1050ms on my pc TestHelper.AssertIsFasterThan(3000, () => { for (int i = 0; i < queryRectangles.Length; i++) { var rect = queryRectangles[i]; var res = quadTree.GetIndices(ref rect, 0f).ToList(); } }); }
public void ConstructQuadTree() { // generate random bounds RectangleF extends; var allBounds = CreateRandomRectangles(out extends); // construct the quad tree (and time it) // 40ms on my pc TestHelper.AssertIsFasterThan(300, () => { var quadTree = new QuadTree(extends, 5, false); for (int i = 0; i < allBounds.Length; i++) quadTree.Insert(i, allBounds[i]); }); }
public QTNode(RectangleF bounds, int level, QuadTree tree) { this.tree = tree; this._bounds = bounds; this._level = level; //if (level < MinLevels) //{ // //create children //} if (Level == tree.maxLevels) { indexList = new List<int>(); boundsList = new List<RectangleF>(); } }