Made int2 struct immutable

This commit is contained in:
David Jiménez
2015-01-30 22:30:27 +01:00
committed by Rydra
parent 8c4ea20636
commit f15f1e41e8
11 changed files with 34 additions and 26 deletions

View File

@@ -17,7 +17,7 @@ namespace OpenRA
[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1300:ElementMustBeginWithUpperCaseLetter", Justification = "Mimic a built-in type alias.")]
public struct int2
{
public int X, Y;
public readonly int X, Y;
public int2(int x, int y) { this.X = x; this.Y = y; }
public int2(Point p) { X = p.X; Y = p.Y; }
public int2(Size p) { X = p.Width; Y = p.Height; }
@@ -39,6 +39,16 @@ namespace OpenRA
public int Length { get { return Exts.ISqrt(LengthSquared); } }
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
public int2 WithX(int newX)
{
return new int2(newX, Y);
}
public int2 WithY(int newY)
{
return new int2(X, newY);
}
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)); }