#region License
/* FNA - XNA4 Reimplementation for Desktop Platforms
* Copyright 2009-2016 Ethan Lee and the MonoGame Team
*
* Released under the Microsoft Public License.
* See LICENSE for details.
*/
/* Derived from code by the Mono.Xna Team (Copyright 2006).
* Released under the MIT License. See monoxna.LICENSE for details.
*/
#endregion
#region Using Statements
using System;
using System.Diagnostics;
using System.ComponentModel;
using Microsoft.Xna.Framework.Design;
#endregion
namespace Microsoft.Xna.Framework
{
///
/// Describes a 2D-point.
///
[Serializable]
[TypeConverter(typeof(PointConverter))]
[DebuggerDisplay("{DebugDisplayString,nq}")]
public struct Point : IEquatable
{
#region Public Static Properties
///
/// Returns a with coordinates 0, 0.
///
public static Point Zero
{
get
{
return zeroPoint;
}
}
#endregion
#region Internal Properties
internal string DebugDisplayString
{
get
{
return string.Concat(
X.ToString(), " ",
Y.ToString()
);
}
}
#endregion
#region Public Fields
///
/// The x coordinate of this .
///
public int X;
///
/// The y coordinate of this .
///
public int Y;
#endregion
#region Private Static Variables
private static readonly Point zeroPoint = new Point();
#endregion
#region Public Constructors
///
/// Constructs a point with X and Y from two values.
///
/// The x coordinate in 2d-space.
/// The y coordinate in 2d-space.
public Point(int x, int y)
{
this.X = x;
this.Y = y;
}
#endregion
#region Public Methods
///
/// Compares whether current instance is equal to specified .
///
/// The to compare.
/// true if the instances are equal; false otherwise.
public bool Equals(Point other)
{
return ((X == other.X) && (Y == other.Y));
}
///
/// Compares whether current instance is equal to specified .
///
/// The to compare.
/// true if the instances are equal; false otherwise.
public override bool Equals(object obj)
{
return (obj is Point) && Equals((Point) obj);
}
///
/// Gets the hash code of this .
///
/// Hash code of this .
public override int GetHashCode()
{
return X ^ Y;
}
///
/// Returns a representation of this in the format:
/// {X:[] Y:[]}
///
/// representation of this .
public override string ToString()
{
return (
"{X:" + X.ToString() +
" Y:" + Y.ToString() +
"}"
);
}
#endregion
#region Public Static Operators
///
/// Adds two points.
///
/// Source on the left of the add sign.
/// Source on the right of the add sign.
/// Sum of the points.
public static Point operator +(Point value1, Point value2)
{
return new Point(value1.X + value2.X, value1.Y + value2.Y);
}
///
/// Subtracts a from a .
///
/// Source on the left of the sub sign.
/// Source on the right of the sub sign.
/// Result of the subtraction.
public static Point operator -(Point value1, Point value2)
{
return new Point(value1.X - value2.X, value1.Y - value2.Y);
}
///
/// Multiplies the components of two points by each other.
///
/// Source on the left of the mul sign.
/// Source on the right of the mul sign.
/// Result of the multiplication.
public static Point operator *(Point value1, Point value2)
{
return new Point(value1.X * value2.X, value1.Y * value2.Y);
}
///
/// Divides the components of a by the components of another .
///
/// Source on the left of the div sign.
/// Divisor on the right of the div sign.
/// The result of dividing the points.
public static Point operator /(Point value1, Point value2)
{
return new Point(value1.X / value2.X, value1.Y / value2.Y);
}
///
/// Compares whether two instances are equal.
///
/// instance on the left of the equal sign.
/// instance on the right of the equal sign.
/// true if the instances are equal; false otherwise.
public static bool operator ==(Point a, Point b)
{
return a.Equals(b);
}
///
/// Compares whether two instances are not equal.
///
/// instance on the left of the not equal sign.
/// instance on the right of the not equal sign.
/// true if the instances are not equal; false otherwise.
public static bool operator !=(Point a, Point b)
{
return !a.Equals(b);
}
#endregion
}
}