Ginger 1.1.5; VERSION ${PROJECT_VERSION}
Loading...
Searching...
No Matches
vector2_ref.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "vector2.hpp"
4
5#if __cpp_constexpr >= 201304
6# define CONSTEXPR14 constexpr
7#else
8# define CONSTEXPR14 inline
9#endif
10
11static double global_vector2_ref_dummy = 0.0;
12
13namespace ginger {
14
19 class Vector2Ref {
20 public:
21 double& _x;
22 double& _y;
23
29 constexpr Vector2Ref() noexcept
30 : _x{global_vector2_ref_dummy}, _y{global_vector2_ref_dummy} {}
31
44 constexpr Vector2Ref(double& x, double& y) noexcept : _x{x}, _y{y} {}
45
51 constexpr auto x() const noexcept -> const double& { return this->_x; }
52
58 constexpr auto y() const noexcept -> const double& { return this->_y; }
59
70 constexpr auto dot(const Vector2Ref& other) const -> double {
71 return this->_x * other._x + this->_y * other._y;
72 }
73
85 constexpr auto cross(const Vector2Ref& other) const -> double {
86 return this->_x * other._y - other._x * this->_y;
87 }
88
93
104 this->_x += other.x();
105 this->_y += other.y();
106 return *this;
107 }
108
119 this->_x -= other.x();
120 this->_y -= other.y();
121 return *this;
122 }
123
133 CONSTEXPR14 auto operator*=(const double& alpha) -> Vector2Ref& {
134 this->_x *= alpha;
135 this->_y *= alpha;
136 return *this;
137 }
138
149 CONSTEXPR14 auto operator/=(const double& alpha) -> Vector2Ref& {
150 this->_x /= alpha;
151 this->_y /= alpha;
152 return *this;
153 }
154
162 CONSTEXPR14 auto operator*(const double& alpha) const -> Vector2<double, double> {
163 return Vector2<double, double>{this->x() * alpha, this->y() * alpha};
164 }
165
167
180 template <class Stream> friend auto operator<<(Stream& out, const Vector2Ref& vec)
181 -> Stream& {
182 out << "{" << vec.x() << ", " << vec.y() << "}";
183 return out;
184 }
185 };
186} // namespace ginger
Vector2Ref.
Definition vector2_ref.hpp:19
CONSTEXPR14 auto operator-=(const Vector2< double, double > &other) -> Vector2Ref &
Definition vector2_ref.hpp:118
constexpr Vector2Ref() noexcept
Construct a new Vector2Ref object.
Definition vector2_ref.hpp:29
constexpr auto y() const noexcept -> const double &
Definition vector2_ref.hpp:58
constexpr auto x() const noexcept -> const double &
Definition vector2_ref.hpp:51
CONSTEXPR14 auto operator/=(const double &alpha) -> Vector2Ref &
Definition vector2_ref.hpp:149
constexpr auto dot(const Vector2Ref &other) const -> double
Definition vector2_ref.hpp:70
constexpr auto cross(const Vector2Ref &other) const -> double
Definition vector2_ref.hpp:85
constexpr Vector2Ref(double &x, double &y) noexcept
Construct a new Vector2Ref object.
Definition vector2_ref.hpp:44
CONSTEXPR14 auto operator*=(const double &alpha) -> Vector2Ref &
Definition vector2_ref.hpp:133
double & _x
Definition vector2_ref.hpp:21
CONSTEXPR14 auto operator+=(const Vector2< double, double > &other) -> Vector2Ref &
Definition vector2_ref.hpp:103
CONSTEXPR14 auto operator*(const double &alpha) const -> Vector2< double, double >
Definition vector2_ref.hpp:162
friend auto operator<<(Stream &out, const Vector2Ref &vec) -> Stream &
Definition vector2_ref.hpp:180
double & _y
Definition vector2_ref.hpp:22
Vector2.
Definition vector2.hpp:19
#define CONSTEXPR14
Definition matrix2.hpp:15
Definition logger.hpp:10