using UnityEngine;
using System;
using System.Collections;

[Serializable]
public struct IntVector3
{
	public IntVector3(int x, int y, int z)
	{
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	public IntVector3(Vector3 position)
	{
		this.x = (int)Mathf.Floor(position.x);
		this.y = (int)Mathf.Floor(position.y);
		this.z = (int)Mathf.Floor(position.z);
	}
	
	public override bool Equals(object o)
	{
		if(o is IntVector3)
		{
			return (IntVector3)o == this;
		}
		return false;
	}
	
	public override int GetHashCode()
	{
		return x.GetHashCode() ^ y.GetHashCode() ^ z.GetHashCode();
	}
	
	public static IntVector3 operator +(IntVector3 a, IntVector3 b)
	{
		return new IntVector3(a.x + b.x, a.y + b.y, a.z + b.z);
	}

	public static IntVector3 operator -(IntVector3 a, IntVector3 b)
	{
		return new IntVector3(a.x - b.x, a.y - b.y, a.z - b.z);
	}

	public static IntVector3 operator *(IntVector3 a, int b)
	{
		return new IntVector3(a.x * b, a.y * b, a.z * b);
	}
	
	public static bool operator ==(IntVector3 a, IntVector3 b)
	{
		return a.x == b.x && a.y == b.y && a.z == b.z;
	}

	public static bool operator !=(IntVector3 a, IntVector3 b)
	{
		return a.x != b.x || a.y != b.y || a.z != b.z;
	}

	public int x;
	public int y;
	public int z;
	
	public override string ToString()
	{
		return "(" + x + ", " + y + ", " + z + ")";
	}
	
	public Vector3 ToVector3()
	{
		return new Vector3(x, y, z);
	}
	
	public Vector3 GetBlockMidpoint()
	{
		return new Vector3(x + 0.5f, y + 0.5f, z + 0.5f);
	}
}
