BlockSet <IBlock> Merge(BlockSet <IBlock> a, BlockSet <IBlock> b) { var result = new BlockSet <IBlock>(); result.AddRange(a); result.AddRange(b); return(result); }
public PipelinePage PdfCheck <T>(Color Color) where T : IValidateMark, new() { if (Color != Color.Orange) { throw new InvalidOperationException(); } int color = MarkLine.ORANGE; var initialMarks = this.LastResult.AllBlocks.Cast <MarkLine>().Where(l => l.Color == color); var marks = new BlockSet <MarkLine>(); marks.AddRange(initialMarks); var processor = new T(); string message = processor.Validate(marks); if (message != null) { ParentContext.LogCheck(PageNumber, typeof(T), message); } return(this); }
public BlockPage Process(BlockPage page) { var result = new BlockPage(); BlockSet <IBlock> last = null; foreach (var block in page.AllBlocks) { var blockset = (BlockSet <IBlock>)block; if ((last == null) || (!CanBeMerged(last, blockset))) { var b = new BlockSet <IBlock>(); b.AddRange(blockset); result.Add(b); last = b; } else { // merge blocks last.AddRange(blockset); } } return(result); }
IBlock[] CreateNewBlocks(BlockSet <IBlock> blocks, int middle) { int total = blocks.Count(); var blockA = new BlockSet <IBlock>(); var blockB = new BlockSet <IBlock>(); blockA.AddRange(blocks.Take(middle)); blockB.AddRange(blocks.TakeLast(total - middle)); return(new IBlock[] { blockA, blockB }); }
BlockSet <IBlock> CreateNewBlock(BlockPage page, IList <IBlock> blockList) { var block = new BlockSet <IBlock>(page); if (blockList.Count == 0) { PdfReaderException.AlwaysThrow("invalid block"); } block.AddRange(blockList); return(block); }
BlockSet <IBlock> GroupBy(BlockPage page, Func <IBlock, bool> filter) { var blocks = page.AllBlocks.Where(filter); var blockset = new BlockSet <IBlock>(page); blockset.AddRange(blocks); if (blocks.Count() == 0) { return(null); } return(blockset); }
BlockSet <IBlock> GetCleanBlockSet(Block overlap, BlockSet <IBlock> block1) { var blockSet = new BlockSet <IBlock>(); var b1 = block1.Where(b => !HasOverlapY(b, overlap)); blockSet.AddRange(b1); if (blockSet.Count() == 0) { return(null); } return(blockSet); }
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 }); }