private void QueryRange(QuadTreeBoundingBox area, ref List <int> pointList) { if (!area.Overlaps(_boundary)) { return; } for (int i = 0; i < _countPoints; i++) { if (area.ContainsPoint(_quadTreePoints[i])) { pointList.Add(_quadTreePoints[i].Index); } } if (UpperLeft == null) { return; } UpperLeft.QueryRange(area, ref pointList); UpperRight.QueryRange(area, ref pointList); LowerLeft.QueryRange(area, ref pointList); LowerRight.QueryRange(area, ref pointList); }
public bool Insert(QuadTreePointStruct p) { if (!_boundary.ContainsPoint(p)) { return(false); } if (_countPoints < NODE_CAPACITY) { _quadTreePoints[_countPoints++] = p; return(true); } //If we don't have room, we must subdivide to make room if (UpperLeft == null) { Subdivide(); } if (UpperLeft.Insert(p)) { return(true); } if (UpperRight.Insert(p)) { return(true); } if (LowerLeft.Insert(p)) { return(true); } if (LowerRight.Insert(p)) { return(true); } return(false); }