shooter/engine/math/Vec2D.h

53 lines
1.3 KiB
C
Raw Normal View History

//
// Created by Иван Ильин on 10.10.2021.
//
#ifndef SHOOTER_VEC2D_H
#define SHOOTER_VEC2D_H
#include <array>
2021-10-31 11:39:08 +03:00
2021-10-28 16:58:02 +03:00
#include "Vec4D.h"
class Vec2D final {
private:
std::array<double, 2> _arr_point{};
public:
2021-10-31 11:39:08 +03:00
Vec2D() = default;
Vec2D(const Vec2D &vec);
explicit Vec2D(const Vec4D &point4D);
explicit Vec2D(double x, double y = 0.0);
Vec2D &operator=(const Vec2D &) = default;
[[nodiscard]] double x() const { return _arr_point[0]; }
[[nodiscard]] double y() const { return _arr_point[1]; }
[[nodiscard]] Vec2D operator-() const;
// Boolean operations
2021-10-31 11:39:08 +03:00
bool operator==(const Vec2D &vec) const;
bool operator!=(const Vec2D &vec) const;
2021-10-31 11:39:08 +03:00
[[nodiscard]] Vec2D operator+(const Vec2D &vec) const;
[[nodiscard]] Vec2D operator-(const Vec2D &vec) const;
2021-10-31 11:39:08 +03:00
[[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