#region License
//
// The Open Toolkit Library License
//
// Copyright (c) 2006 - 2009 the Open Toolkit library.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights to
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
// the Software, and to permit persons to whom the Software is furnished to do
// so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
#endregion
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenTK
{
///
/// Defines a point on a two-dimensional plane.
///
public struct Point : IEquatable
{
#region Fields
int x, y;
#endregion
#region Constructors
///
/// Constructs a new Point instance.
///
/// The X coordinate of this instance.
/// The Y coordinate of this instance.
public Point(int x, int y)
: this()
{
X = x;
Y = y;
}
#endregion
#region Public Members
///
/// Gets a that indicates whether this instance is empty or zero.
///
public bool IsEmpty { get { return X == 0 && Y == 0; } }
///
/// Gets or sets the X coordinate of this instance.
///
public int X { get { return x; } set { x = value; } }
///
/// Gets or sets the Y coordinate of this instance.
///
public int Y { get { return y; } set { y = value; } }
///
/// Returns the Point (0, 0).
///
public static readonly Point Zero = new Point();
///
/// Returns the Point (0, 0).
///
public static readonly Point Empty = new Point();
///
/// Translates the specified Point by the specified Size.
///
///
/// The instance to translate.
///
///
/// The instance to translate point with.
///
///
/// A new instance translated by size.
///
public static Point operator +(Point point, Size size)
{
return new Point(point.X + size.Width, point.Y + size.Height);
}
///
/// Translates the specified Point by the negative of the specified Size.
///
///
/// The instance to translate.
///
///
/// The instance to translate point with.
///
///
/// A new instance translated by size.
///
public static Point operator -(Point point, Size size)
{
return new Point(point.X - size.Width, point.Y - size.Height);
}
///
/// Compares two instances for equality.
///
/// The first instance.
/// The second instance.
/// True, if left is equal to right; false otherwise.
public static bool operator ==(Point left, Point right)
{
return left.Equals(right);
}
///
/// Compares two instances for inequality.
///
/// The first instance.
/// The second instance.
/// True, if left is not equal to right; false otherwise.
public static bool operator !=(Point left, Point right)
{
return !left.Equals(right);
}
///
/// Converts an OpenTK.Point instance to a System.Drawing.Point.
///
///
/// The instance to convert.
///
///
/// A instance equivalent to point.
///
public static implicit operator System.Drawing.Point(Point point)
{
return new System.Drawing.Point(point.X, point.Y);
}
///
/// Converts a System.Drawing.Point instance to an OpenTK.Point.
///
///
/// The instance to convert.
///
///
/// A instance equivalent to point.
///
public static implicit operator Point(System.Drawing.Point point)
{
return new Point(point.X, point.Y);
}
///
/// Converts an OpenTK.Point instance to a System.Drawing.PointF.
///
///
/// The instance to convert.
///
///
/// A instance equivalent to point.
///
public static implicit operator System.Drawing.PointF(Point point)
{
return new System.Drawing.PointF(point.X, point.Y);
}
///
/// Indicates whether this instance is equal to the specified object.
///
/// The object instance to compare to.
/// True, if both instances are equal; false otherwise.
public override bool Equals(object obj)
{
if (obj is Point)
return Equals((Point)obj);
return false;
}
///
/// Returns the hash code for this instance.
///
/// A that represents the hash code for this instance./>
public override int GetHashCode()
{
return X.GetHashCode() ^ Y.GetHashCode();
}
///
/// Returns a that describes this instance.
///
/// A that describes this instance.
public override string ToString()
{
return String.Format("{{{0}, {1}}}", X, Y);
}
#endregion
#region IEquatable Members
///
/// Indicates whether this instance is equal to the specified Point.
///
/// The instance to compare to.
/// True, if both instances are equal; false otherwise.
public bool Equals(Point other)
{
return X == other.X && Y == other.Y;
}
#endregion
}
}