using System;
using UnityEngine;

namespace mgaia.Utils
{
    /// <summary>
    /// Extensões de vetor
    /// </summary>
    /// <owner>Victor</owner>
    public static class VectorExtensions
    {
        /// <summary>
        /// Retorna a distância sem calcular a raiz quadrada
        /// </summary>
        public static float GetDistanceSquared(Vector2 v1, Vector2 v2)
        {
            return Mathf.Pow(v1.x - v2.x, 2) + Mathf.Pow(v1.y - v2.y, 2);
        }

        /// <summary>
        /// Retorna a distância sem calcular a raiz quadrada
        /// </summary>
        public static float GetDistanceSquared(Vector3 v1, Vector3 v2)
        {
            return Mathf.Pow(v1.x - v2.x, 2) + Mathf.Pow(v1.y - v2.y, 2) + Mathf.Pow(v1.z - v2.z, 2);
        }

        /// <summary>
        /// Retorna o ângulo do vetor em radianos
        /// </summary>
        public static float GetAngle(this Vector2 vector)
        {
            float velocityVector = Mathf.Sqrt(Mathf.Pow(vector.x, 2) + Mathf.Pow(vector.y, 2));
            float radiansAngle = Mathf.Acos(vector.x / velocityVector);

            return radiansAngle;
        }
    }
}