Vector2.pkg 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. $#include "Vector2.h"
  2. /// Two-dimensional vector.
  3. class Vector2
  4. {
  5. public:
  6. /// Construct undefined.
  7. Vector2();
  8. /// Copy-construct from another vector.
  9. Vector2(const Vector2& vector);
  10. /// Construct from coordinates.
  11. Vector2(float x, float y);
  12. /// Construct from a float array.
  13. Vector2(const float* data);
  14. /// Test for equality with another vector without epsilon.
  15. bool operator == (const Vector2& rhs) const;
  16. /// Add a vector.
  17. Vector2 operator + (const Vector2& rhs) const;
  18. /// Return negation.
  19. Vector2 operator - () const;
  20. /// Subtract a vector.
  21. Vector2 operator - (const Vector2& rhs) const;
  22. /// Multiply with a scalar.
  23. Vector2 operator * (float rhs) const;
  24. /// Multiply with a vector.
  25. Vector2 operator * (const Vector2& rhs) const;
  26. /// Divide by a scalar.
  27. Vector2 operator / (float rhs) const;
  28. /// Divide by a vector.
  29. Vector2 operator / (const Vector2& rhs) const;
  30. /// Normalize to unit length and return the previous length.
  31. float Normalize();
  32. /// Return length.
  33. float Length() const;
  34. /// Return squared length.
  35. float LengthSquared() const;
  36. /// Calculate dot product.
  37. float DotProduct(const Vector2& rhs) const;
  38. /// Calculate absolute dot product.
  39. float AbsDotProduct(const Vector2& rhs) const;
  40. /// Return absolute vector.
  41. Vector2 Abs() const;
  42. /// Linear interpolation with another vector.
  43. Vector2 Lerp(const Vector2& rhs, float t) const;
  44. /// Test for equality with another vector with epsilon.
  45. bool Equals(const Vector2& rhs) const;
  46. /// Return normalized to unit length.
  47. Vector2 Normalized() const;
  48. /// X coordinate.
  49. float x_ @ x;
  50. /// Y coordinate.
  51. float y_ @ y;
  52. /// Zero vector.
  53. static const Vector2 ZERO;
  54. /// (-1,0) vector.
  55. static const Vector2 LEFT;
  56. /// (1,0) vector.
  57. static const Vector2 RIGHT;
  58. /// (0,1) vector.
  59. static const Vector2 UP;
  60. /// (0,-1) vector.
  61. static const Vector2 DOWN;
  62. /// (1,1) vector.
  63. static const Vector2 ONE;
  64. };
  65. /// Two-dimensional vector with integer values.
  66. class IntVector2
  67. {
  68. public:
  69. /// Construct undefined.
  70. IntVector2();
  71. /// Construct from coordinates.
  72. IntVector2(int x, int y);
  73. /// Construct from an int array.
  74. IntVector2(const int* data);
  75. /// Copy-construct from another vector.
  76. IntVector2(const IntVector2& rhs);
  77. /// Test for equality with another vector.
  78. bool operator == (const IntVector2& rhs) const;
  79. /// Add a vector.
  80. IntVector2 operator + (const IntVector2& rhs) const;
  81. /// Return negation.
  82. IntVector2 operator - () const;
  83. /// Subtract a vector.
  84. IntVector2 operator - (const IntVector2& rhs) const;
  85. /// Multiply with a scalar.
  86. IntVector2 operator * (int rhs) const;
  87. /// Divide by a scalar.
  88. IntVector2 operator / (int rhs) const;
  89. /// X coordinate.
  90. int x_ @ x;
  91. /// Y coordinate.
  92. int y_ @ y;
  93. /// Zero vector.
  94. static const IntVector2 ZERO;
  95. };