2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Tizen.Multimedia
22 /// This class represents location of the object bounded by rectangle defined by
23 /// coordinates of top left corner, width and height.
25 public struct Rectangle
27 private Point _location;
31 /// Initializes a new instance of the Rectangle with the specified values.
33 /// <param name="x">The x-coordinate of the upper-left corner of the rectangle.</param>
34 /// <param name="y">The y-coordinate of the upper-left corner of the rectangle.</param>
35 /// <param name="width">The Width of the rectangle.</param>
36 /// <param name="height">The Height of the rectangle.</param>
37 public Rectangle(int x, int y, int width, int height) : this(new Point(x, y),
38 new Size(width, height))
43 /// Initializes a new instance of the Rectangle with the specified values.
45 /// <param name="location">A <see cref="Location"/> that represents the upper-left corner of the rectangular region.</param>
46 /// <param name="size">A <see cref="Size"/> that represents the width and height of the rectangular region.</param>
47 public Rectangle(Point location, Size size)
54 /// Gets or sets the coordinates of the upper-left corner of the rectangle.
58 get { return _location; }
59 set { _location = value; }
63 /// Gets or sets the x-coordinate of the upper-left corner of the rectangle.
67 get { return _location.X; }
68 set { _location.X = value; }
72 /// Gets or sets the y-coordinate of the upper-left corner of the rectangle.
76 get { return _location.Y; }
77 set { _location.Y = value; }
81 /// Gets or sets the width of the rectangle.
85 get { return _size.Width; }
86 set { _size.Width = value; }
90 /// Gets or sets the height of the rectangle.
94 get { return _size.Height; }
95 set { _size.Height = value; }
99 /// Gets the x-coordinate of the left edge of the rectangle.
101 public int Left => X;
104 /// Gets the y-coordinate of the top edge of the rectangle.
109 /// Gets the x-coordinate of the right edge of the rectangle.
111 public int Right => X + Width;
114 /// Gets the y-coordinate of the bottom edge of the rectangle.
116 public int Bottom => Y + Height;
119 /// Gets or sets the size of the rectangle.
123 get { return _size; }
124 set { _size = value; }
128 /// Returns a string that represents the current object.
130 /// <returns>A string that represents the current object.</returns>
131 public override string ToString() => $"{_location.ToString()}, {_size.ToString()}";
134 /// Gets the hash code for this instance of <see cref="Rectangle"/>.
136 /// <returns>The hash code for this instance of <see cref="Rectangle"/>.</returns>
137 public override int GetHashCode()
139 return new { Location, Size }.GetHashCode();
143 /// Compares an object to an instance of <see cref="Rectangle"/> for equality.
145 /// <param name="obj">A <see cref="Object"/> to compare.</param>
146 /// <returns>true if the rectangles are equal; otherwise, false.</returns>
147 public override bool Equals(object obj)
149 return obj is Rectangle && this == (Rectangle)obj;
153 /// Compares two instances of <see cref="Rectangle"/> for equality.
155 /// <param name="rect1">A <see cref="Rectangle"/> to compare.</param>
156 /// <param name="rect2">A <see cref="Rectangle"/> to compare.</param>
157 /// <returns>true if the two instances of <see cref="Rectangle"/> are equal; otherwise false.</returns>
158 public static bool operator ==(Rectangle rect1, Rectangle rect2)
160 return rect1.Location == rect2.Location && rect1.Size == rect2.Size;
164 /// Compares two instances of <see cref="Rectangle"/> for inequality.
166 /// <param name="rect1">A <see cref="Rectangle"/> to compare.</param>
167 /// <param name="rect2">A <see cref="Rectangle"/> to compare.</param>
168 /// <returns>true if the two instances of <see cref="Rectangle"/> are not equal; otherwise false.</returns>
169 public static bool operator !=(Rectangle rect1, Rectangle rect2)
171 return !(rect1 == rect2);