|
|
Donner
C++20 SVG rendering library
|
A 2D vector, (x, y). More...
#include "donner/base/Vector2.h"
Public Member Functions | |
| Vector2 ()=default | |
| Default constructor for a zero vector. | |
| constexpr | Vector2 (T x, T y) |
| Construct a vector from a given x and y component. | |
| ~Vector2 ()=default | |
| Destructor. | |
| Vector2 (const Vector2< T > &other)=default | |
| Copy constructor. | |
| Vector2< T > & | operator= (const Vector2< T > &other)=default |
| Copy assignment operator. | |
| Vector2 (Vector2< T > &&other) noexcept=default | |
| Move constructor. | |
| Vector2< T > & | operator= (Vector2< T > &&other) noexcept=default |
| Move assignment operator. | |
| template<typename S> | |
| Vector2< T > & | operator= (const Vector2< S > &rhs) |
| Assignment operator from a vector of a different type. | |
| template<typename S> | |
| Vector2 (const Vector2< S > &other) | |
| Construct a vector from a vector of a different type, by implicitly casting each component. | |
| template<typename S> | |
| Vector2 (S x, S y) | |
| Construct a vector from components of a different type, by implicitly casting each component. | |
| T | length () const |
| Returns the length of the vector. | |
| T | lengthSquared () const |
| Returns the squared length of the vector. | |
| T | distance (const Vector2< T > &other) const |
| Returns the distance between two vectors, assuming that each represents a point in space. | |
| T | distanceSquared (const Vector2< T > &other) const |
| Returns the squared distance between two vectors, assuming that each represents a point in space. | |
| T | dot (const Vector2< T > &other) const |
Returns the dot product of this vector and other. | |
| T | cross (const Vector2< T > &other) const |
Returns the Z component of the cross product of this vecctor and other in the 2D plane. | |
| Vector2< T > | rotate (double radians) const |
Rotate this vector by radians. | |
| Vector2< T > | rotate (T cosResult, T sinResult) const |
| Rotate this vector by a given pre-computed cosine/sine angle. | |
| T | angle () const |
| Returns the angle that this vector makes with the +x axis, in radians. | |
| T | angleWith (const Vector2< T > &other) const |
| Returns the angle between this vector and the provided vector, or zero if one of the vectors has zero length. | |
| Vector2< T > | normalize () const |
| Returns the normalized form of this vector. | |
Static Public Member Functions | |
| static Vector2< T > | Zero () |
| Returns a vector with all components set to zero. | |
| static Vector2< T > | XAxis () |
| Returns a vector with for the x-axis, i.e. (1, 0). | |
| static Vector2< T > | YAxis () |
| Returns a vector with for the y-axis, i.e. (0, 1). | |
Public Attributes | |
| T | x = T(0) |
| The x component of the vector. | |
| T | y = T(0) |
| The y component of the vector. | |
Friends | |
| std::ostream & | operator<< (std::ostream &os, const Vector2< T > &vec) |
| Ostream output operator. | |
Operators | |
| Vector2< T > | operator- () const |
| Unary negation. | |
| Vector2< T > | operator+ (const Vector2< T > &rhs) const |
| Addition operator, add two vectors and return the result. | |
| Vector2< T > & | operator+= (const Vector2< T > &rhs) |
Addition assignment operator, add rhs to this vector. | |
| Vector2< T > | operator- (const Vector2< T > &rhs) const |
| Subtraction operator, subtract two vectors and return the result. | |
| Vector2< T > & | operator-= (const Vector2< T > &rhs) |
Subtraction assignment operator, subtract rhs from this vector. | |
| Vector2< T > | operator* (const Vector2< T > &rhs) const |
| Piecewise multiplication operator, multiply the x and y components of two vectors and return the result. | |
| Vector2< T > & | operator*= (const Vector2< T > &rhs) |
Piecewise multiplication assignment operator, multiply the x and y components of this vector by the x and y components of rhs. | |
| Vector2< T > | operator* (const T a) const |
Scalar multiplication operator, multiply the x and y components of this vector by a and return the result. | |
| Vector2< T > & | operator*= (const T a) |
Scalar multiplication assignment operator, multiply the x and y components of this vector by a. | |
| Vector2< T > | operator/ (const Vector2< T > &rhs) const |
| Piecewise division operator, divide the x and y components of two vectors and return the result. | |
| Vector2< T > & | operator/= (const Vector2< T > &rhs) |
Piecewise division assignment operator, divide the x and y components of this vector by the x and y components of rhs. | |
| Vector2< T > | operator/ (const T a) const |
Scalar division operator, divide the x and y components of this vector by a and return the result. | |
| Vector2< T > & | operator/= (const T a) |
Scalar division assignment operator, divide the x and y components of this vector by a. | |
| bool | operator== (const Vector2< T > &other) const |
| Equality operator, check if two vectors are equal. | |
| bool | operator!= (const Vector2< T > &rhs) const |
| Inequality operator, check if two vectors are not equal. | |
| template<typename U> | |
| bool | operator== (const Vector2< U > &other) const |
| Equality operator with a vector of a different type, check if two vectors are equal. | |
| template<typename U> | |
| bool | operator!= (const Vector2< U > &rhs) const |
| Inequality operator with a vector of a different type, check if two vectors are not equal. | |
| Vector2< T > | operator* (const T a, const Vector2< T > &other) |
Reversed scalar multiplication operator, multiply the x and y components of this vector by a and return the result. | |
| Vector2< T > | operator/ (const T a, const Vector2< T > &other) |
Reversed scalar division operator, divide the x and y components of this vector by a and return the result. | |
A 2D vector, (x, y).
| T | The type of the vector's components. |
|
inline |
Construct a vector from a vector of a different type, by implicitly casting each component.
| S | The type of the other vector's components. |
| other | The other vector. |
Construct a vector from components of a different type, by implicitly casting each component.
| S | The type of the components. |
| x | The x component. |
| y | The y component. |
|
inlinenodiscard |
Returns the angle that this vector makes with the +x axis, in radians.
|
inlinenodiscard |
Returns the angle between this vector and the provided vector, or zero if one of the vectors has zero length.
| other | Other vector. |
|
inlinenodiscard |
Returns the Z component of the cross product of this vecctor and other in the 2D plane.
The result always points perpendicular outside the plane.
| other | The other vector. |
|
inlinenodiscard |
Returns the distance between two vectors, assuming that each represents a point in space.
| other | The other vector. |
|
inlinenodiscard |
Returns the squared distance between two vectors, assuming that each represents a point in space.
| other | The other vector. |
|
inlinenodiscard |
Returns the dot product of this vector and other.
| other | The other vector. |
|
inline |
Inequality operator, check if two vectors are not equal.
| rhs | The vector to compare. |
|
inline |
Inequality operator with a vector of a different type, check if two vectors are not equal.
| rhs | The vector to compare. |
|
inline |
Scalar multiplication operator, multiply the x and y components of this vector by a and return the result.
Equivalent to Vector2<T>(lhs.x * a, lhs.y * a).
| a | The scalar to multiply. |
|
inline |
Piecewise multiplication operator, multiply the x and y components of two vectors and return the result.
Equivalent to Vector2<T>(lhs.x * rhs.x, lhs.y * rhs.y).
| rhs | The vector to multiply. |
|
inline |
Scalar multiplication assignment operator, multiply the x and y components of this vector by a.
Equivalent to lhs.x *= a; lhs.y *= a;.
| a | The scalar to multiply. |
|
inline |
Piecewise multiplication assignment operator, multiply the x and y components of this vector by the x and y components of rhs.
Equivalent to lhs.x *= rhs.x; lhs.y *= rhs.y;.
| rhs | The vector to multiply. |
|
inline |
Addition operator, add two vectors and return the result.
| rhs | The vector to add. |
|
inline |
Addition assignment operator, add rhs to this vector.
| rhs | The vector to add. |
|
inline |
Subtraction operator, subtract two vectors and return the result.
| rhs | The vector to subtract. |
|
inline |
Subtraction assignment operator, subtract rhs from this vector.
| rhs | The vector to subtract. |
|
inline |
Scalar division operator, divide the x and y components of this vector by a and return the result.
Equivalent to Vector2<T>(lhs.x / a, lhs.y / a).
| a | The scalar to divide. |
|
inline |
Piecewise division operator, divide the x and y components of two vectors and return the result.
Equivalent to Vector2<T>(lhs.x / rhs.x, lhs.y / rhs.y).
| rhs | The vector to divide. |
|
inline |
Scalar division assignment operator, divide the x and y components of this vector by a.
Equivalent to lhs.x /= a; lhs.y /= a;.
| a | The scalar to divide. |
|
inline |
Piecewise division assignment operator, divide the x and y components of this vector by the x and y components of rhs.
Equivalent to lhs.x /= rhs.x; lhs.y /= rhs.y;.
| rhs | The vector to divide. |
|
inline |
Assignment operator from a vector of a different type.
| S | The type of the other vector's components. |
| rhs | The vector to copy. |
|
inline |
Equality operator, check if two vectors are equal.
| other | The vector to compare. |
|
inline |
Equality operator with a vector of a different type, check if two vectors are equal.
| other | The vector to compare. |
|
inlinenodiscard |
Rotate this vector by radians.
| radians | Angle in radians. |
|
inlinenodiscard |
Rotate this vector by a given pre-computed cosine/sine angle.
| cosResult | The result of cos(angle) |
| sinResult | The result of sin(angle) |
Reversed scalar multiplication operator, multiply the x and y components of this vector by a and return the result.
Equivalent to Vector2<T>(a * lhs.x, a * lhs.y).
| a | The scalar to multiply. |
| other | The vector to multiply. |
Reversed scalar division operator, divide the x and y components of this vector by a and return the result.
Equivalent to Vector2<T>(a / lhs.x, a / lhs.y).
| a | The scalar to divide. |
| other | The vector to divide. |