Advertisement
Deathmax

Untitled

Jun 2nd, 2011
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 22.11 KB | None | 0 0
  1.     public struct Vector2 : IEquatable<Vector2>
  2.     {
  3.         public float X;
  4.         public float Y;
  5.         private static Vector2 _zero = default(Vector2);
  6.         private static Vector2 _one = new Vector2(1f, 1f);
  7.         private static Vector2 _unitX = new Vector2(1f, 0f);
  8.         private static Vector2 _unitY = new Vector2(0f, 1f);
  9.         public static Vector2 Zero
  10.         {
  11.             get
  12.             {
  13.                 return Vector2._zero;
  14.             }
  15.         }
  16.         public static Vector2 One
  17.         {
  18.             get
  19.             {
  20.                 return Vector2._one;
  21.             }
  22.         }
  23.         public static Vector2 UnitX
  24.         {
  25.             get
  26.             {
  27.                 return Vector2._unitX;
  28.             }
  29.         }
  30.         public static Vector2 UnitY
  31.         {
  32.             get
  33.             {
  34.                 return Vector2._unitY;
  35.             }
  36.         }
  37.         public Vector2(float x, float y)
  38.         {
  39.             this.X = x;
  40.             this.Y = y;
  41.         }
  42.         public Vector2(float value)
  43.         {
  44.             this.Y = value;
  45.             this.X = value;
  46.         }
  47.         public override string ToString()
  48.         {
  49.             CultureInfo currentCulture = CultureInfo.CurrentCulture;
  50.             return string.Format(currentCulture, "{{X:{0} Y:{1}}}", new object[]
  51.             {
  52.                 this.X.ToString(currentCulture),
  53.                 this.Y.ToString(currentCulture)
  54.             });
  55.         }
  56.         public bool Equals(Vector2 other)
  57.         {
  58.             return this.X == other.X && this.Y == other.Y;
  59.         }
  60.         public override bool Equals(object obj)
  61.         {
  62.             bool result = false;
  63.             if (obj is Vector2)
  64.             {
  65.                 result = this.Equals((Vector2)obj);
  66.             }
  67.             return result;
  68.         }
  69.         public override int GetHashCode()
  70.         {
  71.             return this.X.GetHashCode() + this.Y.GetHashCode();
  72.         }
  73.         public float Length()
  74.         {
  75.             float num = this.X * this.X + this.Y * this.Y;
  76.             return (float)Math.Sqrt((double)num);
  77.         }
  78.         public float LengthSquared()
  79.         {
  80.             return this.X * this.X + this.Y * this.Y;
  81.         }
  82.         public static float Distance(Vector2 value1, Vector2 value2)
  83.         {
  84.             float num = value1.X - value2.X;
  85.             float num2 = value1.Y - value2.Y;
  86.             float num3 = num * num + num2 * num2;
  87.             return (float)Math.Sqrt((double)num3);
  88.         }
  89.         public static void Distance(ref Vector2 value1, ref Vector2 value2, out float result)
  90.         {
  91.             float num = value1.X - value2.X;
  92.             float num2 = value1.Y - value2.Y;
  93.             float num3 = num * num + num2 * num2;
  94.             result = (float)Math.Sqrt((double)num3);
  95.         }
  96.         public static float DistanceSquared(Vector2 value1, Vector2 value2)
  97.         {
  98.             float num = value1.X - value2.X;
  99.             float num2 = value1.Y - value2.Y;
  100.             return num * num + num2 * num2;
  101.         }
  102.         public static void DistanceSquared(ref Vector2 value1, ref Vector2 value2, out float result)
  103.         {
  104.             float num = value1.X - value2.X;
  105.             float num2 = value1.Y - value2.Y;
  106.             result = num * num + num2 * num2;
  107.         }
  108.         public static float Dot(Vector2 value1, Vector2 value2)
  109.         {
  110.             return value1.X * value2.X + value1.Y * value2.Y;
  111.         }
  112.         public static void Dot(ref Vector2 value1, ref Vector2 value2, out float result)
  113.         {
  114.             result = value1.X * value2.X + value1.Y * value2.Y;
  115.         }
  116.         public void Normalize()
  117.         {
  118.             float num = this.X * this.X + this.Y * this.Y;
  119.             float num2 = 1f / (float)Math.Sqrt((double)num);
  120.             this.X *= num2;
  121.             this.Y *= num2;
  122.         }
  123.         public static Vector2 Normalize(Vector2 value)
  124.         {
  125.             float num = value.X * value.X + value.Y * value.Y;
  126.             float num2 = 1f / (float)Math.Sqrt((double)num);
  127.             Vector2 result;
  128.             result.X = value.X * num2;
  129.             result.Y = value.Y * num2;
  130.             return result;
  131.         }
  132.         public static void Normalize(ref Vector2 value, out Vector2 result)
  133.         {
  134.             float num = value.X * value.X + value.Y * value.Y;
  135.             float num2 = 1f / (float)Math.Sqrt((double)num);
  136.             result.X = value.X * num2;
  137.             result.Y = value.Y * num2;
  138.         }
  139.         public static Vector2 Reflect(Vector2 vector, Vector2 normal)
  140.         {
  141.             float num = vector.X * normal.X + vector.Y * normal.Y;
  142.             Vector2 result;
  143.             result.X = vector.X - 2f * num * normal.X;
  144.             result.Y = vector.Y - 2f * num * normal.Y;
  145.             return result;
  146.         }
  147.         public static void Reflect(ref Vector2 vector, ref Vector2 normal, out Vector2 result)
  148.         {
  149.             float num = vector.X * normal.X + vector.Y * normal.Y;
  150.             result.X = vector.X - 2f * num * normal.X;
  151.             result.Y = vector.Y - 2f * num * normal.Y;
  152.         }
  153.         public static Vector2 Min(Vector2 value1, Vector2 value2)
  154.         {
  155.             Vector2 result;
  156.             result.X = ((value1.X < value2.X) ? value1.X : value2.X);
  157.             result.Y = ((value1.Y < value2.Y) ? value1.Y : value2.Y);
  158.             return result;
  159.         }
  160.         public static void Min(ref Vector2 value1, ref Vector2 value2, out Vector2 result)
  161.         {
  162.             result.X = ((value1.X < value2.X) ? value1.X : value2.X);
  163.             result.Y = ((value1.Y < value2.Y) ? value1.Y : value2.Y);
  164.         }
  165.         public static Vector2 Max(Vector2 value1, Vector2 value2)
  166.         {
  167.             Vector2 result;
  168.             result.X = ((value1.X > value2.X) ? value1.X : value2.X);
  169.             result.Y = ((value1.Y > value2.Y) ? value1.Y : value2.Y);
  170.             return result;
  171.         }
  172.         public static void Max(ref Vector2 value1, ref Vector2 value2, out Vector2 result)
  173.         {
  174.             result.X = ((value1.X > value2.X) ? value1.X : value2.X);
  175.             result.Y = ((value1.Y > value2.Y) ? value1.Y : value2.Y);
  176.         }
  177.         public static Vector2 Clamp(Vector2 value1, Vector2 min, Vector2 max)
  178.         {
  179.             float num = value1.X;
  180.             num = ((num > max.X) ? max.X : num);
  181.             num = ((num < min.X) ? min.X : num);
  182.             float num2 = value1.Y;
  183.             num2 = ((num2 > max.Y) ? max.Y : num2);
  184.             num2 = ((num2 < min.Y) ? min.Y : num2);
  185.             Vector2 result;
  186.             result.X = num;
  187.             result.Y = num2;
  188.             return result;
  189.         }
  190.         public static void Clamp(ref Vector2 value1, ref Vector2 min, ref Vector2 max, out Vector2 result)
  191.         {
  192.             float num = value1.X;
  193.             num = ((num > max.X) ? max.X : num);
  194.             num = ((num < min.X) ? min.X : num);
  195.             float num2 = value1.Y;
  196.             num2 = ((num2 > max.Y) ? max.Y : num2);
  197.             num2 = ((num2 < min.Y) ? min.Y : num2);
  198.             result.X = num;
  199.             result.Y = num2;
  200.         }
  201.         public static Vector2 Lerp(Vector2 value1, Vector2 value2, float amount)
  202.         {
  203.             Vector2 result;
  204.             result.X = value1.X + (value2.X - value1.X) * amount;
  205.             result.Y = value1.Y + (value2.Y - value1.Y) * amount;
  206.             return result;
  207.         }
  208.         public static void Lerp(ref Vector2 value1, ref Vector2 value2, float amount, out Vector2 result)
  209.         {
  210.             result.X = value1.X + (value2.X - value1.X) * amount;
  211.             result.Y = value1.Y + (value2.Y - value1.Y) * amount;
  212.         }
  213.         public static Vector2 Barycentric(Vector2 value1, Vector2 value2, Vector2 value3, float amount1, float amount2)
  214.         {
  215.             Vector2 result;
  216.             result.X = value1.X + amount1 * (value2.X - value1.X) + amount2 * (value3.X - value1.X);
  217.             result.Y = value1.Y + amount1 * (value2.Y - value1.Y) + amount2 * (value3.Y - value1.Y);
  218.             return result;
  219.         }
  220.         public static void Barycentric(ref Vector2 value1, ref Vector2 value2, ref Vector2 value3, float amount1, float amount2, out Vector2 result)
  221.         {
  222.             result.X = value1.X + amount1 * (value2.X - value1.X) + amount2 * (value3.X - value1.X);
  223.             result.Y = value1.Y + amount1 * (value2.Y - value1.Y) + amount2 * (value3.Y - value1.Y);
  224.         }
  225.         public static Vector2 SmoothStep(Vector2 value1, Vector2 value2, float amount)
  226.         {
  227.             amount = ((amount > 1f) ? 1f : ((amount < 0f) ? 0f : amount));
  228.             amount = amount * amount * (3f - 2f * amount);
  229.             Vector2 result;
  230.             result.X = value1.X + (value2.X - value1.X) * amount;
  231.             result.Y = value1.Y + (value2.Y - value1.Y) * amount;
  232.             return result;
  233.         }
  234.         public static void SmoothStep(ref Vector2 value1, ref Vector2 value2, float amount, out Vector2 result)
  235.         {
  236.             amount = ((amount > 1f) ? 1f : ((amount < 0f) ? 0f : amount));
  237.             amount = amount * amount * (3f - 2f * amount);
  238.             result.X = value1.X + (value2.X - value1.X) * amount;
  239.             result.Y = value1.Y + (value2.Y - value1.Y) * amount;
  240.         }
  241.         public static Vector2 CatmullRom(Vector2 value1, Vector2 value2, Vector2 value3, Vector2 value4, float amount)
  242.         {
  243.             float num = amount * amount;
  244.             float num2 = amount * num;
  245.             Vector2 result;
  246.             result.X = 0.5f * (2f * value2.X + (-value1.X + value3.X) * amount + (2f * value1.X - 5f * value2.X + 4f * value3.X - value4.X) * num + (-value1.X + 3f * value2.X - 3f * value3.X + value4.X) * num2);
  247.             result.Y = 0.5f * (2f * value2.Y + (-value1.Y + value3.Y) * amount + (2f * value1.Y - 5f * value2.Y + 4f * value3.Y - value4.Y) * num + (-value1.Y + 3f * value2.Y - 3f * value3.Y + value4.Y) * num2);
  248.             return result;
  249.         }
  250.         public static void CatmullRom(ref Vector2 value1, ref Vector2 value2, ref Vector2 value3, ref Vector2 value4, float amount, out Vector2 result)
  251.         {
  252.             float num = amount * amount;
  253.             float num2 = amount * num;
  254.             result.X = 0.5f * (2f * value2.X + (-value1.X + value3.X) * amount + (2f * value1.X - 5f * value2.X + 4f * value3.X - value4.X) * num + (-value1.X + 3f * value2.X - 3f * value3.X + value4.X) * num2);
  255.             result.Y = 0.5f * (2f * value2.Y + (-value1.Y + value3.Y) * amount + (2f * value1.Y - 5f * value2.Y + 4f * value3.Y - value4.Y) * num + (-value1.Y + 3f * value2.Y - 3f * value3.Y + value4.Y) * num2);
  256.         }
  257.         public static Vector2 Hermite(Vector2 value1, Vector2 tangent1, Vector2 value2, Vector2 tangent2, float amount)
  258.         {
  259.             float num = amount * amount;
  260.             float num2 = amount * num;
  261.             float num3 = 2f * num2 - 3f * num + 1f;
  262.             float num4 = -2f * num2 + 3f * num;
  263.             float num5 = num2 - 2f * num + amount;
  264.             float num6 = num2 - num;
  265.             Vector2 result;
  266.             result.X = value1.X * num3 + value2.X * num4 + tangent1.X * num5 + tangent2.X * num6;
  267.             result.Y = value1.Y * num3 + value2.Y * num4 + tangent1.Y * num5 + tangent2.Y * num6;
  268.             return result;
  269.         }
  270.         public static void Hermite(ref Vector2 value1, ref Vector2 tangent1, ref Vector2 value2, ref Vector2 tangent2, float amount, out Vector2 result)
  271.         {
  272.             float num = amount * amount;
  273.             float num2 = amount * num;
  274.             float num3 = 2f * num2 - 3f * num + 1f;
  275.             float num4 = -2f * num2 + 3f * num;
  276.             float num5 = num2 - 2f * num + amount;
  277.             float num6 = num2 - num;
  278.             result.X = value1.X * num3 + value2.X * num4 + tangent1.X * num5 + tangent2.X * num6;
  279.             result.Y = value1.Y * num3 + value2.Y * num4 + tangent1.Y * num5 + tangent2.Y * num6;
  280.         }
  281.         public static Vector2 Transform(Vector2 position, Matrix matrix)
  282.         {
  283.             float x = position.X * matrix.M11 + position.Y * matrix.M21 + matrix.M41;
  284.             float y = position.X * matrix.M12 + position.Y * matrix.M22 + matrix.M42;
  285.             Vector2 result;
  286.             result.X = x;
  287.             result.Y = y;
  288.             return result;
  289.         }
  290.         public static void Transform(ref Vector2 position, ref Matrix matrix, out Vector2 result)
  291.         {
  292.             float x = position.X * matrix.M11 + position.Y * matrix.M21 + matrix.M41;
  293.             float y = position.X * matrix.M12 + position.Y * matrix.M22 + matrix.M42;
  294.             result.X = x;
  295.             result.Y = y;
  296.         }
  297.         public static Vector2 TransformNormal(Vector2 normal, Matrix matrix)
  298.         {
  299.             float x = normal.X * matrix.M11 + normal.Y * matrix.M21;
  300.             float y = normal.X * matrix.M12 + normal.Y * matrix.M22;
  301.             Vector2 result;
  302.             result.X = x;
  303.             result.Y = y;
  304.             return result;
  305.         }
  306.         public static void TransformNormal(ref Vector2 normal, ref Matrix matrix, out Vector2 result)
  307.         {
  308.             float x = normal.X * matrix.M11 + normal.Y * matrix.M21;
  309.             float y = normal.X * matrix.M12 + normal.Y * matrix.M22;
  310.             result.X = x;
  311.             result.Y = y;
  312.         }
  313.         public static Vector2 Transform(Vector2 value, Quaternion rotation)
  314.         {
  315.             float num = rotation.X + rotation.X;
  316.             float num2 = rotation.Y + rotation.Y;
  317.             float num3 = rotation.Z + rotation.Z;
  318.             float num4 = rotation.W * num3;
  319.             float num5 = rotation.X * num;
  320.             float num6 = rotation.X * num2;
  321.             float num7 = rotation.Y * num2;
  322.             float num8 = rotation.Z * num3;
  323.             float x = value.X * (1f - num7 - num8) + value.Y * (num6 - num4);
  324.             float y = value.X * (num6 + num4) + value.Y * (1f - num5 - num8);
  325.             Vector2 result;
  326.             result.X = x;
  327.             result.Y = y;
  328.             return result;
  329.         }
  330.         public static void Transform(ref Vector2 value, ref Quaternion rotation, out Vector2 result)
  331.         {
  332.             float num = rotation.X + rotation.X;
  333.             float num2 = rotation.Y + rotation.Y;
  334.             float num3 = rotation.Z + rotation.Z;
  335.             float num4 = rotation.W * num3;
  336.             float num5 = rotation.X * num;
  337.             float num6 = rotation.X * num2;
  338.             float num7 = rotation.Y * num2;
  339.             float num8 = rotation.Z * num3;
  340.             float x = value.X * (1f - num7 - num8) + value.Y * (num6 - num4);
  341.             float y = value.X * (num6 + num4) + value.Y * (1f - num5 - num8);
  342.             result.X = x;
  343.             result.Y = y;
  344.         }
  345.         public static void Transform(Vector2[] sourceArray, ref Matrix matrix, Vector2[] destinationArray)
  346.         {
  347.             if (sourceArray == null)
  348.             {
  349.                 throw new ArgumentNullException("sourceArray");
  350.             }
  351.             if (destinationArray == null)
  352.             {
  353.                 throw new ArgumentNullException("destinationArray");
  354.             }
  355.             if (destinationArray.Length < sourceArray.Length)
  356.             {
  357.                 throw new ArgumentException(FrameworkResources.NotEnoughTargetSize);
  358.             }
  359.             for (int i = 0; i < sourceArray.Length; i++)
  360.             {
  361.                 float x = sourceArray[i].X;
  362.                 float y = sourceArray[i].Y;
  363.                 destinationArray[i].X = x * matrix.M11 + y * matrix.M21 + matrix.M41;
  364.                 destinationArray[i].Y = x * matrix.M12 + y * matrix.M22 + matrix.M42;
  365.             }
  366.         }
  367.         public static void Transform(Vector2[] sourceArray, int sourceIndex, ref Matrix matrix, Vector2[] destinationArray, int destinationIndex, int length)
  368.         {
  369.             if (sourceArray == null)
  370.             {
  371.                 throw new ArgumentNullException("sourceArray");
  372.             }
  373.             if (destinationArray == null)
  374.             {
  375.                 throw new ArgumentNullException("destinationArray");
  376.             }
  377.             if ((long)sourceArray.Length < (long)sourceIndex + (long)length)
  378.             {
  379.                 throw new ArgumentException(FrameworkResources.NotEnoughSourceSize);
  380.             }
  381.             if ((long)destinationArray.Length < (long)destinationIndex + (long)length)
  382.             {
  383.                 throw new ArgumentException(FrameworkResources.NotEnoughTargetSize);
  384.             }
  385.             while (length > 0)
  386.             {
  387.                 float x = sourceArray[sourceIndex].X;
  388.                 float y = sourceArray[sourceIndex].Y;
  389.                 destinationArray[destinationIndex].X = x * matrix.M11 + y * matrix.M21 + matrix.M41;
  390.                 destinationArray[destinationIndex].Y = x * matrix.M12 + y * matrix.M22 + matrix.M42;
  391.                 sourceIndex++;
  392.                 destinationIndex++;
  393.                 length--;
  394.             }
  395.         }
  396.         public static void TransformNormal(Vector2[] sourceArray, ref Matrix matrix, Vector2[] destinationArray)
  397.         {
  398.             if (sourceArray == null)
  399.             {
  400.                 throw new ArgumentNullException("sourceArray");
  401.             }
  402.             if (destinationArray == null)
  403.             {
  404.                 throw new ArgumentNullException("destinationArray");
  405.             }
  406.             if (destinationArray.Length < sourceArray.Length)
  407.             {
  408.                 throw new ArgumentException(FrameworkResources.NotEnoughTargetSize);
  409.             }
  410.             for (int i = 0; i < sourceArray.Length; i++)
  411.             {
  412.                 float x = sourceArray[i].X;
  413.                 float y = sourceArray[i].Y;
  414.                 destinationArray[i].X = x * matrix.M11 + y * matrix.M21;
  415.                 destinationArray[i].Y = x * matrix.M12 + y * matrix.M22;
  416.             }
  417.         }
  418.         public static void TransformNormal(Vector2[] sourceArray, int sourceIndex, ref Matrix matrix, Vector2[] destinationArray, int destinationIndex, int length)
  419.         {
  420.             if (sourceArray == null)
  421.             {
  422.                 throw new ArgumentNullException("sourceArray");
  423.             }
  424.             if (destinationArray == null)
  425.             {
  426.                 throw new ArgumentNullException("destinationArray");
  427.             }
  428.             if ((long)sourceArray.Length < (long)sourceIndex + (long)length)
  429.             {
  430.                 throw new ArgumentException(FrameworkResources.NotEnoughSourceSize);
  431.             }
  432.             if ((long)destinationArray.Length < (long)destinationIndex + (long)length)
  433.             {
  434.                 throw new ArgumentException(FrameworkResources.NotEnoughTargetSize);
  435.             }
  436.             while (length > 0)
  437.             {
  438.                 float x = sourceArray[sourceIndex].X;
  439.                 float y = sourceArray[sourceIndex].Y;
  440.                 destinationArray[destinationIndex].X = x * matrix.M11 + y * matrix.M21;
  441.                 destinationArray[destinationIndex].Y = x * matrix.M12 + y * matrix.M22;
  442.                 sourceIndex++;
  443.                 destinationIndex++;
  444.                 length--;
  445.             }
  446.         }
  447.         public static void Transform(Vector2[] sourceArray, ref Quaternion rotation, Vector2[] destinationArray)
  448.         {
  449.             if (sourceArray == null)
  450.             {
  451.                 throw new ArgumentNullException("sourceArray");
  452.             }
  453.             if (destinationArray == null)
  454.             {
  455.                 throw new ArgumentNullException("destinationArray");
  456.             }
  457.             if (destinationArray.Length < sourceArray.Length)
  458.             {
  459.                 throw new ArgumentException(FrameworkResources.NotEnoughTargetSize);
  460.             }
  461.             float num = rotation.X + rotation.X;
  462.             float num2 = rotation.Y + rotation.Y;
  463.             float num3 = rotation.Z + rotation.Z;
  464.             float num4 = rotation.W * num3;
  465.             float num5 = rotation.X * num;
  466.             float num6 = rotation.X * num2;
  467.             float num7 = rotation.Y * num2;
  468.             float num8 = rotation.Z * num3;
  469.             float num9 = 1f - num7 - num8;
  470.             float num10 = num6 - num4;
  471.             float num11 = num6 + num4;
  472.             float num12 = 1f - num5 - num8;
  473.             for (int i = 0; i < sourceArray.Length; i++)
  474.             {
  475.                 float x = sourceArray[i].X;
  476.                 float y = sourceArray[i].Y;
  477.                 destinationArray[i].X = x * num9 + y * num10;
  478.                 destinationArray[i].Y = x * num11 + y * num12;
  479.             }
  480.         }
  481.         public static void Transform(Vector2[] sourceArray, int sourceIndex, ref Quaternion rotation, Vector2[] destinationArray, int destinationIndex, int length)
  482.         {
  483.             if (sourceArray == null)
  484.             {
  485.                 throw new ArgumentNullException("sourceArray");
  486.             }
  487.             if (destinationArray == null)
  488.             {
  489.                 throw new ArgumentNullException("destinationArray");
  490.             }
  491.             if ((long)sourceArray.Length < (long)sourceIndex + (long)length)
  492.             {
  493.                 throw new ArgumentException(FrameworkResources.NotEnoughSourceSize);
  494.             }
  495.             if ((long)destinationArray.Length < (long)destinationIndex + (long)length)
  496.             {
  497.                 throw new ArgumentException(FrameworkResources.NotEnoughTargetSize);
  498.             }
  499.             float num = rotation.X + rotation.X;
  500.             float num2 = rotation.Y + rotation.Y;
  501.             float num3 = rotation.Z + rotation.Z;
  502.             float num4 = rotation.W * num3;
  503.             float num5 = rotation.X * num;
  504.             float num6 = rotation.X * num2;
  505.             float num7 = rotation.Y * num2;
  506.             float num8 = rotation.Z * num3;
  507.             float num9 = 1f - num7 - num8;
  508.             float num10 = num6 - num4;
  509.             float num11 = num6 + num4;
  510.             float num12 = 1f - num5 - num8;
  511.             while (length > 0)
  512.             {
  513.                 float x = sourceArray[sourceIndex].X;
  514.                 float y = sourceArray[sourceIndex].Y;
  515.                 destinationArray[destinationIndex].X = x * num9 + y * num10;
  516.                 destinationArray[destinationIndex].Y = x * num11 + y * num12;
  517.                 sourceIndex++;
  518.                 destinationIndex++;
  519.                 length--;
  520.             }
  521.         }
  522.         public static Vector2 Negate(Vector2 value)
  523.         {
  524.             Vector2 result;
  525.             result.X = -value.X;
  526.             result.Y = -value.Y;
  527.             return result;
  528.         }
  529.         public static void Negate(ref Vector2 value, out Vector2 result)
  530.         {
  531.             result.X = -value.X;
  532.             result.Y = -value.Y;
  533.         }
  534.         public static Vector2 Add(Vector2 value1, Vector2 value2)
  535.         {
  536.             Vector2 result;
  537.             result.X = value1.X + value2.X;
  538.             result.Y = value1.Y + value2.Y;
  539.             return result;
  540.         }
  541.         public static void Add(ref Vector2 value1, ref Vector2 value2, out Vector2 result)
  542.         {
  543.             result.X = value1.X + value2.X;
  544.             result.Y = value1.Y + value2.Y;
  545.         }
  546.         public static Vector2 Subtract(Vector2 value1, Vector2 value2)
  547.         {
  548.             Vector2 result;
  549.             result.X = value1.X - value2.X;
  550.             result.Y = value1.Y - value2.Y;
  551.             return result;
  552.         }
  553.         public static void Subtract(ref Vector2 value1, ref Vector2 value2, out Vector2 result)
  554.         {
  555.             result.X = value1.X - value2.X;
  556.             result.Y = value1.Y - value2.Y;
  557.         }
  558.         public static Vector2 Multiply(Vector2 value1, Vector2 value2)
  559.         {
  560.             Vector2 result;
  561.             result.X = value1.X * value2.X;
  562.             result.Y = value1.Y * value2.Y;
  563.             return result;
  564.         }
  565.         public static void Multiply(ref Vector2 value1, ref Vector2 value2, out Vector2 result)
  566.         {
  567.             result.X = value1.X * value2.X;
  568.             result.Y = value1.Y * value2.Y;
  569.         }
  570.         public static Vector2 Multiply(Vector2 value1, float scaleFactor)
  571.         {
  572.             Vector2 result;
  573.             result.X = value1.X * scaleFactor;
  574.             result.Y = value1.Y * scaleFactor;
  575.             return result;
  576.         }
  577.         public static void Multiply(ref Vector2 value1, float scaleFactor, out Vector2 result)
  578.         {
  579.             result.X = value1.X * scaleFactor;
  580.             result.Y = value1.Y * scaleFactor;
  581.         }
  582.         public static Vector2 Divide(Vector2 value1, Vector2 value2)
  583.         {
  584.             Vector2 result;
  585.             result.X = value1.X / value2.X;
  586.             result.Y = value1.Y / value2.Y;
  587.             return result;
  588.         }
  589.         public static void Divide(ref Vector2 value1, ref Vector2 value2, out Vector2 result)
  590.         {
  591.             result.X = value1.X / value2.X;
  592.             result.Y = value1.Y / value2.Y;
  593.         }
  594.         public static Vector2 Divide(Vector2 value1, float divider)
  595.         {
  596.             float num = 1f / divider;
  597.             Vector2 result;
  598.             result.X = value1.X * num;
  599.             result.Y = value1.Y * num;
  600.             return result;
  601.         }
  602.         public static void Divide(ref Vector2 value1, float divider, out Vector2 result)
  603.         {
  604.             float num = 1f / divider;
  605.             result.X = value1.X * num;
  606.             result.Y = value1.Y * num;
  607.         }
  608.         public static Vector2 operator -(Vector2 value)
  609.         {
  610.             Vector2 result;
  611.             result.X = -value.X;
  612.             result.Y = -value.Y;
  613.             return result;
  614.         }
  615.         public static bool operator ==(Vector2 value1, Vector2 value2)
  616.         {
  617.             return value1.X == value2.X && value1.Y == value2.Y;
  618.         }
  619.         public static bool operator !=(Vector2 value1, Vector2 value2)
  620.         {
  621.             return value1.X != value2.X || value1.Y != value2.Y;
  622.         }
  623.         public static Vector2 operator +(Vector2 value1, Vector2 value2)
  624.         {
  625.             Vector2 result;
  626.             result.X = value1.X + value2.X;
  627.             result.Y = value1.Y + value2.Y;
  628.             return result;
  629.         }
  630.         public static Vector2 operator -(Vector2 value1, Vector2 value2)
  631.         {
  632.             Vector2 result;
  633.             result.X = value1.X - value2.X;
  634.             result.Y = value1.Y - value2.Y;
  635.             return result;
  636.         }
  637.         public static Vector2 operator *(Vector2 value1, Vector2 value2)
  638.         {
  639.             Vector2 result;
  640.             result.X = value1.X * value2.X;
  641.             result.Y = value1.Y * value2.Y;
  642.             return result;
  643.         }
  644.         public static Vector2 operator *(Vector2 value, float scaleFactor)
  645.         {
  646.             Vector2 result;
  647.             result.X = value.X * scaleFactor;
  648.             result.Y = value.Y * scaleFactor;
  649.             return result;
  650.         }
  651.         public static Vector2 operator *(float scaleFactor, Vector2 value)
  652.         {
  653.             Vector2 result;
  654.             result.X = value.X * scaleFactor;
  655.             result.Y = value.Y * scaleFactor;
  656.             return result;
  657.         }
  658.         public static Vector2 operator /(Vector2 value1, Vector2 value2)
  659.         {
  660.             Vector2 result;
  661.             result.X = value1.X / value2.X;
  662.             result.Y = value1.Y / value2.Y;
  663.             return result;
  664.         }
  665.         public static Vector2 operator /(Vector2 value1, float divider)
  666.         {
  667.             float num = 1f / divider;
  668.             Vector2 result;
  669.             result.X = value1.X * num;
  670.             result.Y = value1.Y * num;
  671.             return result;
  672.         }
  673.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement