BitmapReader.Extensions.PointExtensions.GetNeighboringPoints C# (CSharp) Method

GetNeighboringPoints() public static method

public static GetNeighboringPoints ( this point, int maxX = null, int maxY = null ) : Point[]
point this
maxX int
maxY int
return Point[]
        public static Point[] GetNeighboringPoints(this Point point, int? maxX = null, int? maxY = null)
        {
            var neighboringPoints = new[]
                {
                    new Point(point.X, point.Y + 1),
                    new Point(point.X, point.Y - 1),
                    new Point(point.X + 1, point.Y + 1),
                    new Point(point.X + 1, point.Y - 1),
                    new Point(point.X + 1, point.Y),
                    new Point(point.X - 1, point.Y + 1),
                    new Point(point.X - 1, point.Y - 1),
                    new Point(point.X - 1, point.Y),
                };
            if (maxX.HasValue)
            {
                neighboringPoints = neighboringPoints.Where(x => x.X <= maxX.Value).ToArray();
            }
            if (maxY.HasValue)
            {
                neighboringPoints = neighboringPoints.Where(x => x.Y <= maxY.Value).ToArray();
            }
            return neighboringPoints;
        }