Exemple #1
0
        BlockSet <IBlock> FindBlockCore(BlockSet <IBlock> blockset)
        {
            var blocks = blockset.ToList();

            int   total = blocks.Count - 1;
            float limit = blockset.GetWidth() / 2;

            int start = ScanBlock(i => blocks[i], blockset.GetX() + limit);
            int end   = ScanBlock(i => blocks[total - i], blockset.GetX() + limit);

            int ini = start;
            int tot = total + 1 - end;

            var core = new BlockSet <IBlock>();

            // get the core
            for (int i = start; i <= total - end; i++)
            {
                core.Add(blocks[i]);
            }

            return(core);
        }
Exemple #2
0
        BlockSet <IBlock>[] SplitBlock(BlockSet <IBlock> blockset)
        {
            var blocks = blockset.ToList();

            int   total = blocks.Count - 1;
            float limit = blockset.GetWidth() / 2;

            int start = ScanBlock(i => blocks[i], blockset.GetX() + limit);
            int end   = ScanBlock(i => blocks[total - i], blockset.GetX() + limit);

            // no split
            if (start == 0 && end == 0)
            {
                // VALIDATE
                //System.Diagnostics.Debugger.Break();

                return(new BlockSet <IBlock>[] { blockset });
            }

            // split into 2 pieces
            int middle = -1;

            // split into 2 pieces: there is a clear division
            middle = (start + end > total) ? (start) : middle;
            middle = (start == 0) ? (total - end + 1) : middle;
            middle = (end == 0) ? (start) : middle;

            if (middle > 0)
            {
                var blockA = new BlockSet <IBlock>();
                var blockB = new BlockSet <IBlock>();

                blockA.AddRange(blocks.Take(middle));
                blockB.AddRange(blocks.TakeLast(total - middle + 1));

                int count2 = blockA.Count() + blockB.Count();
                if (count2 != blocks.Count)
                {
                    PdfReaderException.AlwaysThrow("count2 != blocks.Count");
                }

                // VALIDATE
                //System.Diagnostics.Debugger.Break();

                return(new BlockSet <IBlock>[] { blockA, blockB });
            }

            // split into 3 pieces
            var topBlock    = new BlockSet <IBlock>();
            var coreBlock   = new BlockSet <IBlock>();
            var bottomBlock = new BlockSet <IBlock>();

            topBlock.AddRange(blocks.Take(start));

            for (int i = start; i <= total - end; i++)
            {
                coreBlock.Add(blocks[i]);
            }

            bottomBlock.AddRange(blocks.TakeLast(end));

            int count3 = topBlock.Count() + coreBlock.Count() + bottomBlock.Count();

            if (count3 != blocks.Count)
            {
                PdfReaderException.AlwaysThrow("count3 != blocks.Count");
            }

            // VALIDATE
            //System.Diagnostics.Debugger.Break();
            return(new BlockSet <IBlock>[] { topBlock, coreBlock, bottomBlock });
        }