Vector2.hpp 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Author: Patrick-Christopher Mattulat
  3. * Company: Lynar Studios
  4. * E-Mail: webmaster@lynarstudios.com
  5. * Created: 2022-08-05
  6. * Changed: 2023-06-02
  7. *
  8. * */
  9. #ifndef LS_MATH_VECTOR2_HPP
  10. #define LS_MATH_VECTOR2_HPP
  11. #include <cstdlib>
  12. #include <ls-math/core/types/VectorTypes.hpp>
  13. #include <ls-math/os/dynamic-goal.hpp>
  14. namespace ls::math::vector
  15. {
  16. class LS_MATH_DYNAMIC_GOAL Vector2
  17. {
  18. public:
  19. Vector2(const ls::math::core::type::vector2_component &_x, const ls::math::core::type::vector2_component &_y);
  20. ~Vector2() = default;
  21. // arithmetic operations
  22. ls::math::vector::Vector2 operator+(const ls::math::vector::Vector2 &_vector) const;
  23. ls::math::vector::Vector2 operator-(const ls::math::vector::Vector2 &_vector) const;
  24. ls::math::core::type::vector_scalar operator*(const ls::math::vector::Vector2 &_vector) const;
  25. ls::math::vector::Vector2 operator*(double _value);
  26. ls::math::vector::Vector2 operator/(double _divisor);
  27. // comparison operations
  28. bool operator==(const Vector2 &_vector);
  29. bool operator!=(const Vector2 &_vector);
  30. // additional functionality
  31. [[nodiscard]] static ls::math::vector::Vector2 add(const ls::math::vector::Vector2 &_leftAddend, const ls::math::vector::Vector2 &_rightAddend);
  32. [[nodiscard]] static ls::math::core::type::vector_scalar dot(const ls::math::vector::Vector2 &_leftAddend, const ls::math::vector::Vector2 &_rightAddend);
  33. [[nodiscard]] ls::math::core::type::vector2_components getComponents() const;
  34. [[nodiscard]] double getLength();
  35. [[nodiscard]] ls::math::core::type::vector2_component getX();
  36. [[nodiscard]] ls::math::core::type::vector2_component getY();
  37. [[nodiscard]] ls::math::vector::Vector2 normalize();
  38. void setX(const ls::math::core::type::vector2_component &_value);
  39. void setY(const ls::math::core::type::vector2_component &_value);
  40. [[nodiscard]] static ls::math::vector::Vector2 subtract(const ls::math::vector::Vector2 &_leftAddend, const ls::math::vector::Vector2 &_rightAddend);
  41. private:
  42. ls::math::core::type::vector2_components components{};
  43. [[nodiscard]] static ls::math::vector::Vector2 _add(const ls::math::vector::Vector2 &_leftAddend, const ls::math::vector::Vector2 &_rightAddend);
  44. [[nodiscard]] static ls::math::core::type::vector_scalar _dot(const ls::math::vector::Vector2 &_leftAddend, const ls::math::vector::Vector2 &_rightAddend);
  45. [[nodiscard]] static double _getLength(const ls::math::core::type::vector2_component &_x, const ls::math::core::type::vector2_component &_y);
  46. [[nodiscard]] static ls::math::vector::Vector2 _operatorDivision(const ls::math::core::type::vector2_component &_x, const ls::math::core::type::vector2_component &_y, double _divisor);
  47. [[nodiscard]] static ls::math::vector::Vector2 _subtract(const ls::math::vector::Vector2 &_leftAddend, const ls::math::vector::Vector2 &_rightAddend);
  48. };
  49. }
  50. #endif