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 <SWCDV::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 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 <SWCDV::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 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 <SWCDV::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 NullChildrenReturnsEmptyEnumeration()
        {
            SquaringAlgorithm rect = new SquaringAlgorithm();
            TreeMapNode       node = new TreeMapNode
            {
                Area     = 1.0,
                Children = null
            };

            IEnumerable <SWCDV::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 <Tuple <Rect, TreeMapNode> > result = rect.Split(new Rect(0, 0, 100, 100), node, NoThickness).ToArray();

            Assert.IsFalse(result.Any());
        }
        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 <SWCDV::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);
        }
        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 <SWCDV::Tuple <Rect, TreeMapNode> > result = rect.Split(new Rect(0, 0, 80, 100), node, NoThickness).ToArray();

            Assert.AreEqual(1, result.Count);
        }
        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 <SWCDV::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 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 <SWCDV::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 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 <SWCDV::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 <SWCDV::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 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 <SWCDV::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 <SWCDV::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);
        }