예제 #1
0
        public WorstCouple GetWorstCouple(IEnumerable <ShapeItem <T> > items)
        {
            var worstCouple = new WorstCouple();

            var currentCoverArea = BoundingBoxHelper <T> .GetDiffCoveredArea(
                items.ElementAt(0).BoundingBox
                , items.ElementAt(1).BoundingBox);

            for (int i = 0; i < items.Count(); i++)
            {
                for (int l = 0; l < items.Count(); l++)
                {
                    if (l != i)
                    {
                        var coverArea = BoundingBoxHelper <T> .GetDiffCoveredArea(
                            items.ElementAt(i).BoundingBox
                            , items.ElementAt(l).BoundingBox);

                        if (coverArea.CompareTo(currentCoverArea) > 0)
                        {
                            currentCoverArea   = coverArea;
                            worstCouple.IndexA = i;
                            worstCouple.IndexB = l;
                        }
                    }
                }
            }

            return(worstCouple);
        }
        public void ShouldGet3Diff()
        {
            var rectangle = BoundingBoxHelper <Int32> .GetBoundingBox(3, 3);

            var rectangle2 = BoundingBoxHelper <Int32> .GetBoundingBox(4, 3);

            var diff = BoundingBoxHelper <Int32> .GetDiffCoveredArea(rectangle, rectangle2);

            Assert.AreEqual(3, diff);
        }
예제 #3
0
        public static RNode <T> GetLessEnlargementNode(IEnumerable <RNode <T> > nodes, IBoundingBox <T> item)
        {
            var nextNode   = nodes.First();
            var coverdArea = nextNode.BoundingBox.GetCoveredBoundingbox(item);
            var diff       = BoundingBoxHelper <T> .Substract(coverdArea.GetArea(), nextNode.BoundingBox.GetArea());

            //get node by trying to get the less enlargement
            for (int i = 1; i < nodes.Count(); i++)
            {
                var diff2 = BoundingBoxHelper <T> .GetDiffCoveredArea(item, nodes.ElementAt(i).BoundingBox);

                if (diff2.CompareTo(diff) < 0)
                {
                    nextNode = nodes.ElementAt(i);
                }
            }
            return(nextNode);
        }