/// <summary> /// Creates a new instance of the <see cref="SharpQuadTrees.QuadTreeLeaf<TContent, TAverage>"/> class with the given content, and its accessors. /// The size ranges are found dynamically. /// <para> /// The minimum value is inclusive, while the maximum value is exclusive. /// Meaning that an item is inside if it's coordinate on each axis is greater or equal to the minimum and less than the maximum for the axis. /// </para> /// </summary> /// <param name="controller">Controller used for handling the content.</param> /// <param name="content">An array of content items.</param> public QuadTreeLeaf(IQuadTreeController <TContent, TAverage> controller, params TContent[] content) : base(controller) { if (content == null) { throw new ArgumentNullException("content", "Content can't be null."); } if (content.Length < 1) { throw new ArgumentOutOfRangeException("content", "To use this constructor, there has to be at least one content item."); } this.content = content.ToList(); //Intermediate IEnumerable of an anonymous type with the coordinates for each item to reduce calls to the controller's method. var coordinates = content.Select(item => new { X = controller.GetContentX(item), Y = controller.GetContentY(item) }); //Add double.Epsilon to max values, because they're exclusive. XMin = coordinates.Min(coordinate => coordinate.X); XMax = coordinates.Max(coordinate => coordinate.X) + double.Epsilon; YMin = coordinates.Min(coordinate => coordinate.Y); YMax = coordinates.Max(coordinate => coordinate.Y) + double.Epsilon; }
/// <summary> /// Creates a new instance of the <see cref="SharpQuadTrees.QuadTreeBranch<TContent, TAverage>"/> class with the given <see cref="SharpQuadTrees.QuadTreeLeaf<TContent, TAverage>"/>s and average-aggrigation function /// </summary> /// <param name="controller">Controller used for handling the content.</param> /// <param name="topRight">The QuadTreeLeaf in the top right part of the QuadTreeBranch.</param> /// <param name="bottomRight">The QuadTreeLeaf in the bottom right part of the QuadTreeBranch.</param> /// <param name="bottomLeft">The QuadTreeLeaf in the bottom left part of the QuadTreeBranch.</param> /// <param name="topLeft">The QuadTreeLeaf in the top left part of the QuadTreeBranch.</param> public QuadTreeBranch(IQuadTreeController <TContent, TAverage> controller, QuadTreeNode <TContent, TAverage> topRight, QuadTreeNode <TContent, TAverage> bottomRight, QuadTreeNode <TContent, TAverage> bottomLeft, QuadTreeNode <TContent, TAverage> topLeft) : base(controller) { if (topRight == null) { throw new ArgumentNullException("topRight", "Child node can't be null."); } if (bottomRight == null) { throw new ArgumentNullException("bottomRight", "Child node can't be null."); } if (bottomLeft == null) { throw new ArgumentNullException("bottomLeft", "Child node can't be null."); } if (topLeft == null) { throw new ArgumentNullException("topLeft", "Child node can't be null."); } TopRight = topRight; BottomRight = bottomRight; BottomLeft = bottomLeft; TopLeft = topLeft; setSize(); }
/// <summary> /// Creates a new instance of the <see cref="SharpQuadTrees.QuadTreeNode<TContent, TAverage>"/> class with the given controller. /// Only available in derived classes. /// </summary> /// <param name="controller">Controller used for handling the content.</param> protected QuadTreeNode(IQuadTreeController <TContent, TAverage> controller) { if (controller == null) { throw new ArgumentNullException("controller", "Controller can't be null."); } this.controller = controller; }
/// <summary> /// Creates a new instance of the <see cref="SharpQuadTrees.QuadTreeLeaf<TContent, TAverage>"/> class with the given size ranges, content, and its accessors. /// The content array is filtered based on the specified ranges for x and y. /// <para> /// The minimum value is inclusive, while the maximum value is exclusive. /// Meaning that an item is inside if it's coordinate on each axis is greater or equal to the minimum and less than the maximum for the axis. /// </para> /// </summary> /// <param name="xStart">Start of range for the x coordinate.</param> /// <param name="xEnd">End of range for the x coordinate.</param> /// <param name="yStart">Start of range for the y coordinate.</param> /// <param name="yEnd">End of range for the y coordinate.</param> /// <param name="controller">Controller used for handling the content.</param> /// <param name="content">An array of content items.</param> public QuadTreeLeaf(double xStart, double xEnd, double yStart, double yEnd, IQuadTreeController <TContent, TAverage> controller, params TContent[] content) : base(controller) { if (content == null) { throw new ArgumentNullException("content", "Content can't be null."); } XMin = Math.Min(xStart, xEnd); XMax = Math.Max(xStart, xEnd); YMin = Math.Min(yStart, yEnd); YMax = Math.Max(yStart, yEnd); this.content = content.Where(item => IsInsideNode(controller.GetContentX(item), controller.GetContentY(item)) ).ToList(); }