Line data Source code
1 : #ifndef ECFFF655_38C8_4C6D_AF35_3FE9EF600169_HPP 2 : #define ECFFF655_38C8_4C6D_AF35_3FE9EF600169_HPP 3 : 4 : #include <ostream> 5 : 6 : namespace cell 7 : { 8 : 9 : struct Vector2d 10 : { 11 : double x; 12 : double y; 13 : 14 715 : Vector2d() 15 715 : : x(0) 16 715 : , y(0) 17 : { 18 715 : } 19 : 20 462715 : Vector2d(double x, double y) 21 462715 : : x(x) 22 462715 : , y(y) 23 : { 24 462715 : } 25 : 26 462385 : Vector2d& operator+=(const Vector2d& rhs) noexcept 27 : { 28 462385 : x += rhs.x; 29 462385 : y += rhs.y; 30 462385 : return *this; 31 : } 32 : 33 825151 : Vector2d& operator-=(const Vector2d& rhs) noexcept 34 : { 35 825151 : x -= rhs.x; 36 825151 : y -= rhs.y; 37 825151 : return *this; 38 : } 39 : 40 69 : Vector2d& operator*=(double s) noexcept 41 : { 42 69 : x *= s; 43 69 : y *= s; 44 69 : return *this; 45 : } 46 : 47 20 : Vector2d& operator/=(double s) noexcept 48 : { 49 20 : x /= s; 50 20 : y /= s; 51 20 : return *this; 52 : } 53 : }; 54 : 55 10 : inline Vector2d operator+(Vector2d lhs, const Vector2d& rhs) noexcept 56 : { 57 10 : return lhs += rhs; 58 : } 59 : 60 825151 : inline Vector2d operator-(Vector2d lhs, const Vector2d& rhs) noexcept 61 : { 62 825151 : return lhs -= rhs; 63 : } 64 : 65 36 : inline Vector2d operator*(Vector2d v, double s) noexcept 66 : { 67 36 : return v *= s; 68 : } 69 : 70 31 : inline Vector2d operator*(double s, Vector2d v) noexcept 71 : { 72 31 : return v *= s; 73 : } 74 : 75 20 : inline Vector2d operator/(Vector2d v, double s) noexcept 76 : { 77 20 : return v /= s; 78 : } 79 : 80 10 : inline double operator*(Vector2d lhs, const Vector2d& rhs) noexcept 81 : { 82 10 : return lhs.x * rhs.x + lhs.y * rhs.y; 83 : } 84 : 85 2 : inline std::ostream& operator<<(std::ostream& os, const Vector2d& v) 86 : { 87 2 : return os << "(" << v.x << ", " << v.y << ")"; 88 : } 89 : 90 3 : inline Vector2d operator-(Vector2d v) noexcept 91 : { 92 3 : return Vector2d{-v.x, -v.y}; 93 : } 94 : 95 : } // namespace cell 96 : 97 : #endif /* ECFFF655_38C8_4C6D_AF35_3FE9EF600169_HPP */