using System;
using UnityEngine;

[Serializable]
public struct Vector2I
{

    public int x;
    public int y;

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

    public static Vector2I operator +(Vector2I v1, Vector2I v2)
    {
        return new Vector2I(v1.x + v2.x, v1.y + v2.y);
    }

    public static Vector2I operator -(Vector2I v1, Vector2I v2)
    {
        return new Vector2I(v1.x - v2.x, v1.y - v2.y);
    }

    public void Normalize()
    {
        float length = Magnitude();
        x = (int)Math.Round(x / length);
        y = (int)Math.Round(y / length);
    }

    public float Magnitude()
    {
        return Mathf.Sqrt(x * x + y * y);
    }

    public static explicit operator Vector2(Vector2I v1)
    {
        return new Vector2(v1.x, v1.y);
    }

    public override string ToString()
    {
        return "Vector2I(" + x + ", " + y + ")";
    }

}
