public static IEnumerable <Point> Within(this IEnumerable <Point> points, char[,] mx) { var(w, h) = mx.Dim(); return(points.Where(p => p.X >= 0 && p.X < w && p.Y >= 0 && p.Y < w)); }