public void ConsumeCluster(ScanCluster cluster) { var thisStart = lines[0].y; var thisEnd = lines[lines.Count - 1].y; var clusterStart = cluster.lines[0].y; var clusterEnd = cluster.lines[cluster.lines.Count - 1].y; var scans = new List <ScanLine>(); var min = Math.Min(thisStart, clusterStart); var max = Math.Max(thisEnd, clusterEnd); for (var i = min; i <= max; i++) { if (i >= thisStart && i <= thisEnd && (i < clusterStart || i > clusterEnd)) { scans.Add(lines[i - thisStart]); continue; } if (i >= clusterStart && i <= clusterEnd && (i < thisStart || i > thisEnd)) { scans.Add(cluster.lines[i - clusterStart]); continue; } // склеить lines[i - thisStart].Consume(cluster.lines[i - clusterStart]); scans.Add(lines[i - thisStart]); } lines = scans; }
public bool AreStick(ScanCluster cluster) { // cluster is beneath this var lastLine = cluster.lines[cluster.lines.Count - 1]; var ownScan = lines[lines.Count - 1].y == lastLine.y - 1 ? lines[lines.Count - 1].scans : lines.Count > 1 && lines[lines.Count - 2].y == lastLine.y - 1 ? lines[lines.Count - 2].scans : null; if (ownScan != null) { foreach (var span in ownScan) { var spanX = span.X; var spanY = span.Y; if (lastLine.scans.Any(s => (s.X >= spanX && s.X <= spanY) || (s.Y >= spanX && s.Y <= spanY))) { return(true); } if (lastLine.scans.Any(s => (spanX >= s.X && spanY <= s.X) || (spanX >= s.Y && spanY <= s.Y))) { return(true); } } } return(false); }