using System.Collections.Generic; using System.Linq; using Chernobyl.Collections.Generic.Event; using Chernobyl.Collections.Generic.Hierarchy; using Chernobyl.Mathematics.Geometry; using Chernobyl.Values; using Chernobyl.Collections.Generic; using Enumerable = System.Linq.Enumerable; namespace Chernobyl.Mathematics.Space { /// /// An implementation of an whose purpose is to only hold /// sub-cells (see ). /// public class CellCollection : Shape, ICell { /// /// Initializes a new instance of the class. /// public CellCollection() : this(null) { } /// /// Initializes a new instance of the class. /// /// The immediate superior of this node in the /// hierarchy or null if this node has no superior. public CellCollection(ICell parent) : this(parent, Enumerable.Empty()) {} /// /// Initializes a new instance of the class. /// /// The immediate superior of this node in the /// hierarchy or null if this node has no superior. /// The immediate subordinates of this node in /// the hierarchy. public CellCollection(ICell parent, IEnumerable children) { Children = new DecoratingEventCollection(new HierarchalChildren(this)); Children.ItemsAdded += (sender, args) => _shapeCollection.AddRange(args.Items); Children.ItemsRemoved += (sender, args) => _shapeCollection.RemoveRange(args.Items); Parent = new HierarchalParent(this); Parent.Value = parent; Children.AddRange(children); } /// /// The immediate superior of this node in the hierarchy or null if this /// node has no superior. /// public IDynamicContainer Parent { get; private set; } /// /// The immediate subordinates of this node in the hierarchy. /// public IEventCollection Children { get; private set; } /// /// True if this is convex, false if it is concave /// or has 0 (such as a point). A /// is convex if for every pair of points within /// the object, every point on the straight line segment that joins them /// is also within the object. A concave is the /// opposite of this. /// public override bool IsConvex { get { return _shapeCollection.IsConvex; } } /// /// The amount of space taken up by an object on a flat plane in /// square metres (m^2). /// public override float Area { get { return _shapeCollection.Area; } } /// /// The amount of 3D space this object consumes in cubic metres (m^3). /// If this object is 2D, then the value of this property is zero. /// public override float Volume { get { return _shapeCollection.Volume; } } /// /// The length of the path that surrounds a shape specified in metres (m). /// in the case of a closed curve such as a circle, this value represents /// the circumference of the object. /// public override float Perimeter { get { return _shapeCollection.Perimeter; } } /// /// The minimum number of coordinates needed to specify each point /// within this object. For example: a point has 0 dimensions, a /// line has 1 dimension, a circle or rectangle has 2 dimensions, a /// cube or sphere has 3 dimensions, and a moving cube or sphere has 4. /// public override uint Dimensions { get { return _shapeCollection.Dimensions; } } /// /// The instance that manages that manages that /// aspect of this type. /// readonly ShapeCollection _shapeCollection = new ShapeCollection(); } }