Vector2.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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-07
  7. *
  8. * */
  9. #ifndef LS_MATH_VECTOR2_HPP
  10. #define LS_MATH_VECTOR2_HPP
  11. #include <ls-math/core/types/VectorTypes.hpp>
  12. #include <cstdlib>
  13. namespace ls::math::vector
  14. {
  15. class Vector2
  16. {
  17. public:
  18. Vector2(const ls::math::core::type::vector2_component& _x, const ls::math::core::type::vector2_component& _y);
  19. ~Vector2() = default;
  20. // arithmetic operations
  21. ls::math::vector::Vector2 operator+(const ls::math::vector::Vector2& _vector) const;
  22. ls::math::vector::Vector2 operator-(const ls::math::vector::Vector2& _vector) const;
  23. ls::math::core::type::vector_scalar operator*(const ls::math::vector::Vector2& _vector) const;
  24. ls::math::vector::Vector2 operator*(double _value);
  25. ls::math::vector::Vector2 operator/(double _divisor);
  26. // comparison operations
  27. bool operator==(const Vector2& _vector);
  28. bool operator!=(const Vector2& _vector);
  29. // additional functionality
  30. static ls::math::vector::Vector2 add(const ls::math::vector::Vector2& _leftAddend, const ls::math::vector::Vector2& _rightAddend);
  31. static ls::math::core::type::vector_scalar dot(const ls::math::vector::Vector2& _leftAddend, const ls::math::vector::Vector2& _rightAddend);
  32. ls::math::core::type::vector2_components getComponents();
  33. double getLength();
  34. ls::math::core::type::vector2_component getX();
  35. ls::math::core::type::vector2_component getY();
  36. ls::math::vector::Vector2 normalize();
  37. void setX(const ls::math::core::type::vector2_component& _value);
  38. void setY(const ls::math::core::type::vector2_component& _value);
  39. static ls::math::vector::Vector2 subtract(const ls::math::vector::Vector2& _leftAddend, const ls::math::vector::Vector2& _rightAddend);
  40. private:
  41. ls::math::core::type::vector2_components components{};
  42. static ls::math::vector::Vector2 _add(const ls::math::vector::Vector2& _leftAddend, const ls::math::vector::Vector2& _rightAddend);
  43. static ls::math::core::type::vector_scalar _dot(const ls::math::vector::Vector2& _leftAddend, const ls::math::vector::Vector2& _rightAddend);
  44. static double _getLength(const ls::math::core::type::vector2_component& _x, const ls::math::core::type::vector2_component& _y);
  45. static ls::math::vector::Vector2 _operatorDivision(const ls::math::core::type::vector2_component& _x, const ls::math::core::type::vector2_component& _y, double _divisor);
  46. static ls::math::vector::Vector2 _subtract(const ls::math::vector::Vector2& _leftAddend, const ls::math::vector::Vector2& _rightAddend);
  47. };
  48. }
  49. #endif