using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace Chernobyl.Mathematics.Collision { /// /// An /// that holds /// /// instances. This class acts like a composite; for example, calling /// /// returns the instances from /// the contained /// that were collided against. /// /// The type of /// being held /// within this . /// This type must derive from . /// The type that will /// be passed in to check for collisions against the /// instances contained within /// this . public class CollidableCollectionComposite : CollidableEnumerableComposite, ICollidableCollection where TContainedCollidable : IExtendedCollidable { /// /// Initializes a new instance of the /// /// class. /// /// The /// this list is composed of. public CollidableCollectionComposite(IEnumerable> collidables) : base(collidables.Cast>()) { Collidables = collidables; } /// /// Adds the argument passed in to all /// /// instances contained within this provided /// they are not read only (if they are the argument is not added to that /// instance). /// /// The object to add to all (except those that are /// read only) of the /// instances contained within the . public void Add(TContainedCollidable item) { foreach (ICollidableCollection containedCollidables in Collidables) { if (containedCollidables.IsReadOnly == false) containedCollidables.Add(item); } } /// /// Removes the argument passed in from all /// /// instances contained within this . /// /// The object to remove from all the /// /// instances. /// True if was successfully removed /// from at least one of the /// /// instances contained within this . /// public bool Remove(TContainedCollidable item) { bool result = false; foreach (ICollidableCollection containedCollidables in Collidables) { if (containedCollidables.IsReadOnly == false && containedCollidables.Remove(item) == true) result = true; } return result; } /// /// Determines whether the contains a specific value. /// /// The object to locate in the . /// /// true if is found in the ; otherwise, false. /// public bool Contains(TContainedCollidable item) { bool result = false; using (IEnumerator> enumerator = Collidables.GetEnumerator()) { while (enumerator.MoveNext() == true && enumerator.Current != null && result == false) result = enumerator.Current.Contains(item); } return result; } /// /// Copies the elements of the to an /// , starting at a particular /// index. /// /// The one-dimensional that is /// the destination of the elements copied from . /// The must have zero-based indexing. /// The zero-based index in /// at which copying begins. /// Thrown if /// is null. /// Thrown if /// is less than 0. /// Thrown if /// is multidimensional, is equal to or /// greater than the length of , or the number of /// elements in the source is greater than /// the available space from to the end of /// the destination . public void CopyTo(TContainedCollidable[] array, int arrayIndex) { // TODO: implement this. throw new NotImplementedException("This method is not currently implemented at the moment."); } /// /// Returns an enumerator that iterates through a collection. /// /// /// An object that can be used to /// iterate through the collection. /// public new IEnumerator GetEnumerator() { return base.GetEnumerator(); } /// /// The /// this list is composed of. /// public new IEnumerable> Collidables { get; private set; } } }