GibTreaty

VectorI

Jun 14th, 2015
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 19.26 KB | None | 0 0
  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5.  
  6. [System.Serializable]
  7. public struct VectorI3 {
  8.     #region Constants
  9.     public static readonly VectorI3 one = new VectorI3(1, 1, 1);
  10.     public static readonly VectorI3 negativeOne = new VectorI3(-1, -1, -1);
  11.     public static readonly VectorI3 zero = new VectorI3(0, 0, 0);
  12.     public static readonly VectorI3 left = new VectorI3(-1, 0, 0);
  13.     public static readonly VectorI3 right = new VectorI3(1, 0, 0);
  14.     public static readonly VectorI3 up = new VectorI3(0, 1, 0);
  15.     public static readonly VectorI3 top = new VectorI3(0, 1, 0);
  16.     public static readonly VectorI3 down = new VectorI3(0, -1, 0);
  17.     public static readonly VectorI3 bottom = new VectorI3(0, -1, 0);
  18.     public static readonly VectorI3 forward = new VectorI3(0, 0, 1);
  19.     public static readonly VectorI3 back = new VectorI3(0, 0, -1);
  20.  
  21.     #region Direction Array
  22.     static readonly List<VectorI3> _direction = new List<VectorI3>(){
  23.         VectorI3.left,
  24.         VectorI3.right,
  25.         VectorI3.up,
  26.         VectorI3.down,
  27.         VectorI3.forward,
  28.         VectorI3.back,
  29.        
  30.         //Corner
  31.         new VectorI3(-1,1,1),
  32.         new VectorI3(1,-1,-1),
  33.  
  34.         new VectorI3(-1,-1,1),
  35.         new VectorI3(1,1,-1),
  36.  
  37.         new VectorI3(-1,1,-1),
  38.         new VectorI3(1,-1,1),
  39.  
  40.         new VectorI3(-1,-1,-1),
  41.         new VectorI3(1,1,1),
  42.  
  43.         //Edge Corner
  44.         new VectorI3(-1,0,1), //Left Front
  45.         new VectorI3(1,0,-1), //Right Back
  46.         new VectorI3(-1,0,-1), //Left Back
  47.         new VectorI3(1,0,1), //Right Front
  48.  
  49.         new VectorI3(-1,1,0), //Left Top
  50.         new VectorI3(1,-1,0), //Right Bottom
  51.         new VectorI3(-1,-1,0), //Left Bottom
  52.         new VectorI3(1,1,0), //Right Top
  53.  
  54.         new VectorI3(0,1,1), //Top Front
  55.         new VectorI3(0,-1,-1), //Bottom Back
  56.         new VectorI3(0,1,-1), //Top Back
  57.         new VectorI3(0,-1,1), //Bottom Front
  58.     };
  59.     #endregion
  60.     public static VectorI3[] direction {
  61.         get { return (VectorI3[])_direction.ToArray(); }
  62.     }
  63.     #endregion
  64.  
  65.     public int x, y, z;
  66.     public int this[int index] {
  67.         get {
  68.             switch(index) {
  69.                 default: return x;
  70.                 case 1: return y;
  71.                 case 2: return z;
  72.             }
  73.         }
  74.         set {
  75.             switch(index) {
  76.                 default: x = value; break;
  77.                 case 1: y = value; break;
  78.                 case 2: z = value; break;
  79.             }
  80.         }
  81.     }
  82.  
  83.     public VectorI3(int x, int y, int z) {
  84.         this.x = x;
  85.         this.y = y;
  86.         this.z = z;
  87.     }
  88.     public VectorI3(float x, float y, float z) {
  89.         this.x = (int)x;
  90.         this.y = (int)y;
  91.         this.z = (int)z;
  92.     }
  93.     public VectorI3(VectorI3 vector) {
  94.         this.x = vector.x;
  95.         this.y = vector.y;
  96.         this.z = vector.z;
  97.     }
  98.     public VectorI3(Vector3 vector) {
  99.         this.x = (int)vector.x;
  100.         this.y = (int)vector.y;
  101.         this.z = (int)vector.z;
  102.     }
  103.     public VectorI3(VectorI2 vector) {
  104.         this.x = vector.x;
  105.         this.y = vector.y;
  106.         z = 0;
  107.     }
  108.  
  109.     #region VectorI3 / Vector3 Methods
  110.     public void Abs() {
  111.         x = Mathf.Abs(x);
  112.         y = Mathf.Abs(y);
  113.         z = Mathf.Abs(z);
  114.     }
  115.  
  116.     public static VectorI3 GridCeil(Vector3 v, Vector3 roundBy) {
  117.         return Round(new Vector3(
  118.             Mathf.Ceil(v.x / roundBy.x) * roundBy.x,
  119.             Mathf.Ceil(v.y / roundBy.y) * roundBy.y,
  120.             Mathf.Ceil(v.z / roundBy.z) * roundBy.z
  121.             ));
  122.     }
  123.     public static VectorI3 GridFloor(Vector3 v, Vector3 roundBy) {
  124.         return Round(new Vector3(
  125.             Mathf.Floor(v.x / roundBy.x) * roundBy.x,
  126.             Mathf.Floor(v.y / roundBy.y) * roundBy.y,
  127.             Mathf.Floor(v.z / roundBy.z) * roundBy.z
  128.             ));
  129.     }
  130.     public static VectorI3 GridRound(Vector3 v, Vector3 roundBy) {
  131.         return Round(new Vector3(
  132.             Mathf.Round(v.x / roundBy.x) * roundBy.x,
  133.             Mathf.Round(v.y / roundBy.y) * roundBy.y,
  134.             Mathf.Round(v.z / roundBy.z) * roundBy.z
  135.             ));
  136.     }
  137.  
  138.     public static VectorI3 Ceil(Vector3 v) {
  139.         return new VectorI3(Mathf.CeilToInt(v.x), Mathf.CeilToInt(v.y), Mathf.CeilToInt(v.z));
  140.     }
  141.     public static VectorI3 Floor(Vector3 v) {
  142.         return new VectorI3(Mathf.FloorToInt(v.x), Mathf.FloorToInt(v.y), Mathf.FloorToInt(v.z));
  143.     }
  144.     public static VectorI3 Round(Vector3 v) {
  145.         return new VectorI3(Mathf.RoundToInt(v.x), Mathf.RoundToInt(v.y), Mathf.RoundToInt(v.z));
  146.     }
  147.     public static VectorI3 FastRound(Vector3 v) {
  148.         return new VectorI3(
  149.             v.x > 0 ? (int)(v.x + .5f) : (int)(v.x - .5f),
  150.             v.y > 0 ? (int)(v.y + .5f) : (int)(v.y - .5f),
  151.             v.z > 0 ? (int)(v.z + .5f) : (int)(v.z - .5f)
  152.         );
  153.     }
  154.  
  155.     public void Ceil() {
  156.         x = Mathf.CeilToInt(x);
  157.         y = Mathf.CeilToInt(y);
  158.         z = Mathf.CeilToInt(z);
  159.     }
  160.     public void Floor() {
  161.         x = Mathf.FloorToInt(x);
  162.         y = Mathf.FloorToInt(y);
  163.         z = Mathf.FloorToInt(z);
  164.     }
  165.     public void Round() {
  166.         x = Mathf.RoundToInt(x);
  167.         y = Mathf.RoundToInt(y);
  168.         z = Mathf.RoundToInt(z);
  169.     }
  170.     public void FastRound() {
  171.         x = x > 0 ? (int)(x + .5f) : (int)(x - .5f);
  172.         y = y > 0 ? (int)(y + .5f) : (int)(y - .5f);
  173.         z = z > 0 ? (int)(z + .5f) : (int)(z - .5f);
  174.     }
  175.  
  176.     public int size {
  177.         get { return Size(this); }
  178.     }
  179.     public static int Size(VectorI3 v) {
  180.         return v.x * v.y * v.z;
  181.     }
  182.  
  183.     public static int DirectionToIndex(VectorI3 dir) {
  184.         if(_direction.Contains(dir)) {
  185.             return _direction.IndexOf(dir);
  186.         }
  187.         else {
  188.             return 0;
  189.         }
  190.     }
  191.     public static VectorI3 Wrap3DIndex(VectorI3 positionIndex, VectorI3 direction, VectorI3 arraySize) {
  192.         VectorI3 newDirection = new VectorI3(
  193.             ((positionIndex.x + direction.x) % (arraySize.x)),
  194.             ((positionIndex.y + direction.y) % (arraySize.y)),
  195.             ((positionIndex.z + direction.z) % (arraySize.z))
  196.             );
  197.  
  198.         if(newDirection.x < 0) { newDirection.x = arraySize.x + newDirection.x; }
  199.         if(newDirection.y < 0) { newDirection.y = arraySize.y + newDirection.y; }
  200.         if(newDirection.z < 0) { newDirection.z = arraySize.z + newDirection.z; }
  201.  
  202.         return newDirection;
  203.     }
  204.  
  205.     public static bool AnyGreater(VectorI3 a, VectorI3 b) {
  206.         return a.x > b.x || a.y > b.y || a.z > b.z;
  207.     }
  208.     public static bool AllGreater(VectorI3 a, VectorI3 b) {
  209.         return a.x > b.x && a.y > b.y && a.z > b.z;
  210.     }
  211.     public static bool AnyLower(VectorI3 a, VectorI3 b) {
  212.         return a.x < b.x || a.y < b.y || a.z < b.z;
  213.     }
  214.     public static bool AllLower(VectorI3 a, VectorI3 b) {
  215.         return a.x < b.x && a.y < b.y && a.z < b.z;
  216.     }
  217.     public static bool AnyGreaterAllEqual(VectorI3 a, VectorI3 b) {
  218.         return a == b || AnyGreater(a, b);
  219.     }
  220.     public static bool AllGreaterEqual(VectorI3 a, VectorI3 b) {
  221.         return a == b || AllGreater(a, b);
  222.     }
  223.     public static bool AnyLowerEqual(VectorI3 a, VectorI3 b) {
  224.         return a == b || AnyLower(a, b);
  225.     }
  226.     public static bool AllLowerEqual(VectorI3 a, VectorI3 b) {
  227.         return a == b || AllLower(a, b);
  228.     }
  229.  
  230.     public static VectorI3 Max(VectorI3 lhs, VectorI3 rhs) {
  231.         return new VectorI3(Mathf.Max(lhs.x, rhs.x), Mathf.Max(lhs.y, rhs.y), Mathf.Max(lhs.z, rhs.z));
  232.     }
  233.     public static VectorI3 Min(VectorI3 lhs, VectorI3 rhs) {
  234.         return new VectorI3(Mathf.Min(lhs.x, rhs.x), Mathf.Min(lhs.y, rhs.y), Mathf.Min(lhs.z, rhs.z));
  235.     }
  236.     #endregion
  237.  
  238.     #region Advanced
  239.     public static VectorI3 operator -(VectorI3 a) {
  240.         return new VectorI3(-a.x, -a.y, -a.z);
  241.     }
  242.     public static VectorI3 operator -(VectorI3 a, VectorI3 b) {
  243.         return new VectorI3(a.x - b.x, a.y - b.y, a.z - b.z);
  244.     }
  245.     public static Vector3 operator -(Vector3 a, VectorI3 b) {
  246.         return new Vector3(a.x - b.x, a.y - b.y, a.z - b.z);
  247.     }
  248.     public static Vector3 operator -(VectorI3 a, Vector3 b) {
  249.         return new Vector3(a.x - b.x, a.y - b.y, a.z - b.z);
  250.     }
  251.  
  252.     public static bool operator !=(VectorI3 lhs, VectorI3 rhs) {
  253.         return lhs.x != rhs.x || lhs.y != rhs.y || lhs.z != rhs.z;
  254.     }
  255.     public static bool operator !=(Vector3 lhs, VectorI3 rhs) {
  256.         return lhs.x != rhs.x || lhs.y != rhs.y || lhs.z != rhs.z;
  257.     }
  258.     public static bool operator !=(VectorI3 lhs, Vector3 rhs) {
  259.         return lhs.x != rhs.x || lhs.y != rhs.y || lhs.z != rhs.z;
  260.     }
  261.  
  262.     public static Vector3 operator *(float d, VectorI3 a) {
  263.         return new Vector3(d * a.x, d * a.y, d * a.z);
  264.     }
  265.     public static VectorI3 operator *(int d, VectorI3 a) {
  266.         return new VectorI3(d * a.x, d * a.y, d * a.z);
  267.     }
  268.     public static Vector3 operator *(VectorI3 a, float d) {
  269.         return new Vector3(a.x * d, a.y * d, a.z * d);
  270.     }
  271.     public static VectorI3 operator *(VectorI3 a, int d) {
  272.         return new VectorI3(a.x * d, a.y * d, a.z * d);
  273.     }
  274.     public static Vector3 operator /(VectorI3 a, float d) {
  275.         return new Vector3(a.x / d, a.y / d, a.z / d);
  276.     }
  277.     public static VectorI3 operator /(VectorI3 a, int d) {
  278.         return new VectorI3(a.x / d, a.y / d, a.z / d);
  279.     }
  280.     public static float operator /(float d, VectorI3 a) {
  281.         d /= a.x; d /= a.y; d /= a.z;
  282.         return d;
  283.     }
  284.  
  285.     public static VectorI3 operator *(VectorI3 a, VectorI3 b) {
  286.         return new VectorI3(a.x * b.x, a.y * b.y, a.z * b.z);
  287.     }
  288.     public static Vector3 operator *(Vector3 a, VectorI3 b) {
  289.         return new Vector3(a.x * b.x, a.y * b.y, a.z * b.z);
  290.     }
  291.     public static Vector3 operator *(VectorI3 a, Vector3 b) {
  292.         return new Vector3(a.x * b.x, a.y * b.y, a.z * b.z);
  293.     }
  294.  
  295.     public static VectorI3 operator /(VectorI3 a, VectorI3 b) {
  296.         return new VectorI3(a.x / b.x, a.y / b.y, a.z / b.z);
  297.     }
  298.     public static Vector3 operator /(Vector3 a, VectorI3 b) {
  299.         return new Vector3(a.x / b.x, a.y / b.y, a.z / b.z);
  300.     }
  301.     public static Vector3 operator /(VectorI3 a, Vector3 b) {
  302.         return new Vector3(a.x / b.x, a.y / b.y, a.z / b.z);
  303.     }
  304.  
  305.     public static VectorI3 operator +(VectorI3 a, VectorI3 b) {
  306.         return new VectorI3(a.x + b.x, a.y + b.y, a.z + b.z);
  307.     }
  308.     public static Vector3 operator +(Vector3 a, VectorI3 b) {
  309.         return new Vector3(a.x + b.x, a.y + b.y, a.z + b.z);
  310.     }
  311.     public static Vector3 operator +(VectorI3 a, Vector3 b) {
  312.         return new Vector3(a.x + b.x, a.y + b.y, a.z + b.z);
  313.     }
  314.  
  315.     public static Vector3 operator +(VectorI3 a, float d) {
  316.         return new Vector3(a.x + d, a.y + d, a.z + d);
  317.     }
  318.     public static VectorI3 operator +(VectorI3 a, int d) {
  319.         return new VectorI3(a.x + d, a.y + d, a.z + d);
  320.     }
  321.  
  322.     public static bool operator ==(VectorI3 lhs, VectorI3 rhs) {
  323.         return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z;
  324.     }
  325.     public static bool operator ==(Vector3 lhs, VectorI3 rhs) {
  326.         return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z;
  327.     }
  328.     public static bool operator ==(VectorI3 lhs, Vector3 rhs) {
  329.         return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z;
  330.     }
  331.  
  332.     public static implicit operator VectorI3(Vector2 v) {
  333.         return new VectorI3(v.x, v.y, 0);
  334.     }
  335.     public static implicit operator VectorI3(Vector3 v) {
  336.         return new VectorI3(v);
  337.     }
  338.     public static implicit operator VectorI3(Vector4 v) {
  339.         return new VectorI3(v.x, v.y, v.z);
  340.     }
  341.     public static implicit operator Vector2(VectorI3 v) {
  342.         return new Vector3(v.x, v.y, v.z);
  343.     }
  344.     public static implicit operator Vector3(VectorI3 v) {
  345.         return new Vector3(v.x, v.y, v.z);
  346.     }
  347.     public static implicit operator Vector4(VectorI3 v) {
  348.         return new Vector3(v.x, v.y, v.z);
  349.     }
  350.  
  351.     public static implicit operator int[](VectorI3 v) {
  352.         return new int[] { v.x, v.y, v.z };
  353.     }
  354.  
  355.     public override bool Equals(object obj) {
  356.         if(obj.GetType() == typeof(VectorI3)) {
  357.             VectorI3 v = (VectorI3)obj;
  358.             return this.x == v.x && this.y == v.y && this.z == v.z;
  359.         }
  360.  
  361.         return false;
  362.     }
  363.     public override int GetHashCode() {
  364.         return base.GetHashCode();
  365.     }
  366.     public override string ToString() {
  367.         return "(" + x + ", " + y + ", " + z + ")";
  368.     }
  369.     #endregion
  370. }
  371.  
  372. [System.Serializable]
  373. public struct VectorI2 {
  374.     #region Constants
  375.     public static readonly VectorI2 one = new VectorI2(1, 1);
  376.     public static readonly VectorI2 negativeOne = new VectorI2(-1, -1);
  377.     public static readonly VectorI2 zero = new VectorI2(0, 0);
  378.     public static readonly VectorI2 left = new VectorI2(-1, 0);
  379.     public static readonly VectorI2 right = new VectorI2(1, 0);
  380.     public static readonly VectorI2 up = new VectorI2(0, 1);
  381.     public static readonly VectorI2 top = new VectorI2(0, 1);
  382.     public static readonly VectorI2 down = new VectorI2(0, -1);
  383.     public static readonly VectorI2 bottom = new VectorI2(0, -1);
  384.     #endregion
  385.  
  386.     public int x, y;
  387.     public int this[int index] {
  388.         get {
  389.             switch(index) {
  390.                 default: return x;
  391.                 case 1: return y;
  392.             }
  393.         }
  394.         set {
  395.             switch(index) {
  396.                 default: x = value; break;
  397.                 case 1: y = value; break;
  398.             }
  399.         }
  400.     }
  401.  
  402.     public VectorI2(int x, int y) {
  403.         this.x = x;
  404.         this.y = y;
  405.     }
  406.     public VectorI2(float x, float y) {
  407.         this.x = (int)x;
  408.         this.y = (int)y;
  409.     }
  410.     public VectorI2(VectorI2 vector) {
  411.         this.x = vector.x;
  412.         this.y = vector.y;
  413.     }
  414.     public VectorI2(Vector2 vector) {
  415.         this.x = (int)vector.x;
  416.         this.y = (int)vector.y;
  417.     }
  418.  
  419.     #region VectorI2 / Vector3 Methods
  420.  
  421.     public static VectorI2 GridCeil(Vector2 v, Vector2 roundBy) {
  422.         return Round(new Vector2(
  423.             Mathf.Ceil(v.x / roundBy.x) * roundBy.x,
  424.             Mathf.Ceil(v.y / roundBy.y) * roundBy.y
  425.             ));
  426.     }
  427.     public static VectorI2 GridFloor(Vector2 v, Vector2 roundBy) {
  428.         return Round(new Vector2(
  429.             Mathf.Floor(v.x / roundBy.x) * roundBy.x,
  430.             Mathf.Floor(v.y / roundBy.y) * roundBy.y
  431.             ));
  432.     }
  433.     public static VectorI2 GridRound(Vector2 v, Vector2 roundBy) {
  434.         return Round(new Vector2(
  435.             Mathf.Round(v.x / roundBy.x) * roundBy.x,
  436.             Mathf.Round(v.y / roundBy.y) * roundBy.y
  437.             ));
  438.     }
  439.  
  440.     public static VectorI2 Ceil(Vector2 v) {
  441.         return new VectorI2(Mathf.CeilToInt(v.x), Mathf.CeilToInt(v.y));
  442.     }
  443.     public static VectorI2 Floor(Vector2 v) {
  444.         return new VectorI2(Mathf.FloorToInt(v.x), Mathf.FloorToInt(v.y));
  445.     }
  446.     public static VectorI2 Round(Vector2 v) {
  447.         return new VectorI2(Mathf.RoundToInt(v.x), Mathf.RoundToInt(v.y));
  448.     }
  449.  
  450.     public int size {
  451.         get { return Size(this); }
  452.     }
  453.     public static int Size(VectorI2 v) {
  454.         return v.x * v.y;
  455.     }
  456.  
  457.     public static VectorI2 Wrap2DIndex(VectorI2 positionIndex, VectorI2 direction, VectorI2 arraySize) {
  458.         VectorI2 newDirection = new VectorI2(
  459.             ((positionIndex.x + direction.x) % (arraySize.x)),
  460.             ((positionIndex.y + direction.y) % (arraySize.y))
  461.             );
  462.  
  463.         if(newDirection.x < 0) { newDirection.x = arraySize.x + newDirection.x; }
  464.         if(newDirection.y < 0) { newDirection.y = arraySize.y + newDirection.y; }
  465.  
  466.         return newDirection;
  467.     }
  468.  
  469.     public static bool AnyGreater(VectorI2 a, VectorI2 b) {
  470.         return a.x > b.x || a.y > b.y;
  471.     }
  472.     public static bool AllGreater(VectorI2 a, VectorI2 b) {
  473.         return a.x > b.x && a.y > b.y;
  474.     }
  475.     public static bool AnyLower(VectorI2 a, VectorI2 b) {
  476.         return a.x < b.x || a.y < b.y;
  477.     }
  478.     public static bool AllLower(VectorI2 a, VectorI2 b) {
  479.         return a.x < b.x && a.y < b.y;
  480.     }
  481.     public static bool AnyGreaterAllEqual(VectorI2 a, VectorI2 b) {
  482.         return a == b || AnyGreater(a, b);
  483.     }
  484.     public static bool AllGreaterEqual(VectorI2 a, VectorI2 b) {
  485.         return a == b || AllGreater(a, b);
  486.     }
  487.     public static bool AnyLowerEqual(VectorI2 a, VectorI2 b) {
  488.         return a == b || AnyLower(a, b);
  489.     }
  490.     public static bool AllLowerEqual(VectorI2 a, VectorI2 b) {
  491.         return a == b || AllLower(a, b);
  492.     }
  493.  
  494.     public static VectorI2 Max(VectorI2 lhs, VectorI2 rhs) {
  495.         return new VectorI2(Mathf.Max(lhs.x, rhs.x), Mathf.Max(lhs.y, rhs.y));
  496.     }
  497.     public static VectorI2 Min(VectorI2 lhs, VectorI2 rhs) {
  498.         return new VectorI2(Mathf.Min(lhs.x, rhs.x), Mathf.Min(lhs.y, rhs.y));
  499.     }
  500.     #endregion
  501.  
  502.     #region Advanced
  503.     public static VectorI2 operator -(VectorI2 a) {
  504.         return new VectorI2(-a.x, -a.y);
  505.     }
  506.     public static VectorI2 operator -(VectorI2 a, VectorI2 b) {
  507.         return new VectorI2(a.x - b.x, a.y - b.y);
  508.     }
  509.     public static Vector2 operator -(Vector3 a, VectorI2 b) {
  510.         return new Vector2(a.x - b.x, a.y - b.y);
  511.     }
  512.     public static Vector2 operator -(VectorI2 a, Vector2 b) {
  513.         return new Vector2(a.x - b.x, a.y - b.y);
  514.     }
  515.  
  516.     public static bool operator !=(VectorI2 lhs, VectorI2 rhs) {
  517.         return lhs.x != rhs.x && lhs.y != rhs.y;
  518.     }
  519.     public static bool operator !=(Vector2 lhs, VectorI2 rhs) {
  520.         return lhs.x != rhs.x && lhs.y != rhs.y;
  521.     }
  522.     public static bool operator !=(VectorI2 lhs, Vector2 rhs) {
  523.         return lhs.x != rhs.x && lhs.y != rhs.y;
  524.     }
  525.  
  526.     public static Vector2 operator *(float d, VectorI2 a) {
  527.         return new Vector2(d * a.x, d * a.y);
  528.     }
  529.     public static Vector2 operator *(VectorI2 a, float d) {
  530.         return new Vector2(a.x * d, a.y * d);
  531.     }
  532.     public static Vector2 operator /(VectorI2 a, float d) {
  533.         return new Vector2(a.x / d, a.y / d);
  534.     }
  535.     public static float operator /(float d, VectorI2 a) {
  536.         d /= a.x; d /= a.y;
  537.         return d;
  538.     }
  539.  
  540.     public static VectorI2 operator *(VectorI2 a, VectorI2 b) {
  541.         return new VectorI2(a.x * b.x, a.y * b.y);
  542.     }
  543.     public static Vector2 operator *(Vector2 a, VectorI2 b) {
  544.         return new Vector2(a.x * b.x, a.y * b.y);
  545.     }
  546.     public static Vector2 operator *(VectorI2 a, Vector2 b) {
  547.         return new Vector2(a.x * b.x, a.y * b.y);
  548.     }
  549.  
  550.     public static VectorI2 operator /(VectorI2 a, VectorI2 b) {
  551.         return new VectorI2(a.x / b.x, a.y / b.y);
  552.     }
  553.     public static Vector2 operator /(Vector2 a, VectorI2 b) {
  554.         return new Vector2(a.x / b.x, a.y / b.y);
  555.     }
  556.     public static Vector2 operator /(VectorI2 a, Vector2 b) {
  557.         return new Vector2(a.x / b.x, a.y / b.y);
  558.     }
  559.  
  560.     public static VectorI3 operator +(VectorI2 a, VectorI3 b) {
  561.         return new VectorI3(a.x + b.x, a.y + b.y, b.z);
  562.     }
  563.     public static VectorI3 operator +(VectorI3 a, VectorI2 b) {
  564.         return new VectorI3(a.x + b.x, a.y + b.y, a.z);
  565.     }
  566.     public static Vector3 operator +(VectorI2 a, Vector3 b) {
  567.         return new VectorI3(a.x + b.x, a.y + b.y, b.z);
  568.     }
  569.     public static Vector3 operator +(Vector3 a, VectorI2 b) {
  570.         return new VectorI3(a.x + b.x, a.y + b.y, a.z);
  571.     }
  572.     public static VectorI2 operator +(VectorI2 a, VectorI2 b) {
  573.         return new VectorI2(a.x + b.x, a.y + b.y);
  574.     }
  575.     public static Vector2 operator +(Vector2 a, VectorI2 b) {
  576.         return new Vector2(a.x + b.x, a.y + b.y);
  577.     }
  578.     public static Vector2 operator +(VectorI2 a, Vector2 b) {
  579.         return new Vector2(a.x + b.x, a.y + b.y);
  580.     }
  581.  
  582.     public static Vector2 operator +(VectorI2 a, float d) {
  583.         return new Vector2(a.x + d, a.y + d);
  584.     }
  585.  
  586.     public static bool operator ==(VectorI2 lhs, VectorI2 rhs) {
  587.         return lhs.x == rhs.x && lhs.y == rhs.y;
  588.     }
  589.     public static bool operator ==(Vector2 lhs, VectorI2 rhs) {
  590.         return lhs.x == rhs.x && lhs.y == rhs.y;
  591.     }
  592.     public static bool operator ==(VectorI2 lhs, Vector2 rhs) {
  593.         return lhs.x == rhs.x && lhs.y == rhs.y;
  594.     }
  595.  
  596.     public static implicit operator VectorI2(VectorI3 v) {
  597.         return new VectorI2(v.x, v.y);
  598.     }
  599.     public static implicit operator VectorI3(VectorI2 v) {
  600.         return new VectorI3(v.x, v.y, 0);
  601.     }
  602.     public static implicit operator VectorI2(Vector2 v) {
  603.         return new VectorI2(v);
  604.     }
  605.     public static implicit operator VectorI2(Vector4 v) {
  606.         return new VectorI2(v.x, v.y);
  607.     }
  608.     public static implicit operator Vector2(VectorI2 v) {
  609.         return new Vector2(v.x, v.y);
  610.     }
  611.     public static implicit operator Vector3(VectorI2 v) {
  612.         return new Vector3(v.x, v.y, 0);
  613.     }
  614.     public static implicit operator Vector4(VectorI2 v) {
  615.         return new Vector4(v.x, v.y, 0);
  616.     }
  617.  
  618.     public override bool Equals(object obj) {
  619.         if(obj.GetType() == typeof(VectorI2)) {
  620.             VectorI2 v = (VectorI2)obj;
  621.             return this.x == v.x && this.y == v.y;
  622.         }
  623.  
  624.         return false;
  625.     }
  626.     public override int GetHashCode() {
  627.         return base.GetHashCode();
  628.     }
  629.     public override string ToString() {
  630.         return "(" + x + ", " + y + ")";
  631.     }
  632.     #endregion
  633. }
  634.  
  635. /*class VectorIComparer : IEqualityComparer<VectorI3> {
  636.     public bool Equals(VectorI3 a, VectorI3 b) {
  637.         return (a.x == b.x) && (a.y == b.y) && (a.z == b.z);
  638.     }
  639.     public int GetHashCode(VectorI3 a) {
  640.         return base.GetHashCode();
  641.     }
  642. }
  643.  
  644. class VectorI2Comparer : IEqualityComparer<VectorI2> {
  645.     public bool Equals(VectorI2 a, VectorI2 b) {
  646.         return (a.x == b.x) && (a.y == b.y);
  647.     }
  648.     public int GetHashCode(VectorI2 a) {
  649.         return base.GetHashCode();
  650.     }
  651. }*/
Advertisement
Add Comment
Please, Sign In to add comment