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.Content.MediaContent
22 /// Represents the location of the object bounded by the rectangle defined by
23 /// coordinates of top left corner, width, and height.
25 public struct Rectangle
28 /// Initializes a new instance of the rectangle with the specified values.
30 /// <param name="x">The x-coordinate of the upper-left corner of the rectangle.</param>
31 /// <param name="y">The y-coordinate of the upper-left corner of the rectangle.</param>
32 /// <param name="width">The width of the rectangle.</param>
33 /// <param name="height">The height of the rectangle.</param>
34 public Rectangle(int x, int y, int width, int height)
43 /// Gets or sets the x-coordinate of the upper-left corner of the rectangle.
45 /// <value>The x-coordinate of the upper-left edge of the rectangle.</value>
46 public int X { get; set; }
49 /// Gets or sets the y-coordinate of the upper-left corner of the rectangle.
51 /// <value>The y-coordinate of the upper-left edge of the rectangle.</value>
52 public int Y { get; set; }
55 /// Gets or sets the width of the rectangle.
57 /// <value>The width of the rectangle.</value>
58 public int Width { get; set; }
61 /// Gets or sets the height of the rectangle.
63 /// <value>The height of the rectangle.</value>
64 public int Height { get; set; }
67 /// Gets the x-coordinate of the left edge of the rectangle.
69 /// <value>The x-coordinate of the left edge of the rectangle.</value>
73 /// Gets the y-coordinate of the top edge of the rectangle.
75 /// <value>The y-coordinate of the top edge of the rectangle.</value>
79 /// Gets the x-coordinate of the right edge of the rectangle.
81 /// <value>The x-coordinate of the right edge of the rectangle.</value>
82 public int Right => X + Width;
85 /// Gets the y-coordinate of the bottom edge of the rectangle.
87 /// <value>The y-coordinate of the bottom edge of the rectangle.</value>
88 public int Bottom => Y + Height;
91 /// Returns a string representation of the rectangle.
93 /// <returns>A string representation of the current rectangle.</returns>
94 public override string ToString() =>
95 $"X={X.ToString()}, Y={Y.ToString()}, Width={Width.ToString()}, Height={Height.ToString()}";
98 /// Returns the hash code for this rectangle structure.
100 /// <returns>An integer that represents the hash code for this rectangle.</returns>
101 public override int GetHashCode() => new { X, Y, Width, Height }.GetHashCode();
104 /// Tests whether object is a rectangle structure with the same location and size of this rectangle structure.
106 /// <param name="obj">The <see cref="Object"/> to compare.</param>
108 /// true if object is a rectangle structure and its x, y, width, and height properties are
109 /// equal to the corresponding properties of this rectangle structure; otherwise, false.
111 public override bool Equals(object obj) => obj is Rectangle && this == (Rectangle)obj;
114 /// Tests whether two rectangle structures have equal location and size.
116 /// <param name="rect1">The <see cref="Rectangle"/> to compare.</param>
117 /// <param name="rect2">The <see cref="Rectangle"/> to compare.</param>
118 /// <returns>true if the two rectangle structures have equal x, y, width, and height properties; otherwise, false.</returns>
119 public static bool operator ==(Rectangle rect1, Rectangle rect2)
120 => rect1.X == rect2.X && rect1.Y == rect2.Y && rect1.Width == rect2.Width && rect1.Height == rect2.Height;
123 /// Tests whether two rectangle structures differ in location or size.
125 /// <param name="rect1">The <see cref="Rectangle"/> to compare.</param>
126 /// <param name="rect2">The <see cref="Rectangle"/> to compare.</param>
127 /// <returns>true if any of the x, y, width, or height properties of the two rectangle structures are unequal; otherwise false.</returns>
128 public static bool operator !=(Rectangle rect1, Rectangle rect2) => !(rect1 == rect2);