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 /// Represents the location of the object bounded by a rectangle defined by
23 /// coordinates of top left corner, width and height.
25 /// <since_tizen> 3 </since_tizen>
26 public struct Rectangle
28 private Point _location;
32 /// Initializes a new instance of the <see cref="Rectangle"/> with the specified values.
34 /// <param name="x">The x-coordinate of the upper-left corner of the rectangle.</param>
35 /// <param name="y">The y-coordinate of the upper-left corner of the rectangle.</param>
36 /// <param name="width">The Width of the rectangle.</param>
37 /// <param name="height">The Height of the rectangle.</param>
38 /// <since_tizen> 3 </since_tizen>
39 public Rectangle(int x, int y, int width, int height) : this(new Point(x, y),
40 new Size(width, height))
45 /// Initializes a new instance of the <see cref="Rectangle"/> with the specified values.
47 /// <param name="location">A <see cref="Location"/> that represents the upper-left corner of the rectangular region.</param>
48 /// <param name="size">A <see cref="Size"/> that represents the width and height of the rectangular region.</param>
49 /// <since_tizen> 3 </since_tizen>
50 public Rectangle(Point location, Size size)
57 /// Gets or sets the coordinates of the upper-left corner of the rectangle.
59 /// <since_tizen> 3 </since_tizen>
62 get { return _location; }
63 set { _location = value; }
67 /// Gets or sets the x-coordinate of the upper-left corner of the rectangle.
69 /// <since_tizen> 3 </since_tizen>
72 get { return _location.X; }
73 set { _location.X = value; }
77 /// Gets or sets the y-coordinate of the upper-left corner of the rectangle.
79 /// <since_tizen> 3 </since_tizen>
82 get { return _location.Y; }
83 set { _location.Y = value; }
87 /// Gets or sets the width of the rectangle.
89 /// <since_tizen> 3 </since_tizen>
92 get { return _size.Width; }
93 set { _size.Width = value; }
97 /// Gets or sets the height of the rectangle.
99 /// <since_tizen> 3 </since_tizen>
102 get { return _size.Height; }
103 set { _size.Height = value; }
107 /// Gets the x-coordinate of the left edge of the rectangle.
109 /// <since_tizen> 3 </since_tizen>
110 public int Left => X;
113 /// Gets the y-coordinate of the top edge of the rectangle.
115 /// <since_tizen> 3 </since_tizen>
119 /// Gets the x-coordinate of the right edge of the rectangle.
121 /// <since_tizen> 3 </since_tizen>
122 public int Right => X + Width;
125 /// Gets the y-coordinate of the bottom edge of the rectangle.
127 /// <since_tizen> 3 </since_tizen>
128 public int Bottom => Y + Height;
131 /// Gets or sets the size of the rectangle.
133 /// <since_tizen> 3 </since_tizen>
136 get { return _size; }
137 set { _size = value; }
141 /// Returns a string that represents the current object.
143 /// <returns>A string that represents the current object.</returns>
144 /// <since_tizen> 3 </since_tizen>
145 public override string ToString() => $"{_location.ToString()}, {_size.ToString()}";
148 /// Gets the hash code for this instance of <see cref="Rectangle"/>.
150 /// <returns>The hash code for this instance of <see cref="Rectangle"/>.</returns>
151 /// <since_tizen> 3 </since_tizen>
152 public override int GetHashCode()
154 return new { Location, Size }.GetHashCode();
158 /// Compares an object to an instance of <see cref="Rectangle"/> for equality.
160 /// <param name="obj">A <see cref="Object"/> to compare.</param>
161 /// <returns>true if the rectangles are equal; otherwise, false.</returns>
162 /// <since_tizen> 3 </since_tizen>
163 public override bool Equals(object obj)
165 return obj is Rectangle && this == (Rectangle)obj;
169 /// Compares two instances of <see cref="Rectangle"/> for equality.
171 /// <param name="rect1">A <see cref="Rectangle"/> to compare.</param>
172 /// <param name="rect2">A <see cref="Rectangle"/> to compare.</param>
173 /// <returns>true if the two instances of <see cref="Rectangle"/> are equal; otherwise false.</returns>
174 /// <since_tizen> 3 </since_tizen>
175 public static bool operator ==(Rectangle rect1, Rectangle rect2)
177 return rect1.Location == rect2.Location && rect1.Size == rect2.Size;
181 /// Compares two instances of <see cref="Rectangle"/> for inequality.
183 /// <param name="rect1">A <see cref="Rectangle"/> to compare.</param>
184 /// <param name="rect2">A <see cref="Rectangle"/> to compare.</param>
185 /// <returns>true if the two instances of <see cref="Rectangle"/> are not equal; otherwise false.</returns>
186 /// <since_tizen> 3 </since_tizen>
187 public static bool operator !=(Rectangle rect1, Rectangle rect2)
189 return !(rect1 == rect2);