RealWorldTerrainVector2i.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* INFINITY CODE 2013-2019 */
  2. /* http://www.infinity-code.com */
  3. using System;
  4. using UnityEngine;
  5. namespace InfinityCode.RealWorldTerrain
  6. {
  7. /// <summary>
  8. /// Integer version of Vector2 struct.
  9. /// </summary>
  10. [Serializable]
  11. public struct RealWorldTerrainVector2i
  12. {
  13. /// <summary>
  14. /// Gets the RealWorldTerrainVector2i where x=1 and y=1.
  15. /// </summary>
  16. public static RealWorldTerrainVector2i one
  17. {
  18. get
  19. {
  20. return new RealWorldTerrainVector2i(1, 1);
  21. }
  22. }
  23. /// <summary>
  24. /// The x value.
  25. /// </summary>
  26. public int x;
  27. /// <summary>
  28. /// The y value.
  29. /// </summary>
  30. public int y;
  31. /// <summary>
  32. /// Returns the count items (X * Y).
  33. /// </summary>
  34. public int count
  35. {
  36. get { return x * y; }
  37. }
  38. /// <summary>
  39. /// Returns the maximum value of x and y.
  40. /// </summary>
  41. public int max
  42. {
  43. get { return Mathf.Max(x, y); }
  44. }
  45. /// <summary>
  46. /// Constructor.
  47. /// </summary>
  48. /// <param name="X">X value.</param>
  49. /// <param name="Y">Y value.</param>
  50. public RealWorldTerrainVector2i(int X = 0, int Y = 0)
  51. {
  52. x = X;
  53. y = Y;
  54. }
  55. public override string ToString()
  56. {
  57. return string.Format("X: {0}, Y: {1}", x, y);
  58. }
  59. public static implicit operator Vector2(RealWorldTerrainVector2i val)
  60. {
  61. return new Vector2(val.x, val.y);
  62. }
  63. public static implicit operator int(RealWorldTerrainVector2i val)
  64. {
  65. return val.count;
  66. }
  67. public static RealWorldTerrainVector2i operator +(RealWorldTerrainVector2i v1, RealWorldTerrainVector2i v2)
  68. {
  69. return new RealWorldTerrainVector2i(v1.x + v2.x, v1.y + v2.y);
  70. }
  71. public static RealWorldTerrainVector2i operator -(RealWorldTerrainVector2i v1, RealWorldTerrainVector2i v2)
  72. {
  73. return new RealWorldTerrainVector2i(v1.x - v2.x, v1.y - v2.y);
  74. }
  75. }
  76. }