Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static class Vector2Extensions
- {
- #region BasicMath
- /// <summary>
- /// (v.x + v.y) / 2;
- /// </summary>
- /// <param name="v"></param>
- /// <returns></returns>
- public static float AverageValues(this Vector2 v)
- => (v.x + v.y) / 2;
- /// <summary>
- /// v.x + v.y.
- /// </summary>
- /// <param name="v"></param>
- /// <returns></returns>
- public static float SumValues(this Vector2 v)
- => v.x + v.y;
- /// <summary>
- /// v.x * v.y.
- /// </summary>
- /// <param name="v"></param>
- /// <returns></returns>
- public static float MultiplyValues(this Vector2 v)
- => v.x * v.y;
- /// <summary>
- /// v.x / v.y.
- /// </summary>
- /// <param name="v"></param>
- /// <returns></returns>
- public static float DivideValues(this Vector2 v)
- => v.x / v.y;
- /// <summary>
- /// v.x - v.y.
- /// </summary>
- /// <param name="v"></param>
- /// <returns></returns>
- public static float SubtractValues(this Vector2 v)
- => v.x - v.y;
- /// <summary>
- /// Vector2(v1.x + v2.x, v1.y + v2.y).
- /// </summary>
- /// <param name="v1"></param>
- /// <param name="v2"></param>
- /// <returns></returns>
- public static Vector2 AddToMe(this Vector2 v1, Vector2 v2)
- => new Vector2(v1.x + v2.x, v1.y + v2.y);
- /// <summary>
- /// Vector2(v1.x - v2.x, v1.y - v2.y).
- /// </summary>
- /// <param name="v1"></param>
- /// <param name="v2"></param>
- /// <returns></returns>
- public static Vector2 SubtractFromMe(this Vector2 v1, Vector2 v2)
- => new Vector2(v1.x - v2.x, v1.y - v2.y);
- /// <summary>
- /// Vector2(v1.x * v2.x, v1.y * v2.y).
- /// </summary>
- /// <param name="v1"></param>
- /// <param name="v2"></param>
- /// <returns></returns>
- public static Vector2 MultiplyMe(this Vector2 v1, Vector2 v2)
- => new Vector2(v1.x * v2.x, v1.y * v2.y);
- /// <summary>
- /// Vector2(v1.x / v2.x, v1.y / v2.y).
- /// </summary>
- /// <param name="v1"></param>
- /// <param name="v2"></param>
- /// <returns></returns>
- public static Vector2 DivideMeBy(this Vector2 v1, Vector2 v2)
- => new Vector2(v1.x / v2.x, v1.y / v2.y);
- #endregion BasicMath
- # region MathfExtensions
- /// <summary>
- /// Vector2(Mathf.Abs(vector2.x), Mathf.Abs(vector2.y)).
- /// </summary>
- /// <param name="vector2"></param>
- /// <returns></returns>
- public static Vector2 Abs(this Vector2 vector2)
- => new Vector2(Mathf.Abs(vector2.x), Mathf.Abs(vector2.y));
- /// <summary>
- /// Vector2(Mathf.Acos(vector2.x), Mathf.Acos(vector2.y)).
- /// </summary>
- /// <param name="vector2"></param>
- /// <returns></returns>
- public static Vector2 Acos(this Vector2 vector2)
- => new Vector2(Mathf.Acos(vector2.x), Mathf.Acos(vector2.y));
- /// <summary>
- /// Vector2(Mathf.Asin(vector2.x), Mathf.Asin(vector2.y)).
- /// </summary>
- /// <param name="vector2"></param>
- /// <returns></returns>
- public static Vector2 Asin(this Vector2 vector2)
- => new Vector2(Mathf.Asin(vector2.x), Mathf.Asin(vector2.y));
- /// <summary>
- /// Vector2(Mathf.Atan(vector2.x), Mathf.Abs(vector2.y)).
- /// </summary>
- /// <param name="vector2"></param>
- /// <returns></returns>
- public static Vector2 Atan(this Vector2 vector2)
- => new Vector2(Mathf.Atan(vector2.x), Mathf.Abs(vector2.y));
- /// <summary>
- /// Vector2(Mathf.Ceil(vector2.x), Mathf.Ceil(vector2.y)).
- /// </summary>
- /// <param name="vector2"></param>
- /// <returns></returns>
- public static Vector2 Ceil(this Vector2 vector2)
- => new Vector2(Mathf.Ceil(vector2.x), Mathf.Ceil(vector2.y));
- /// <summary>
- /// Vector2(Mathf.Clamp01(vector2.x), Mathf.Clamp01(vector2.y)).
- /// </summary>
- /// <param name="vector2"></param>
- /// <returns></returns>
- public static Vector2 Clamp01(this Vector2 vector2)
- => new Vector2(Mathf.Clamp01(vector2.x), Mathf.Clamp01(vector2.y));
- /// <summary>
- /// Vector2(Mathf.Cos(vector2.x), Mathf.Cos(vector2.y)).
- /// </summary>
- /// <param name="vector2"></param>
- /// <returns></returns>
- public static Vector2 Cos(this Vector2 vector2)
- => new Vector2(Mathf.Cos(vector2.x), Mathf.Cos(vector2.y));
- /// <summary>
- /// Vector2(Mathf.Exp(vector2.x), Mathf.Exp(vector2.y)).
- /// </summary>
- /// <param name="vector2"></param>
- /// <returns></returns>
- public static Vector2 Exp(this Vector2 vector2)
- => new Vector2(Mathf.Exp(vector2.x), Mathf.Exp(vector2.y));
- /// <summary>
- /// Vector2(Mathf.Floor(vector2.x), Mathf.Floor(vector2.y)).
- /// </summary>
- /// <param name="vector2"></param>
- /// <returns></returns>
- public static Vector2 Floor(this Vector2 vector2)
- => new Vector2(Mathf.Floor(vector2.x), Mathf.Floor(vector2.y));
- /// <summary>
- /// Vector2(Mathf.Log10(vector2.x), Mathf.Log10(vector2.y)).
- /// </summary>
- /// <param name="vector2"></param>
- /// <returns></returns>
- public static Vector2 Log10(this Vector2 vector2)
- => new Vector2(Mathf.Log10(vector2.x), Mathf.Log10(vector2.y));
- /// <summary>
- /// Mathf.Max(vector2.x, vector2.y).
- /// </summary>
- /// <param name="vector2"></param>
- /// <returns></returns>
- public static float Max(this Vector2 vector2)
- => Mathf.Max(vector2.x, vector2.y);
- /// <summary>
- /// Mathf.Min(vector2.x, vector2.y).
- /// </summary>
- /// <param name="vector2"></param>
- /// <returns></returns>
- public static float Min(this Vector2 vector2)
- => Mathf.Min(vector2.x, vector2.y);
- /// <summary>
- /// Vector2(Mathf.Round(vector2.x), Mathf.Round(vector2.y)).
- /// </summary>
- /// <param name="vector2"></param>
- /// <returns></returns>
- public static Vector2 Round(this Vector2 vector2)
- => new Vector2(Mathf.Round(vector2.x), Mathf.Round(vector2.y));
- /// <summary>
- /// Vector2(Mathf.Sign(vector2.x), Mathf.Sign(vector2.y)).
- /// </summary>
- /// <param name="vector2"></param>
- /// <returns></returns>
- public static Vector2 Sign(this Vector2 vector2)
- => new Vector2(Mathf.Sign(vector2.x), Mathf.Sign(vector2.y));
- /// <summary>
- /// Vector2(Mathf.Sin(vector2.x), Mathf.Sin(vector2.y)).
- /// </summary>
- /// <param name="vector2"></param>
- /// <returns></returns>
- public static Vector2 Sin(this Vector2 vector2)
- => new Vector2(Mathf.Sin(vector2.x), Mathf.Sin(vector2.y));
- /// <summary>
- /// Vector2(Mathf.Sqrt(vector2.x), Mathf.Sqrt(vector2.y)).
- /// </summary>
- /// <param name="vector2"></param>
- /// <returns></returns>
- public static Vector2 Sqrt(this Vector2 vector2)
- => new Vector2(Mathf.Sqrt(vector2.x), Mathf.Sqrt(vector2.y));
- /// <summary>
- /// Vector2(Mathf.Tan(vector2.x), Mathf.Tan(vector2.y)).
- /// </summary>
- /// <param name="vector2"></param>
- /// <returns></returns>
- public static Vector2 Tan(this Vector2 vector2)
- => new Vector2(Mathf.Tan(vector2.x), Mathf.Tan(vector2.y));
- # endregion MathfExtensions
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement