public void NullChildrenReturnsEmptyEnumeration() { SquaringAlgorithm rect = new SquaringAlgorithm(); TreeMapNode node = new TreeMapNode { Area = 1.0, Children = null }; IEnumerable<Tuple<Rect, TreeMapNode>> result = rect.Split(new Rect(0, 0, 100, 100), node, NoThickness).ToArray(); Assert.IsFalse(result.Any()); }
public void ZeroParentAreaReturnsEmptyEnumeration() { SquaringAlgorithm rect = new SquaringAlgorithm(); TreeMapNode node = new TreeMapNode { Area = 0.0, Children = new List<TreeMapNode> { new TreeMapNode { Area = 0.0, Children = null } } }; IList<SWCDV::Tuple<Rect, TreeMapNode>> result = rect.Split(new Rect(0, 0, 100, 100), node, NoThickness).ToArray(); Assert.IsFalse(result.Any()); }
/// <summary> /// Recursively computes TreeMap rectangles given the root node and the bounding rectangle as start. /// </summary> /// <param name="root">Root of the TreeMapNode tree.</param> /// <param name="boundingRectangle">Bounding rectangle which will be sub-divided.</param> /// <returns>A list of RectangularAreas containing a rectangle for each node in the tree.</returns> private IEnumerable <(Rect RectangularArea, TreeMapNode TreeMapNode)> ComputeRectangles(TreeMapNode root, Rect boundingRectangle) { Queue <(Rect RectangularArea, TreeMapNode TreeMapNode)> treeQueue = new Queue <(Rect RectangularArea, TreeMapNode TreeMapNode)>(); treeQueue.Enqueue((boundingRectangle, root)); // Perform a breadth-first traversal of the tree SquaringAlgorithm algorithm = new SquaringAlgorithm(); while (treeQueue.Count > 0) { var currentParent = treeQueue.Dequeue(); yield return(currentParent); foreach (var rectangle in algorithm.Split(currentParent.RectangularArea, currentParent.TreeMapNode, currentParent.TreeMapNode.ChildItemPadding)) { treeQueue.Enqueue(rectangle); } } }
/// <summary> /// Recursively computes TreeMap rectangles given the root node and the bounding rectangle as start. /// </summary> /// <param name="root">Root of the TreeMapNode tree.</param> /// <param name="boundingRectangle">Bounding rectangle which will be sub-divided.</param> /// <returns>A list of RectangularAreas containing a rectangle for each node in the tree.</returns> private IEnumerable <Tuple <Rect, TreeMapNode> > ComputeRectangles(TreeMapNode root, Rect boundingRectangle) { Queue <Tuple <Rect, TreeMapNode> > treeQueue = new Queue <Tuple <Rect, TreeMapNode> >(); treeQueue.Enqueue(new Tuple <Rect, TreeMapNode>(boundingRectangle, root)); // Perform a breadth-first traversal of the tree SquaringAlgorithm algorithm = new SquaringAlgorithm(); while (treeQueue.Count > 0) { Tuple <Rect, TreeMapNode> currentParent = treeQueue.Dequeue(); yield return(currentParent); foreach (Tuple <Rect, TreeMapNode> rectangle in algorithm.Split(currentParent.Item1, currentParent.Item2, currentParent.Item2.ChildItemPadding)) { treeQueue.Enqueue(rectangle); } } }
/// <summary> /// Recursively computes TreeMap rectangles given the root node and the bounding rectangle as start. /// </summary> /// <param name="root">Root of the TreeMapNode tree.</param> /// <param name="boundingRectangle">Bounding rectangle which will be sub-divided.</param> /// <returns>A list of RectangularAreas containing a rectangle for each node in the tree.</returns> private IEnumerable<Tuple<Rect, TreeMapNode>> ComputeRectangles(TreeMapNode root, Rect boundingRectangle) { Queue<Tuple<Rect, TreeMapNode>> treeQueue = new Queue<Tuple<Rect, TreeMapNode>>(); treeQueue.Enqueue(new Tuple<Rect, TreeMapNode>(boundingRectangle, root)); // Perform a breadth-first traversal of the tree SquaringAlgorithm algorithm = new SquaringAlgorithm(); while (treeQueue.Count > 0) { Tuple<Rect, TreeMapNode> currentParent = treeQueue.Dequeue(); yield return currentParent; foreach (Tuple<Rect, TreeMapNode> rectangle in algorithm.Split(currentParent.Item1, currentParent.Item2, currentParent.Item2.ChildItemPadding)) { treeQueue.Enqueue(rectangle); } } }
public void ZeroChildAreaReturnsNonemptyEnumeration() { SquaringAlgorithm rect = new SquaringAlgorithm(); TreeMapNode node = new TreeMapNode { Area = 1.0, Children = new List<TreeMapNode> { new TreeMapNode { Area = 1.0, Children = null }, new TreeMapNode { Area = 0.0, Children = null } } }; IList<Tuple<Rect, TreeMapNode>> result = rect.Split(new Rect(0, 0, 80, 100), node, NoThickness).ToArray(); Assert.AreEqual(1, result.Count); }
public void CanSplitRectanglesWithThickness() { SquaringAlgorithm rect = new SquaringAlgorithm(); TreeMapNode node = new TreeMapNode { Area = 10.0, Children = new List<TreeMapNode> { new TreeMapNode { Area = 1.0, Children = null }, new TreeMapNode { Area = 9.0, Children = null } } }; Thickness thickness = new Thickness(10, 30, 20, 40); IList<Tuple<Rect, TreeMapNode>> result = rect.Split(new Rect(40, 20, 110, 170), node, thickness).ToArray(); Assert.AreEqual(50, result[0].Item1.Top, DELTA); Assert.AreEqual(140, result[0].Item1.Bottom, DELTA); Assert.AreEqual(140, result[1].Item1.Top, DELTA); Assert.AreEqual(150, result[1].Item1.Bottom, DELTA); Assert.AreEqual(50, result[0].Item1.Left, DELTA); Assert.AreEqual(130, result[0].Item1.Right, DELTA); Assert.AreEqual(50, result[1].Item1.Left, DELTA); Assert.AreEqual(130, result[1].Item1.Right, DELTA); }
public void ThicknessIsSubtractedFromRectangleSize() { SquaringAlgorithm rect = new SquaringAlgorithm(); TreeMapNode node = new TreeMapNode { Area = 10.0, Children = new List<TreeMapNode> { new TreeMapNode { Area = 1.0, Children = null }, new TreeMapNode { Area = 9.0, Children = null } } }; Thickness thickness = new Thickness(10, 30, 20, 40); IList<Tuple<Rect, TreeMapNode>> result = rect.Split(new Rect(10, 30, 130, 170), node, thickness).ToArray(); Assert.AreEqual(2, result.Count); Assert.AreEqual(9000, result[0].Item1.Width * result[0].Item1.Height); Assert.AreEqual(1000, result[1].Item1.Width * result[1].Item1.Height); }
public void CanSplitRectanglesWithTranslatedViewport() { SquaringAlgorithm rect = new SquaringAlgorithm(); TreeMapNode node = new TreeMapNode { Area = 10.0, Children = new List<TreeMapNode> { new TreeMapNode { Area = 1.0, Children = null }, new TreeMapNode { Area = 9.0, Children = null } } }; IList<Tuple<Rect, TreeMapNode>> result = rect.Split(new Rect(50, 50, 80, 100), node, NoThickness).ToArray(); Assert.AreEqual(50, result[0].Item1.Top, DELTA); Assert.AreEqual(140, result[0].Item1.Bottom, DELTA); Assert.AreEqual(140, result[1].Item1.Top, DELTA); Assert.AreEqual(150, result[1].Item1.Bottom, DELTA); Assert.AreEqual(50, result[0].Item1.Left, DELTA); Assert.AreEqual(130, result[0].Item1.Right, DELTA); Assert.AreEqual(50, result[1].Item1.Left, DELTA); Assert.AreEqual(130, result[1].Item1.Right, DELTA); }
public void MultipleVerticalChildrenTakeAllHorizontalSpace() { SquaringAlgorithm rect = new SquaringAlgorithm(); TreeMapNode node = new TreeMapNode { Area = 10.0, Children = new List<TreeMapNode> { new TreeMapNode { Area = 1.0, Children = null }, new TreeMapNode { Area = 9.0, Children = null } } }; IList<Tuple<Rect, TreeMapNode>> result = rect.Split(new Rect(0, 0, 100, 150), node, NoThickness).ToArray(); Assert.AreEqual(0, result[0].Item1.Left, DELTA); Assert.AreEqual(100, result[0].Item1.Right, DELTA); Assert.AreEqual(0, result[1].Item1.Left, DELTA); Assert.AreEqual(100, result[1].Item1.Right, DELTA); }
public void RectanglesDoNotOverlap() { SquaringAlgorithm rect = new SquaringAlgorithm(); TreeMapNode node = new TreeMapNode { Area = 10.0, Children = new List<TreeMapNode> { new TreeMapNode { Area = 1.0, Children = null }, new TreeMapNode { Area = 9.0, Children = null } } }; IList<Tuple<Rect, TreeMapNode>> result = rect.Split(new Rect(0, 0, 100, 100), node, NoThickness).ToArray(); Assert.AreEqual(0, result[0].Item1.Top, DELTA); Assert.AreEqual(90, result[0].Item1.Bottom, DELTA); Assert.AreEqual(90, result[1].Item1.Top, DELTA); Assert.AreEqual(100, result[1].Item1.Bottom, DELTA); }
public void TupleRectTreeMapNodeTakesCorrectNode() { SquaringAlgorithm rect = new SquaringAlgorithm(); TreeMapNode node = new TreeMapNode { Area = 10.0, Children = new List<TreeMapNode> { new TreeMapNode { Area = 1.0, Children = null }, new TreeMapNode { Area = 9.0, Children = null } } }; IList<Tuple<Rect, TreeMapNode>> result = rect.Split(new Rect(0, 0, 100, 100), node, NoThickness).ToArray(); Assert.IsTrue(Object.ReferenceEquals(node.Children.First(), result[1].Item2)); }
public void PlaceholderRectangleIsCorrect() { SquaringAlgorithm rect = new SquaringAlgorithm(); TreeMapNode node = new TreeMapNode { Area = 10.0, Children = new List<TreeMapNode> { new TreeMapNode { Area = 10.0, Children = new List<TreeMapNode> { new TreeMapNode { Area = 2.0, Children = null }, new TreeMapNode { Area = 1.0, Children = null } } } } }; IList<Tuple<Rect, TreeMapNode>> result = rect.Split(new Rect(0, 0, 100, 100), node, NoThickness).ToArray(); Assert.AreEqual(new Rect(0, 0, 100, 100), result[0].Item1); }
public void ChildrenNotAddingToParent() { SquaringAlgorithm rect = new SquaringAlgorithm(); TreeMapNode node = new TreeMapNode { Area = 10.0, Children = new List<TreeMapNode> { new TreeMapNode { Area = 1.0, Children = null }, new TreeMapNode { Area = 2.0, Children = null } } }; IList<Tuple<Rect, TreeMapNode>> result = rect.Split(new Rect(0, 0, 100, 100), node, NoThickness).ToArray(); Assert.AreEqual(2, result.Count); Assert.AreEqual(result[0].Item1.Width * result[0].Item1.Height, 1999, 2001); Assert.AreEqual(result[1].Item1.Width * result[1].Item1.Height, 999, 1001); }
public void TwoReverseOrderedChildrenSplitAreaProperly() { SquaringAlgorithm rect = new SquaringAlgorithm(); TreeMapNode node = new TreeMapNode { Area = 10.0, Children = new List<TreeMapNode> { new TreeMapNode { Area = 1.0, Children = null }, new TreeMapNode { Area = 9.0, Children = null } } }; IList<Tuple<Rect, TreeMapNode>> result = rect.Split(new Rect(0, 0, 100, 100), node, NoThickness).ToArray(); Assert.AreEqual(2, result.Count); Assert.AreEqual(9000, result[0].Item1.Width * result[0].Item1.Height, DELTA); Assert.AreEqual(1000, result[1].Item1.Width * result[1].Item1.Height, DELTA); }
public void SingleChildTakesAllSpace() { SquaringAlgorithm rect = new SquaringAlgorithm(); TreeMapNode node = new TreeMapNode { Area = 1.0, Children = new List<TreeMapNode> { new TreeMapNode { Area = 1.0, Children = null } } }; IList<Tuple<Rect, TreeMapNode>> result = rect.Split(new Rect(0, 0, 100, 100), node, NoThickness).ToArray(); Assert.AreEqual(1, result.Count); Assert.AreEqual(100, result[0].Item1.Width, DELTA); Assert.AreEqual(100, result[0].Item1.Height, DELTA); }