Vector2.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2022-08-05
  6. * Changed: 2022-08-05
  7. *
  8. * */
  9. #include <ls-math/vector/Vector2.hpp>
  10. #include <math.h>
  11. ls::math::vector::Vector2::Vector2(const ls::math::core::type::vector2_component &_x, const ls::math::core::type::vector2_component &_y)
  12. {
  13. this->components[0] = _x;
  14. this->components[1] = _y;
  15. }
  16. ls::math::vector::Vector2 ls::math::vector::Vector2::operator+(ls::math::vector::Vector2 _vector)
  17. {
  18. ls::math::vector::Vector2 calculatedVector{0, 0};
  19. calculatedVector.setX(this->components[0] + _vector.getX());
  20. calculatedVector.setY(this->components[1] + _vector.getY());
  21. return calculatedVector;
  22. }
  23. ls::math::vector::Vector2 ls::math::vector::Vector2::operator-(ls::math::vector::Vector2 _vector)
  24. {
  25. ls::math::vector::Vector2 calculatedVector{0, 0};
  26. calculatedVector.setX(this->components[0] - _vector.getX());
  27. calculatedVector.setY(this->components[1] - _vector.getY());
  28. return calculatedVector;
  29. }
  30. ls::math::core::type::vector_scalar ls::math::vector::Vector2::operator*(ls::math::vector::Vector2 _vector)
  31. {
  32. return this->components[0] * _vector.getX() + this->components[1] * _vector.getY();
  33. }
  34. ls::math::vector::Vector2 ls::math::vector::Vector2::operator*(double _value)
  35. {
  36. ls::math::vector::Vector2 calculatedVector{0, 0};
  37. calculatedVector.setX(components[0] * _value);
  38. calculatedVector.setY(components[1] * _value);
  39. return calculatedVector;
  40. }
  41. bool ls::math::vector::Vector2::operator==(const ls::math::vector::Vector2 &_vector)
  42. {
  43. return this->components[0] == _vector.components[0] && this->components[1] == _vector.components[1];
  44. }
  45. bool ls::math::vector::Vector2::operator!=(const ls::math::vector::Vector2 &_vector)
  46. {
  47. return this->components[0] != _vector.components[0] || this->components[1] != _vector.components[1];
  48. }
  49. double ls::math::vector::Vector2::getLength()
  50. {
  51. return sqrt(this->components[0] * this->components[0] + this->components[1] * this->components[1]);
  52. }
  53. ls::math::core::type::vector2_component ls::math::vector::Vector2::getX()
  54. {
  55. return this->components[0];
  56. }
  57. ls::math::core::type::vector2_component ls::math::vector::Vector2::getY()
  58. {
  59. return this->components[1];
  60. }
  61. void ls::math::vector::Vector2::setX(const ls::math::core::type::vector2_component &_value)
  62. {
  63. this->components[0] = _value;
  64. }
  65. void ls::math::vector::Vector2::setY(const ls::math::core::type::vector2_component &_value)
  66. {
  67. this->components[1] = _value;
  68. }