#region CPL License
/*
Nuclex Framework
Copyright (C) 2002-2011 Nuclex Development Labs
This library is free software; you can redistribute it and/or
modify it under the terms of the IBM Common Public License as
published by the IBM Corporation; either version 1.0 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
IBM Common Public License for more details.
You should have received a copy of the IBM Common Public
License along with this library
*/
#endregion
using System;
using System.Collections.Generic;
namespace Nuclex.Game.Space {
/// Two-dimensional spatial index
/// Type of the items being indexed
///
///
/// This class serves as the base class for spatial indexes that allow for
/// efficient searches in large sets of two-dimensional objects.
///
///
public abstract class SpatialIndex2 {
/// Queries the spatial database for all items in a region
/// Region of which the items will be returned
/// An enumerator for all items in the queried region
public virtual IEnumerable Query(BoundingRectangle region) {
List items = new List();
Query(region, items);
for(int index = 0; index < items.Count; ++index) {
yield return items[index];
}
}
/// Queries the spatial database for all objects in a region
/// Region of which the items will be returned
///
/// Collection that will receive all items in the query region
///
///
/// Use this method to avoid generating garbage by reusing the collection
/// the queried items are stored in.
///
public abstract void Query(BoundingRectangle region, ICollection items);
/// Inserts an item into the spatial database
/// Item that will be inserted
public abstract void Insert(ItemType itemToAdd);
/// Removes an item from the spatial database
/// Item that will be removed
public abstract bool Remove(ItemType itemToRemove);
}
} // namespace Nuclex.Game.Space