public static void QuadtreeNonAllocTest() { float topBoundry = float.MinValue; float bottomBoundry = float.MaxValue; float leftBoundry = float.MaxValue; float rightBoundry = float.MinValue; foreach (var s in ShapeSystem.shapes) { if (s.center.x > rightBoundry) { rightBoundry = s.center.x; } if (s.center.x < leftBoundry) { leftBoundry = s.center.x; } if (s.center.y > topBoundry) { topBoundry = s.center.y; } if (s.center.y < bottomBoundry) { bottomBoundry = s.center.y; } } q.Resize( (rightBoundry + leftBoundry) / 2, (topBoundry + bottomBoundry) / 2, rightBoundry - leftBoundry, topBoundry - bottomBoundry); q.Clear(); foreach (var s in ShapeSystem.shapes) { q.Insert(s); } q.ClearEmptySubdivisions(); if (Settings.debugDrawTree) { q.Draw(); } foreach (var s in ShapeSystem.shapes) { q.Search(s); } }
public void ClearEmptySubdivisions() { if (subdivided == true) { tl.ClearEmptySubdivisions(); tr.ClearEmptySubdivisions(); bl.ClearEmptySubdivisions(); br.ClearEmptySubdivisions(); if (this.shapesCounter + tl.shapesCounter + tr.shapesCounter + bl.shapesCounter + br.shapesCounter <= 4) { for (int i = 0; i < tl.shapesCounter; i++) { shapes[shapesCounter] = tl.shapes[i]; shapesCounter++; } for (int i = 0; i < bl.shapesCounter; i++) { shapes[shapesCounter] = bl.shapes[i]; shapesCounter++; } for (int i = 0; i < tr.shapesCounter; i++) { shapes[shapesCounter] = tr.shapes[i]; shapesCounter++; } for (int i = 0; i < br.shapesCounter; i++) { shapes[shapesCounter] = br.shapes[i]; shapesCounter++; } subdivided = false; } } }