internal Point Locate(Needle needle) { // Points 0... // RearPoints 0... // Sizes 1... int firstRow = needle.StrongestPoint.Y * Size.Width; int firstRowFirstPixel = firstRow + needle.StrongestPoint.X; int lastRearRow = needle.StrongestRearPoint.Y * Size.Width; int lastRow = Pixels.Length - lastRearRow; int lastRowLastPixel = lastRow - needle.StrongestRearPoint.X; Point result = new Point(-1, -1); Parallel.For(firstRowFirstPixel, lastRowLastPixel, (index, state) => { if (MatchPixel(needle.StrongestPixel, Pixels[index]) == false) { return; } Point point = IndexToPoint(index); point.Offset(needle.StrongestPoint.X * -1, needle.StrongestPoint.Y * -1); if (MatchLocation(needle, point) == false) { return; } state.Stop(); result = point; }); return(result); }
internal bool MatchLocation(Needle needle, Point startPoint) { bool result = true; Parallel.ForEach(needle.Pixels, (pixel, state, index) => { int x = startPoint.X + (int)(index % needle.Size.Width); int y = startPoint.Y + (int)(index / needle.Size.Width); if (MatchPixel(pixel, GetPixel(x, y))) { return; } state.Stop(); result = false; }); return(result); }
internal bool Contains(Needle needle) => Locate(needle).X >= 0;