Release 4.0.0-preview1-00201
[platform/core/csapi/tizenfx.git] / src / Tizen.Multimedia / Common / 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.Multimedia
20 {
21     /// <summary>
22     /// Represents the location of the object bounded by a rectangle defined by
23     /// coordinates of top left corner, width and height.
24     /// </summary>
25     public struct Rectangle
26     {
27         private Point _location;
28         private Size _size;
29
30         /// <summary>
31         /// Initializes a new instance of the <see cref="Rectangle"/> with the specified values.
32         /// </summary>
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))
39         {
40         }
41
42         /// <summary>
43         /// Initializes a new instance of the <see cref="Rectangle"/> with the specified values.
44         /// </summary>
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)
48         {
49             _location = location;
50             _size = size;
51         }
52
53         /// <summary>
54         /// Gets or sets the coordinates of the upper-left corner of the rectangle.
55         /// </summary>
56         public Point Location
57         {
58             get { return _location; }
59             set { _location = value; }
60         }
61
62         /// <summary>
63         /// Gets or sets the x-coordinate of the upper-left corner of the rectangle.
64         /// </summary>
65         public int X
66         {
67             get { return _location.X; }
68             set { _location.X = value; }
69         }
70
71         /// <summary>
72         /// Gets or sets the y-coordinate of the upper-left corner of the rectangle.
73         /// </summary>
74         public int Y
75         {
76             get { return _location.Y; }
77             set { _location.Y = value; }
78         }
79
80         /// <summary>
81         /// Gets or sets the width of the rectangle.
82         /// </summary>
83         public int Width
84         {
85             get { return _size.Width; }
86             set { _size.Width = value; }
87         }
88
89         /// <summary>
90         /// Gets or sets the height of the rectangle.
91         /// </summary>
92         public int Height
93         {
94             get { return _size.Height; }
95             set { _size.Height = value; }
96         }
97
98         /// <summary>
99         /// Gets the x-coordinate of the left edge of the rectangle.
100         /// </summary>
101         public int Left => X;
102
103         /// <summary>
104         /// Gets the y-coordinate of the top edge of the rectangle.
105         /// </summary>
106         public int Top => Y;
107
108         /// <summary>
109         /// Gets the x-coordinate of the right edge of the rectangle.
110         /// </summary>
111         public int Right => X + Width;
112
113         /// <summary>
114         /// Gets the y-coordinate of the bottom edge of the rectangle.
115         /// </summary>
116         public int Bottom => Y + Height;
117
118         /// <summary>
119         /// Gets or sets the size of the rectangle.
120         /// </summary>
121         public Size Size
122         {
123             get { return _size; }
124             set { _size = value; }
125         }
126
127         /// <summary>
128         /// Returns a string that represents the current object.
129         /// </summary>
130         /// <returns>A string that represents the current object.</returns>
131         public override string ToString() => $"{_location.ToString()}, {_size.ToString()}";
132
133         /// <summary>
134         /// Gets the hash code for this instance of <see cref="Rectangle"/>.
135         /// </summary>
136         /// <returns>The hash code for this instance of <see cref="Rectangle"/>.</returns>
137         public override int GetHashCode()
138         {
139             return new { Location, Size }.GetHashCode();
140         }
141
142         /// <summary>
143         /// Compares an object to an instance of <see cref="Rectangle"/> for equality.
144         /// </summary>
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)
148         {
149             return obj is Rectangle && this == (Rectangle)obj;
150         }
151
152         /// <summary>
153         /// Compares two instances of <see cref="Rectangle"/> for equality.
154         /// </summary>
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)
159         {
160             return rect1.Location == rect2.Location && rect1.Size == rect2.Size;
161         }
162
163         /// <summary>
164         /// Compares two instances of <see cref="Rectangle"/> for inequality.
165         /// </summary>
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)
170         {
171             return !(rect1 == rect2);
172         }
173     }
174 }