/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Runtime.InteropServices; namespace ElmSharp { /// /// The Rect is a struct that represent rectangluar space. /// [StructLayout(LayoutKind.Sequential)] public struct Rect : IEquatable { /// /// Creates and initializes a new instance of the Rect class. /// /// X axis value. /// Y axis value. /// Width value. /// Height value. public Rect(int x, int y, int w, int h) { X = x; Y = y; Width = w; Height = h; } /// /// Gets or sets the position of this Rectangle on the X axis. /// public int X { get; set; } /// /// Gets or sets the position of this Rectangle on the Y axis. /// public int Y { get; set; } /// /// Gets or sets the width of this Rectangle. /// public int Width { get; set; } /// /// Gets or sets the height of this Rectangle. /// public int Height { get; set; } /// /// Gets the position of this Rectangle on the X axis. /// public int Left { get { return X; } } /// /// Gets the extent along the X axis. /// public int Right { get { return X + Width; } } /// /// Gets the position of this Rectangle on the Y axis. /// public int Top { get { return Y; } } /// /// Gets the extent along the Y axis. /// public int Bottom { get { return Y + Height; } } /// /// Gets the Point defined by Rectangle.Left and Rectangle.Top. /// public Point Location { get { return new Point { X = X, Y = Y }; } } /// /// Gets the extent of the Rectangle along its X and Y axis. /// public Size Size { get { return new Size { Width = Width, Height = Height }; } } public override string ToString() { return string.Format("{{X={0} Y={1} Width={2} Height={3}}}", X, Y, Width, Height); } public override int GetHashCode() { unchecked { int hashCode = X.GetHashCode(); hashCode = (hashCode * 397) ^ Y.GetHashCode(); hashCode = (hashCode * 397) ^ Width.GetHashCode(); hashCode = (hashCode * 397) ^ Height.GetHashCode(); return hashCode; } } public override bool Equals(object obj) { if (!(obj is Rect)) return false; return Equals((Rect)obj); } public bool Equals(Rect other) { return X.Equals(other.X) && Y.Equals(other.Y) && Width.Equals(other.Width) && Height.Equals(other.Height); } /// /// Whether the two s are equal. /// /// A on the left hand side. /// A on the right hand side. /// True if the two s have equal values. public static bool operator ==(Rect r1, Rect r2) { return r1.Equals(r2); } /// /// Whether two s are not equal. /// /// A on the left hand side. /// A on the right hand side. /// True if the two s do not have equal values. public static bool operator !=(Rect r1, Rect r2) { return !r1.Equals(r2); } } }