/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
namespace Tizen.Multimedia
{
///
/// Represents the location of the object bounded by a rectangle defined by
/// coordinates of top left corner, width and height.
///
public struct Rectangle
{
private Point _location;
private Size _size;
///
/// Initializes a new instance of the with the specified values.
///
/// The x-coordinate of the upper-left corner of the rectangle.
/// The y-coordinate of the upper-left corner of the rectangle.
/// The Width of the rectangle.
/// The Height of the rectangle.
public Rectangle(int x, int y, int width, int height) : this(new Point(x, y),
new Size(width, height))
{
}
///
/// Initializes a new instance of the with the specified values.
///
/// A that represents the upper-left corner of the rectangular region.
/// A that represents the width and height of the rectangular region.
public Rectangle(Point location, Size size)
{
_location = location;
_size = size;
}
///
/// Gets or sets the coordinates of the upper-left corner of the rectangle.
///
public Point Location
{
get { return _location; }
set { _location = value; }
}
///
/// Gets or sets the x-coordinate of the upper-left corner of the rectangle.
///
public int X
{
get { return _location.X; }
set { _location.X = value; }
}
///
/// Gets or sets the y-coordinate of the upper-left corner of the rectangle.
///
public int Y
{
get { return _location.Y; }
set { _location.Y = value; }
}
///
/// Gets or sets the width of the rectangle.
///
public int Width
{
get { return _size.Width; }
set { _size.Width = value; }
}
///
/// Gets or sets the height of the rectangle.
///
public int Height
{
get { return _size.Height; }
set { _size.Height = value; }
}
///
/// Gets the x-coordinate of the left edge of the rectangle.
///
public int Left => X;
///
/// Gets the y-coordinate of the top edge of the rectangle.
///
public int Top => Y;
///
/// Gets the x-coordinate of the right edge of the rectangle.
///
public int Right => X + Width;
///
/// Gets the y-coordinate of the bottom edge of the rectangle.
///
public int Bottom => Y + Height;
///
/// Gets or sets the size of the rectangle.
///
public Size Size
{
get { return _size; }
set { _size = value; }
}
///
/// Returns a string that represents the current object.
///
/// A string that represents the current object.
public override string ToString() => $"{_location.ToString()}, {_size.ToString()}";
///
/// Gets the hash code for this instance of .
///
/// The hash code for this instance of .
public override int GetHashCode()
{
return new { Location, Size }.GetHashCode();
}
///
/// Compares an object to an instance of for equality.
///
/// A to compare.
/// true if the rectangles are equal; otherwise, false.
public override bool Equals(object obj)
{
return obj is Rectangle && this == (Rectangle)obj;
}
///
/// Compares two instances of for equality.
///
/// A to compare.
/// A to compare.
/// true if the two instances of are equal; otherwise false.
public static bool operator ==(Rectangle rect1, Rectangle rect2)
{
return rect1.Location == rect2.Location && rect1.Size == rect2.Size;
}
///
/// Compares two instances of for inequality.
///
/// A to compare.
/// A to compare.
/// true if the two instances of are not equal; otherwise false.
public static bool operator !=(Rectangle rect1, Rectangle rect2)
{
return !(rect1 == rect2);
}
}
}