1 #region Copyright & License Information 2 /* 3 * Copyright 2007-2020 The OpenRA Developers (see AUTHORS) 4 * This file is part of OpenRA, which is free software. It is made 5 * available to you under the terms of the GNU General Public License 6 * as published by the Free Software Foundation, either version 3 of 7 * the License, or (at your option) any later version. For more 8 * information, see COPYING. 9 */ 10 #endregion 11 12 using System; 13 14 namespace OpenRA.Primitives 15 { 16 public struct Size : IEquatable<Size> 17 { 18 public readonly int Width; 19 public readonly int Height; 20 operator +OpenRA.Primitives.Size21 public static Size operator +(Size left, Size right) 22 { 23 return new Size(left.Width + right.Width, left.Height + right.Height); 24 } 25 operator ==OpenRA.Primitives.Size26 public static bool operator ==(Size left, Size right) 27 { 28 return left.Width == right.Width && left.Height == right.Height; 29 } 30 operator !=OpenRA.Primitives.Size31 public static bool operator !=(Size left, Size right) 32 { 33 return !(left == right); 34 } 35 operator -OpenRA.Primitives.Size36 public static Size operator -(Size sz1, Size sz2) 37 { 38 return new Size(sz1.Width - sz2.Width, sz1.Height - sz2.Height); 39 } 40 SizeOpenRA.Primitives.Size41 public Size(int width, int height) 42 { 43 Width = width; 44 Height = height; 45 } 46 47 public bool IsEmpty { get { return Width == 0 && Height == 0; } } 48 EqualsOpenRA.Primitives.Size49 public bool Equals(Size other) 50 { 51 return this == other; 52 } 53 EqualsOpenRA.Primitives.Size54 public override bool Equals(object obj) 55 { 56 if (!(obj is Size)) 57 return false; 58 59 return this == (Size)obj; 60 } 61 GetHashCodeOpenRA.Primitives.Size62 public override int GetHashCode() 63 { 64 return Width ^ Height; 65 } 66 ToStringOpenRA.Primitives.Size67 public override string ToString() 68 { 69 return string.Format("{{Width={0}, Height={1}}}", Width, Height); 70 } 71 } 72 } 73