예제 #1
0
 public void CellViewSanityTest2()
 {
     List<RectanglePoly> r = new List<RectanglePoly>() { };
     CellsPageViewer cv = new CellsPageViewer(200, 200);
     List<Rectangle> result = new List<Rectangle>(cv.ComputeView(r));
     Assert.AreEqual(0, result.Count);
 }
예제 #2
0
        public void CellViewSanityTest1()
        {
            RectanglePoly rect = new RectanglePoly(100, 100, 200, 200);
            List<RectanglePoly> r = new List<RectanglePoly>() { rect };
            CellsPageViewer cv = new CellsPageViewer(200, 200);

            List<Rectangle> result = new List<Rectangle>(cv.ComputeView(r));

            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(rect.BoundingBox, result[0]);
        }
예제 #3
0
        public void NoOverlapNoMerge()
        {
            RectanglePoly rect1 = new RectanglePoly(100, 100, 200, 200);
            RectanglePoly rect2= new RectanglePoly(200, 100, 250, 200);
            List<RectanglePoly> r = new List<RectanglePoly>() { rect1, rect2 };
            CellsPageViewer cv = new CellsPageViewer(250, 250);

            List<Rectangle> result = new List<Rectangle>(cv.ComputeView(r));
            List<Rectangle> expected = new List<Rectangle>() { rect1, rect2 };

            CollectionAssert.AreEqual(result, expected);
        }
예제 #4
0
        public override IEnumerable<Rectangle> ComputeView(IEnumerable<IPolygon> polygons)
        {
            var merged = MergeCellsIterative((from p in polygons select p.BoundingBox).AsParallel().ToList());
            CellsPageViewer cellsmerger = new CellsPageViewer(maxWidth, maxHeight);

            foreach (var merge in merged)
            {
                if (merge.Item1.Width < maxWidth)
                {
                    yield return merge.Item1;
                }
                else
                {
                    // If the strip does not fit in the current view, we want to
                    // split it at cells boundaries in such a way that each chunk
                    // of the strip fits in the view.

                    // As a first approximation, we use a greedy algorithm that
                    // stuffs as many cells of the strip as the view can hold,
                    // repeatedly. This can cause the views to be unbalanced:
                    // a strip of 4 cells of the same size could be split into
                    // a large view of 3 cells and a small view of 1 cell.

                    // We use a naive algorithm to balance the cells between each
                    // views to avoid this.

                    var mergedCells = (
                        from cell in cellsmerger.MergeCellsIterative(merge.Item2)
                        select cell.Item1).ToList();
                    var views = balance(maxViews(mergedCells).ToList(), mergedCells);

                    int i = 0;
                    foreach (var view in views)
                    {
                        Rectangle viewRect = mergedCells[i++];
                        while (i < view)
                        {
                            viewRect = Rectangle.Union(viewRect, mergedCells[i]);
                            i++;
                        }
                        yield return viewRect;
                    }
                }
            }
        }