2021-10-12 17:12:47 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 10.10.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef SHOOTER_VEC2D_H
|
|
|
|
#define SHOOTER_VEC2D_H
|
|
|
|
|
|
|
|
#include <array>
|
2021-10-28 16:58:02 +03:00
|
|
|
#include "Vec4D.h"
|
2021-10-12 17:12:47 +03:00
|
|
|
|
2021-10-12 20:18:56 +03:00
|
|
|
class Vec2D final {
|
2021-10-12 17:12:47 +03:00
|
|
|
private:
|
|
|
|
std::array<double, 2> _arr_point{};
|
|
|
|
|
|
|
|
public:
|
|
|
|
Vec2D () = default;
|
|
|
|
Vec2D (const Vec2D& vec);
|
2021-10-28 16:58:02 +03:00
|
|
|
explicit Vec2D (const Vec4D& point4D);
|
2021-10-12 17:12:47 +03:00
|
|
|
explicit Vec2D (double x, double y = 0.0);
|
2021-10-28 16:58:02 +03:00
|
|
|
Vec2D& operator=(const Vec2D&) = default;
|
2021-10-12 17:12:47 +03:00
|
|
|
|
|
|
|
[[nodiscard]] double x() const { return _arr_point[0]; }
|
|
|
|
[[nodiscard]] double y() const { return _arr_point[1]; }
|
|
|
|
|
|
|
|
[[nodiscard]] Vec2D operator-() const;
|
|
|
|
|
|
|
|
// Boolean operations
|
|
|
|
bool operator==(const Vec2D& vec) const;
|
|
|
|
bool operator!=(const Vec2D& vec) const;
|
|
|
|
|
|
|
|
[[nodiscard]] Vec2D operator+(const Vec2D& vec) const;
|
|
|
|
[[nodiscard]] Vec2D operator-(const Vec2D& vec) const;
|
|
|
|
|
|
|
|
[[nodiscard]] double dot(const Vec2D& vec) const; // Returns dot product
|
|
|
|
|
|
|
|
// Operations with numbers
|
|
|
|
[[nodiscard]] Vec2D operator*(double number) const;
|
|
|
|
[[nodiscard]] Vec2D operator/(double number) const;
|
|
|
|
|
|
|
|
// Other useful methods
|
|
|
|
[[nodiscard]] double sqrAbs() const; // Returns squared vector length
|
|
|
|
[[nodiscard]] double abs() const; // Returns vector length
|
|
|
|
[[nodiscard]] Vec2D normalized() const; // Returns normalized vector without changing
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //SHOOTER_VEC2D_H
|