public Rect(Point location, Size size) { if (location.IsNullOrEmpty() || size.IsNullOrEmpty()) { this.IsEmpty = true; this.Location = Point.Empty; this.Size = Size.Empty; this.Left = Double.NaN; this.Top = Double.NaN; this.Right = Double.NaN; this.Bottom = Double.NaN; this.Width = Double.NaN; this.Height = Double.NaN; } else { if (size.IsPartiallyEmpty) { throw new Granular.Exception("Can't create Rect with a size with an empty dimension"); } if (size.Width < 0 || size.Height < 0) { throw new Granular.Exception("Can't create Rect with a negative size"); } this.IsEmpty = false; this.Location = location; this.Size = size; this.Left = Location.X; this.Top = Location.Y; this.Right = Size.Width + Location.X; this.Bottom = Size.Height + Location.Y; this.Width = Size.Width; this.Height = Size.Height; } }
public static bool Contains(this Rect rect, Point point) { return(point.IsNullOrEmpty() || !rect.IsNullOrEmpty() && rect.Left <= point.X && point.X < rect.Right && rect.Top <= point.Y && point.Y < rect.Bottom); }
public static Point DefaultIfNullOrEmpty(this Point point, Point defaultValue = null) { return(Point.IsNullOrEmpty(point) ? (defaultValue ?? Point.Zero) : point); }
public static bool IsNullOrEmpty(this Point point) { return(Point.IsNullOrEmpty(point)); }