Ensure some structs implement IEquatable<T>.
This commit is contained in:
@@ -15,7 +15,7 @@ using System.Drawing;
|
||||
namespace OpenRA
|
||||
{
|
||||
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Mimic a built-in type alias.")]
|
||||
public struct int2
|
||||
public struct int2 : IEquatable<int2>
|
||||
{
|
||||
public readonly int X, Y;
|
||||
public int2(int x, int y) { this.X = x; this.Y = y; }
|
||||
@@ -33,11 +33,17 @@ namespace OpenRA
|
||||
public static bool operator ==(int2 me, int2 other) { return me.X == other.X && me.Y == other.Y; }
|
||||
public static bool operator !=(int2 me, int2 other) { return !(me == other); }
|
||||
|
||||
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
|
||||
|
||||
public bool Equals(int2 other) { return this == other; }
|
||||
public override bool Equals(object obj) { return obj is int2 && Equals((int2)obj); }
|
||||
|
||||
public override string ToString() { return X + "," + Y; }
|
||||
|
||||
public int2 Sign() { return new int2(Math.Sign(X), Math.Sign(Y)); }
|
||||
public int2 Abs() { return new int2(Math.Abs(X), Math.Abs(Y)); }
|
||||
public int LengthSquared { get { return X * X + Y * Y; } }
|
||||
public int Length { get { return Exts.ISqrt(LengthSquared); } }
|
||||
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
|
||||
|
||||
public int2 WithX(int newX)
|
||||
{
|
||||
@@ -52,19 +58,11 @@ namespace OpenRA
|
||||
public static int2 Max(int2 a, int2 b) { return new int2(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); }
|
||||
public static int2 Min(int2 a, int2 b) { return new int2(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)); }
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
var o = obj as int2?;
|
||||
return o != null && o == this;
|
||||
}
|
||||
|
||||
public static readonly int2 Zero = new int2(0, 0);
|
||||
public Point ToPoint() { return new Point(X, Y); }
|
||||
public PointF ToPointF() { return new PointF(X, Y); }
|
||||
public float2 ToFloat2() { return new float2(X, Y); }
|
||||
|
||||
public override string ToString() { return "{0},{1}".F(X, Y); }
|
||||
|
||||
// Change endianness of a uint32
|
||||
public static uint Swap(uint orig)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user