10#if __cpp_constexpr >= 201304
11# define CONSTEXPR14 constexpr
13# define CONSTEXPR14 inline
28 template <
typename T1,
typename T2 = T1>
class Vector2 {
46 constexpr Vector2(T1 vec_x, T2 vec_y) noexcept
47 : _x{std::move(vec_x)}, _y{std::move(vec_y)} {}
61 template <
typename U1,
typename U2>
63 : _x(other_vector.
x()), _y(other_vector.
y()) {}
72 constexpr auto x() const noexcept -> const T1& {
return this->_x; }
81 constexpr auto y() const noexcept -> const T2& {
return this->_y; }
95 template <
typename U1,
typename U2>
97 return this->_x * other_vector._y - other_vector._x * this->_y;
117 template <
typename U1,
typename U2>
119 return std::tie(this->
x(), this->
y()) == std::tie(other_vector.x(), other_vector.y());
134 template <
typename U1,
typename U2>
136 return !(*
this == other_vector);
161 template <
typename U1,
typename U2>
163 this->_x += other_vector.
x();
164 this->_y += other_vector.y();
176 template <
typename U1,
typename U2>
178 this->_x -= other_vector.
x();
179 this->_y -= other_vector.y();
218 template <
typename U1,
typename U2>
221 return right_vector += left_vector;
233 template <
typename U1,
typename U2>
236 return right_vector -= left_vector;
247 template <
typename R>
friend constexpr auto operator*(
Vector2 right_vector,
const R& scalar)
249 return right_vector *= scalar;
260 template <
typename R>
friend constexpr auto operator*(
const R& scalar,
Vector2 left_vector)
262 return left_vector *= scalar;
273 template <
typename R>
friend constexpr auto operator/(
Vector2 right_vector,
const R& scalar)
275 return right_vector /= scalar;
290 output_stream <<
"{" << vector.x() <<
", " << vector.y() <<
"}";
291 return output_stream;
2D vector template class.
Definition vector2.hpp:28
friend constexpr auto operator*(const R &scalar, Vector2 left_vector) -> Vector2
Multiply the components of the given vector by the scalar.
Definition vector2.hpp:260
CONSTEXPR14 auto operator*=(const R &scalar) -> Vector2 &
Multiply the components of this vector by the given scalar.
Definition vector2.hpp:190
friend constexpr auto operator+(Vector2 right_vector, const Vector2< U1, U2 > &left_vector) -> Vector2
Add the components of the given vector to this vector.
Definition vector2.hpp:219
constexpr auto x() const noexcept -> const T1 &
Returns a const reference to the x-coordinate of the vector.
Definition vector2.hpp:72
constexpr auto y() const noexcept -> const T2 &
Returns a const reference to the y-coordinate of the vector.
Definition vector2.hpp:81
constexpr auto operator==(const Vector2< U1, U2 > &other_vector) const -> bool
Compares two Vector2 objects for equality.
Definition vector2.hpp:118
constexpr auto cross(const Vector2< U1, U2 > &other_vector) const
Calculates the cross product of two Vector2 objects.
Definition vector2.hpp:96
friend constexpr auto operator-(Vector2 right_vector, const Vector2< U1, U2 > &left_vector) -> Vector2
Subtract the components of the given vector from this vector.
Definition vector2.hpp:234
CONSTEXPR14 auto operator+=(const Vector2< U1, U2 > &other_vector) -> Vector2 &
Add the components of the given vector to this vector.
Definition vector2.hpp:162
friend constexpr auto operator*(Vector2 right_vector, const R &scalar) -> Vector2
Multiply the components of this vector by the given scalar.
Definition vector2.hpp:247
constexpr Vector2(T1 vec_x, T2 vec_y) noexcept
Construct a new Vector2 object.
Definition vector2.hpp:46
CONSTEXPR14 auto operator/=(const R &scalar) -> Vector2 &
Divide the components of this vector by the given scalar.
Definition vector2.hpp:203
friend constexpr auto operator/(Vector2 right_vector, const R &scalar) -> Vector2
Divide the components of this vector by the given scalar.
Definition vector2.hpp:273
constexpr auto operator!=(const Vector2< U1, U2 > &other_vector) const -> bool
Compares two Vector2 objects for inequality.
Definition vector2.hpp:135
CONSTEXPR14 auto operator-=(const Vector2< U1, U2 > &other_vector) -> Vector2 &
Subtract the components of the given vector from this vector.
Definition vector2.hpp:177
constexpr Vector2(const Vector2< U1, U2 > &other_vector)
Construct a new Vector2 object.
Definition vector2.hpp:62
constexpr auto operator-() const -> Vector2
Negate the vector, returning a new vector with the negated components.
Definition vector2.hpp:151
friend auto operator<<(Stream &output_stream, const Vector2 &vector) -> Stream &
Overload the stream insertion operator to print a Vector2 object.
Definition vector2.hpp:288
Definition svg_utils.hpp:12
#define CONSTEXPR14
Definition vector2.hpp:13