Release 4.0.0-preview1-00172
[platform/core/csapi/tizenfx.git] / src / Tizen.Content.MediaContent / Tizen.Content.MediaContent / Rectangle.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18
19 namespace Tizen.Content.MediaContent
20 {
21     /// <summary>
22     /// Represents the location of the object bounded by the rectangle defined by
23     /// coordinates of top left corner, width, and height.
24     /// </summary>
25     public struct Rectangle
26     {
27         /// <summary>
28         /// Initializes a new instance of the rectangle with the specified values.
29         /// </summary>
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)
35         {
36             X = x;
37             Y = y;
38             Width = width;
39             Height = height;
40         }
41
42         /// <summary>
43         /// Gets or sets the x-coordinate of the upper-left corner of the rectangle.
44         /// </summary>
45         /// <value>The x-coordinate of the upper-left edge of the rectangle.</value>
46         public int X { get; set; }
47
48         /// <summary>
49         /// Gets or sets the y-coordinate of the upper-left corner of the rectangle.
50         /// </summary>
51         /// <value>The y-coordinate of the upper-left edge of the rectangle.</value>
52         public int Y { get; set; }
53
54         /// <summary>
55         /// Gets or sets the width of the rectangle.
56         /// </summary>
57         /// <value>The width of the rectangle.</value>
58         public int Width { get; set; }
59
60         /// <summary>
61         /// Gets or sets the height of the rectangle.
62         /// </summary>
63         /// <value>The height of the rectangle.</value>
64         public int Height { get; set; }
65
66         /// <summary>
67         /// Gets the x-coordinate of the left edge of the rectangle.
68         /// </summary>
69         /// <value>The x-coordinate of the left edge of the rectangle.</value>
70         public int Left => X;
71
72         /// <summary>
73         /// Gets the y-coordinate of the top edge of the rectangle.
74         /// </summary>
75         /// <value>The y-coordinate of the top edge of the rectangle.</value>
76         public int Top => Y;
77
78         /// <summary>
79         /// Gets the x-coordinate of the right edge of the rectangle.
80         /// </summary>
81         /// <value>The x-coordinate of the right edge of the rectangle.</value>
82         public int Right => X + Width;
83
84         /// <summary>
85         /// Gets the y-coordinate of the bottom edge of the rectangle.
86         /// </summary>
87         /// <value>The y-coordinate of the bottom edge of the rectangle.</value>
88         public int Bottom => Y + Height;
89
90         /// <summary>
91         /// Returns a string representation of the rectangle.
92         /// </summary>
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()}";
96
97         /// <summary>
98         /// Returns the hash code for this rectangle structure.
99         /// </summary>
100         /// <returns>An integer that represents the hash code for this rectangle.</returns>
101         public override int GetHashCode() => new { X, Y, Width, Height }.GetHashCode();
102
103         /// <summary>
104         /// Tests whether object is a rectangle structure with the same location and size of this rectangle structure.
105         /// </summary>
106         /// <param name="obj">The <see cref="Object"/> to compare.</param>
107         /// <returns>
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.
110         /// </returns>
111         public override bool Equals(object obj) => obj is Rectangle && this == (Rectangle)obj;
112
113         /// <summary>
114         /// Tests whether two rectangle structures have equal location and size.
115         /// </summary>
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;
121
122         /// <summary>
123         /// Tests whether two rectangle structures differ in location or size.
124         /// </summary>
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);
129     }
130 }