private void GenerateExtractSpans(int pageIdx, List <Span <Color> > tmpSpans) { var spans = ExtractSpans.SafeGet(pageIdx, new List <Span <Color> >()); var lastSpan = tmpSpans[0]; // Consolidate extracts for (int i = 1; i < tmpSpans.Count; i++) { var curSpan = tmpSpans[i]; bool sameColor = lastSpan.Object == curSpan.Object; if (sameColor && lastSpan.Adjacent(curSpan)) { lastSpan += curSpan; continue; } if (lastSpan.Overlaps(curSpan, out _)) { if (sameColor) { lastSpan += curSpan; continue; } if (lastSpan.IsWithin(curSpan)) { continue; } curSpan = new Span <Color>(curSpan.Object, lastSpan.EndIdx + 1, curSpan.EndIdx); } spans.Add(lastSpan); lastSpan = curSpan; } spans.Add(lastSpan); ExtractSpans[pageIdx] = spans; }
private bool OverlapsWithExtract(int pageIdx, Span span, out List <Span <Color> > overlaps) { overlaps = null; var spans = ExtractSpans.SafeGet(pageIdx); if (spans == null) { return(false); } // Find any overlap -- which might not be the first. int i = ExtractSpansBase[pageIdx].BinarySearch(span, SpanComparer); if (i < 0 || i >= spans.Count) { return(false); } // Iterate backward to the first overlap while (i > 0 && spans[i - 1].Overlaps(span, out _)) { i--; } // Ensure current span is overlapping if (spans[i++].Overlaps(span, out var overlap, SpanColorSelector) == false) { return(false); } // Iterate and build overlap list overlaps = new List <Span <Color> >(); for (; i < spans.Count && spans[i].Overlaps(span, out var exOverlap, SpanColorSelector); i++) { /* * bool sameColor = overlap.Object == exOverlap.Object; * * if (sameColor && (overlap.Adjacent(exOverlap) || overlap.Overlaps(exOverlap, out _))) * { * overlap += exOverlap; * } * * else * { * overlaps.Add(overlap); * overlap = exOverlap; * }*/ overlaps.Add(overlap); overlap = exOverlap; } overlaps.Add(overlap); return(true); }