using System;
using System.Globalization;
using System.Linq;

namespace Mox.Shared.Math
{
	public class Rect : IEquatable<Rect>
	{
		public Rect(int _iLeft, int _iTop, int _iWidth, int _iHeight)
		{
			Left = _iLeft;
			Top = _iTop;
			Width = _iWidth;
			Height = _iHeight;
		}

		public override string ToString()
		{
			return string.Join(", ", (new [] { Left, Top, Width, Height}).Select(c => c.ToString()));
		}

		public int Left;
		public int Top;
		public int Width;
		public int Height;

		public bool Equals(Rect other)
		{
			if (ReferenceEquals(null, other))
			{
				return false;
			}

			if (ReferenceEquals(this, other))
			{
				return true;
			}

			return Left == other.Left && Top == other.Top && Width == other.Width && Height == other.Height;
		}

		public override bool Equals(object obj)
		{
			if (ReferenceEquals(null, obj))
			{
				return false;
			}

			if (ReferenceEquals(this, obj))
			{
				return true;
			}

			if (obj.GetType() != GetType())
			{
				return false;
			}

			return Equals((Rect) obj);
		}

		public override int GetHashCode()
		{
			unchecked
			{
				var hashCode = Left;
				hashCode = (hashCode * 397) ^ Top;
				hashCode = (hashCode * 397) ^ Width;
				hashCode = (hashCode * 397) ^ Height;

				return hashCode;
			}
		}
	}
}
