Advertisement
Mad_Joker

Vector2Extensions

Apr 27th, 2023
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 8.29 KB | None | 0 0
  1.     public static class Vector2Extensions
  2.     {
  3.         #region  BasicMath
  4.  
  5.        
  6.         /// <summary>
  7.         ///  (v.x + v.y) / 2;
  8.         /// </summary>
  9.         /// <param name="v"></param>
  10.         /// <returns></returns>
  11.         public static float AverageValues(this Vector2 v)
  12.             => (v.x + v.y) / 2;
  13.  
  14.        
  15.         /// <summary>
  16.         ///  v.x + v.y.
  17.         /// </summary>
  18.         /// <param name="v"></param>
  19.         /// <returns></returns>
  20.         public static float SumValues(this Vector2 v)
  21.             => v.x + v.y;
  22.  
  23.  
  24.        
  25.         /// <summary>
  26.         ///  v.x * v.y.
  27.         /// </summary>
  28.         /// <param name="v"></param>
  29.         /// <returns></returns>
  30.         public static float MultiplyValues(this Vector2 v)
  31.             => v.x * v.y;
  32.  
  33.  
  34.        
  35.         /// <summary>
  36.         ///  v.x / v.y.
  37.         /// </summary>
  38.         /// <param name="v"></param>
  39.         /// <returns></returns>
  40.         public static float DivideValues(this Vector2 v)
  41.             => v.x / v.y;
  42.  
  43.  
  44.        
  45.         /// <summary>
  46.         ///  v.x - v.y.
  47.         /// </summary>
  48.         /// <param name="v"></param>
  49.         /// <returns></returns>
  50.         public static float SubtractValues(this Vector2 v)
  51.             => v.x - v.y;
  52.  
  53.  
  54.        
  55.         /// <summary>
  56.         ///  Vector2(v1.x + v2.x, v1.y + v2.y).
  57.         /// </summary>
  58.         /// <param name="v1"></param>
  59.         /// <param name="v2"></param>
  60.         /// <returns></returns>
  61.         public static Vector2 AddToMe(this Vector2 v1, Vector2 v2)
  62.             => new Vector2(v1.x + v2.x, v1.y + v2.y);
  63.  
  64.  
  65.        
  66.         /// <summary>
  67.         ///  Vector2(v1.x - v2.x, v1.y - v2.y).
  68.         /// </summary>
  69.         /// <param name="v1"></param>
  70.         /// <param name="v2"></param>
  71.         /// <returns></returns>
  72.         public static Vector2 SubtractFromMe(this Vector2 v1, Vector2 v2)
  73.             => new Vector2(v1.x - v2.x, v1.y - v2.y);
  74.  
  75.  
  76.  
  77.        
  78.         /// <summary>
  79.         ///  Vector2(v1.x * v2.x, v1.y * v2.y).
  80.         /// </summary>
  81.         /// <param name="v1"></param>
  82.         /// <param name="v2"></param>
  83.         /// <returns></returns>
  84.         public static Vector2 MultiplyMe(this Vector2 v1, Vector2 v2)
  85.             => new Vector2(v1.x * v2.x, v1.y * v2.y);
  86.  
  87.  
  88.  
  89.        
  90.         /// <summary>
  91.         ///  Vector2(v1.x / v2.x, v1.y / v2.y).
  92.         /// </summary>
  93.         /// <param name="v1"></param>
  94.         /// <param name="v2"></param>
  95.         /// <returns></returns>
  96.         public static Vector2 DivideMeBy(this Vector2 v1, Vector2 v2)
  97.             => new Vector2(v1.x / v2.x, v1.y / v2.y);
  98.  
  99.         #endregion BasicMath
  100.  
  101.         # region MathfExtensions
  102.  
  103.  
  104.        
  105.         /// <summary>
  106.         /// Vector2(Mathf.Abs(vector2.x), Mathf.Abs(vector2.y)).
  107.         /// </summary>
  108.         /// <param name="vector2"></param>
  109.         /// <returns></returns>
  110.         public static Vector2 Abs(this Vector2 vector2)
  111.             => new Vector2(Mathf.Abs(vector2.x), Mathf.Abs(vector2.y));
  112.  
  113.  
  114.  
  115.        
  116.         /// <summary>
  117.         /// Vector2(Mathf.Acos(vector2.x), Mathf.Acos(vector2.y)).
  118.         /// </summary>
  119.         /// <param name="vector2"></param>
  120.         /// <returns></returns>
  121.         public static Vector2 Acos(this Vector2 vector2)
  122.             => new Vector2(Mathf.Acos(vector2.x), Mathf.Acos(vector2.y));
  123.  
  124.  
  125.        
  126.         /// <summary>
  127.         /// Vector2(Mathf.Asin(vector2.x), Mathf.Asin(vector2.y)).
  128.         /// </summary>
  129.         /// <param name="vector2"></param>
  130.         /// <returns></returns>
  131.         public static Vector2 Asin(this Vector2 vector2)
  132.             => new Vector2(Mathf.Asin(vector2.x), Mathf.Asin(vector2.y));
  133.  
  134.  
  135.  
  136.        
  137.         /// <summary>
  138.         /// Vector2(Mathf.Atan(vector2.x), Mathf.Abs(vector2.y)).
  139.         /// </summary>
  140.         /// <param name="vector2"></param>
  141.         /// <returns></returns>
  142.         public static Vector2 Atan(this Vector2 vector2)
  143.             => new Vector2(Mathf.Atan(vector2.x), Mathf.Abs(vector2.y));
  144.  
  145.  
  146.  
  147.        
  148.         /// <summary>
  149.         /// Vector2(Mathf.Ceil(vector2.x), Mathf.Ceil(vector2.y)).
  150.         /// </summary>
  151.         /// <param name="vector2"></param>
  152.         /// <returns></returns>
  153.         public static Vector2 Ceil(this Vector2 vector2)
  154.             => new Vector2(Mathf.Ceil(vector2.x), Mathf.Ceil(vector2.y));
  155.  
  156.  
  157.  
  158.        
  159.         /// <summary>
  160.         /// Vector2(Mathf.Clamp01(vector2.x), Mathf.Clamp01(vector2.y)).
  161.         /// </summary>
  162.         /// <param name="vector2"></param>
  163.         /// <returns></returns>
  164.         public static Vector2 Clamp01(this Vector2 vector2)
  165.             => new Vector2(Mathf.Clamp01(vector2.x), Mathf.Clamp01(vector2.y));
  166.  
  167.  
  168.        
  169.         /// <summary>
  170.         /// Vector2(Mathf.Cos(vector2.x), Mathf.Cos(vector2.y)).
  171.         /// </summary>
  172.         /// <param name="vector2"></param>
  173.         /// <returns></returns>
  174.         public static Vector2 Cos(this Vector2 vector2)
  175.             => new Vector2(Mathf.Cos(vector2.x), Mathf.Cos(vector2.y));
  176.  
  177.  
  178.        
  179.         /// <summary>
  180.         /// Vector2(Mathf.Exp(vector2.x), Mathf.Exp(vector2.y)).
  181.         /// </summary>
  182.         /// <param name="vector2"></param>
  183.         /// <returns></returns>
  184.         public static Vector2 Exp(this Vector2 vector2)
  185.             => new Vector2(Mathf.Exp(vector2.x), Mathf.Exp(vector2.y));
  186.  
  187.  
  188.        
  189.         /// <summary>
  190.         /// Vector2(Mathf.Floor(vector2.x), Mathf.Floor(vector2.y)).
  191.         /// </summary>
  192.         /// <param name="vector2"></param>
  193.         /// <returns></returns>
  194.         public static Vector2 Floor(this Vector2 vector2)
  195.             => new Vector2(Mathf.Floor(vector2.x), Mathf.Floor(vector2.y));
  196.  
  197.  
  198.  
  199.        
  200.         /// <summary>
  201.         /// Vector2(Mathf.Log10(vector2.x), Mathf.Log10(vector2.y)).
  202.         /// </summary>
  203.         /// <param name="vector2"></param>
  204.         /// <returns></returns>
  205.         public static Vector2 Log10(this Vector2 vector2)
  206.             => new Vector2(Mathf.Log10(vector2.x), Mathf.Log10(vector2.y));
  207.  
  208.  
  209.        
  210.         /// <summary>
  211.         ///  Mathf.Max(vector2.x, vector2.y).
  212.         /// </summary>
  213.         /// <param name="vector2"></param>
  214.         /// <returns></returns>
  215.         public static float Max(this Vector2 vector2)
  216.             => Mathf.Max(vector2.x, vector2.y);
  217.  
  218.  
  219.        
  220.         /// <summary>
  221.         ///  Mathf.Min(vector2.x, vector2.y).
  222.         /// </summary>
  223.         /// <param name="vector2"></param>
  224.         /// <returns></returns>
  225.         public static float Min(this Vector2 vector2)
  226.             => Mathf.Min(vector2.x, vector2.y);
  227.        
  228.  
  229.        
  230.         /// <summary>
  231.         /// Vector2(Mathf.Round(vector2.x), Mathf.Round(vector2.y)).
  232.         /// </summary>
  233.         /// <param name="vector2"></param>
  234.         /// <returns></returns>
  235.         public static Vector2 Round(this Vector2 vector2)
  236.             => new Vector2(Mathf.Round(vector2.x), Mathf.Round(vector2.y));
  237.  
  238.  
  239.        
  240.         /// <summary>
  241.         /// Vector2(Mathf.Sign(vector2.x), Mathf.Sign(vector2.y)).
  242.         /// </summary>
  243.         /// <param name="vector2"></param>
  244.         /// <returns></returns>
  245.         public static Vector2 Sign(this Vector2 vector2)
  246.             => new Vector2(Mathf.Sign(vector2.x), Mathf.Sign(vector2.y));
  247.  
  248.  
  249.        
  250.         /// <summary>
  251.         /// Vector2(Mathf.Sin(vector2.x), Mathf.Sin(vector2.y)).
  252.         /// </summary>
  253.         /// <param name="vector2"></param>
  254.         /// <returns></returns>
  255.         public static Vector2 Sin(this Vector2 vector2)
  256.             => new Vector2(Mathf.Sin(vector2.x), Mathf.Sin(vector2.y));
  257.  
  258.  
  259.        
  260.         /// <summary>
  261.         /// Vector2(Mathf.Sqrt(vector2.x), Mathf.Sqrt(vector2.y)).
  262.         /// </summary>
  263.         /// <param name="vector2"></param>
  264.         /// <returns></returns>
  265.         public static Vector2 Sqrt(this Vector2 vector2)
  266.             => new Vector2(Mathf.Sqrt(vector2.x), Mathf.Sqrt(vector2.y));
  267.  
  268.  
  269.        
  270.         /// <summary>
  271.         /// Vector2(Mathf.Tan(vector2.x), Mathf.Tan(vector2.y)).
  272.         /// </summary>
  273.         /// <param name="vector2"></param>
  274.         /// <returns></returns>
  275.         public static Vector2 Tan(this Vector2 vector2)
  276.             => new Vector2(Mathf.Tan(vector2.x), Mathf.Tan(vector2.y));
  277.  
  278.  
  279.         # endregion MathfExtensions
  280.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement