using System; using System.Drawing; using Newtonsoft.Json; namespace SBRL.Utilities { /// /// Represents a rectangle in 2D space. /// public struct Rectangle { /// /// A rectangle with all it's properties initialised to zero. /// public static Rectangle Zero = new Rectangle() { X = 0, Y = 0, Width = 0, Height = 0 }; #region Core Data /// /// The X coordinate of the rectangle. /// public int X { get; set; } /// /// The Ycoordinateof the rectangle. /// /// The y. public int Y { get; set; } /// /// The width of the rectangle. /// public int Width { get; set; } /// /// The height of the rectangle. /// public int Height { get; set; } #endregion #region Corners /// /// The top-left corner of the rectangle. /// [JsonIgnore] public Point TopLeft { get { return new Point(X, Y); } } /// /// The top-right corner of the rectangle. /// [JsonIgnore] public Point TopRight { get { return new Point(X + Width, Y); } } /// /// The bottom-left corner of the rectangle. /// [JsonIgnore] public Point BottomLeft { get { return new Point(X, Y + Height); } } /// /// The bottom-right corner of the rectangle. /// [JsonIgnore] public Point BottomRight { get { return new Point(X + Width, Y + Height); } } #endregion #region Edges /// /// The Y coordinate of the top of the rectangle. /// [JsonIgnore] public int Top { get { return Y; } } /// /// The Y coordinate of the bottom of the rectangle. /// [JsonIgnore] public int Bottom { get { return Y + Height; } } /// /// The X coordinate of the left side of the rectangle. /// [JsonIgnore] public int Left { get { return X; } } /// /// The X coordinate of the right side of the rectangle. /// [JsonIgnore] public int Right { get { return X + Width; } } #endregion public Rectangle(int x, int y, int width, int height) { X = x; Y = y; Width = width; Height = height; } } }