using UnityEngine;
using System.Collections;

public class GridPos {
	private int x;
	private int y;

	public GridPos() {
		x = -1;
		y = -1;
	}

	public GridPos(int x, int y) {
		this.x = x;
		this.y = y;
	}

	public GridPos(Vector3 pos) {
		if (pos.x < 0.0f || pos.y < 0.0f) {
			x = -1;
			y = -1;
		}
		else {
			x = (int)pos.x;
			y = (int)pos.y;
		}
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public bool isValid() {
		return x >= 0 && y >= 0;
	}

	public Vector3 getWorldPosition() {
		return new Vector3(x + 0.5f, y + 0.5f, 0.0f);
	}

	public float distanceSquared(GridPos other) {
		float dx = x - other.x;
		float dy = y - other.y;
		return dx * dx + dy * dy;
	}

	public float distance(GridPos other) {
		return Mathf.Sqrt(distanceSquared(other));
	}

	public bool equals(GridPos other) {
		return x == other.x && y == other.y;
	}
}
