Vector representing a point in DIM-dimensional space. More...
#include <ptems/vector.hpp>
Public Types | |
using | ConjugateType = BasicVector< typename std::conditional_t< is_complex_v< T >, T, std::complex< T > >, DIM > |
The type of the conjugate of the vector. More... | |
Public Member Functions | |
constexpr | BasicVector () |
Construct a zero vector. More... | |
constexpr | BasicVector (T value) |
Construct a vector with all components equal to the specified value. More... | |
template<typename... F, typename = std::enable_if_t<sizeof...(F) == DIM>> | |
constexpr | BasicVector (F... pt) |
Construct a vector for the specified point. More... | |
template<typename U > | |
constexpr | BasicVector (const BasicVector< U, DIM > rhs) |
Construct a vector by copying the specified vector. More... | |
template<typename U > | |
constexpr BasicVector & | operator= (const BasicVector< U, DIM > rhs) |
Copy the specified vector to this. More... | |
constexpr BasicVector & | operator= (T rhs) |
Set all components tof vector equal to a constants. More... | |
constexpr BasicVector & | operator+= (T rhs) |
Adds a constant to every component to this vector. More... | |
template<typename U > | |
constexpr BasicVector & | operator+= (const BasicVector< U, DIM > &rhs) |
Adds another vector to this vector. More... | |
constexpr BasicVector & | operator-= (T rhs) |
Subtracts constant from every component to this vector. More... | |
template<typename U > | |
constexpr BasicVector & | operator-= (const BasicVector< U, DIM > &rhs) |
Subtracts another vector to this vector. More... | |
template<typename U > | |
constexpr BasicVector & | operator/= (U rhs) |
Divides all components of this vector by a constant. More... | |
template<typename U > | |
constexpr BasicVector & | operator/= (const BasicVector< U, DIM > &rhs) |
Performs elementwise division of all components of this vector by the other vector. More... | |
template<typename U > | |
constexpr BasicVector & | operator*= (U rhs) |
Multiplies all components of this vector by a constant. More... | |
template<typename U > | |
constexpr BasicVector & | operator*= (const BasicVector< U, DIM > &rhs) |
Performs elementwise multiplication of all components of this vector by the other vector. More... | |
constexpr BasicVector | operator- () const |
Returns the negated vector. More... | |
template<typename U > | |
constexpr std::common_type_t< T, U > | Dot (const BasicVector< U, DIM > &rhs) const |
Computes the dot product of this vector with the specified vector. More... | |
constexpr remove_complex_t< T > | Length () const |
Computes the length of the vector. More... | |
constexpr T | operator[] (std::size_t i) const |
Gets a component of the vector by index. More... | |
constexpr T & | operator[] (std::size_t i) |
Gets a mutable reference to the component of the vector by index. More... | |
constexpr remove_complex_t< T > | LengthSquared () const |
Gets the square of the length of the vector. More... | |
constexpr BasicVector & | Normalise () |
Normalises the current vector. More... | |
constexpr BasicVector | Normalised () const |
Gets a new vector which is the normalised version of this vector. More... | |
ConjugateType | Conjugate () const |
Computes the complex conjugate of the vector. More... | |
BasicVector & | ConjugateOverwrite () const |
Overwrites the vector with its complex conjugate. More... | |
std::size_t | size () const |
Gets the number of elements in the vector. More... | |
Related Functions | |
(Note that these are not member functions.) | |
template<typename T , typename U , std::size_t DIM> | |
constexpr BasicVector< std::common_type_t< T, U >, DIM > | operator+ (const BasicVector< T, DIM > &lhs, const BasicVector< U, DIM > &rhs) |
Computes the vector resulting from the addition of two vectors. More... | |
template<typename U , typename T , std::size_t DIM> | |
constexpr BasicVector< T, DIM > | operator+ (BasicVector< T, DIM > lhs, U rhs) |
Computes the vector resulting from adding a scalar to a vector. More... | |
template<typename U , typename T , std::size_t DIM> | |
constexpr BasicVector< T, DIM > | operator+ (U lhs, BasicVector< T, DIM > rhs) |
Computes the vector resulting from adding a scalar to a vector. More... | |
template<typename T , typename U , std::size_t DIM> | |
constexpr BasicVector< std::common_type_t< T, U >, DIM > | operator- (const BasicVector< T, DIM > &lhs, const BasicVector< U, DIM > &rhs) |
Computes the vector resulting from the subtraction of two vectors. More... | |
template<typename U , typename T , std::size_t DIM> | |
constexpr BasicVector< T, DIM > | operator- (BasicVector< T, DIM > lhs, U rhs) |
Computes the vector resulting from subtracting a scalar from a vector. More... | |
template<typename U , typename T , std::size_t DIM> | |
constexpr BasicVector< T, DIM > | operator- (U lhs, const BasicVector< T, DIM > &rhs) |
Computes the vector resulting from subtracting a vector from a scalar. More... | |
template<typename T , typename U , std::size_t DIM> | |
constexpr BasicVector< std::common_type_t< T, U >, DIM > | operator/ (const BasicVector< T, DIM > &lhs, const BasicVector< U, DIM > &rhs) |
Computes the vector resulting from dividing all components of the first vector by the matching component of the second vector (elementwise division) More... | |
template<typename U , typename T , std::size_t DIM> | |
constexpr BasicVector< T, DIM > | operator/ (BasicVector< T, DIM > lhs, U rhs) |
Computes the vector resulting from dividing all components of the specified vector by a constant. More... | |
template<typename T , typename U , std::size_t DIM> | |
constexpr BasicVector< std::common_type_t< T, U >, DIM > | operator/ (U lhs, const BasicVector< T, DIM > &rhs) |
Computes the vector resulting from dividing a constant by every component of a vector (elementwise division) More... | |
template<typename T , typename U , std::size_t DIM> | |
constexpr BasicVector< std::common_type_t< T, U >, DIM > | operator* (const BasicVector< T, DIM > &lhs, const BasicVector< U, DIM > &rhs) |
Computes the vector resulting from multiplying all components of the first vector by the matching component of the second vector (elementwise multiplication) More... | |
template<typename U , typename T , std::size_t DIM> | |
constexpr BasicVector< T, DIM > | operator* (BasicVector< T, DIM > lhs, U rhs) |
Computes the vector resulting from (right) multiplying all components of the specified vector by a constant. More... | |
template<typename U , typename T , std::size_t DIM> | |
constexpr BasicVector< T, DIM > | operator* (U lhs, BasicVector< T, DIM > rhs) |
Computes the vector resulting from (left) multiplying all components of the specified vector by a constant. More... | |
template<typename T , std::size_t DIM> | |
std::istream & | operator>> (std::istream &is, BasicVector< T, DIM > &vec) |
Reads a vector from an input stream. More... | |
template<typename T , std::size_t DIM> | |
std::ostream & | operator<< (std::ostream &os, const BasicVector< T, DIM > &vec) |
Writes a vector to an output stream. More... | |
template<typename T , typename U , std::size_t DIM> | |
constexpr bool | operator== (const BasicVector< T, DIM > &lhs, const BasicVector< U, DIM > &rhs) |
Compares two vectors for equality - all components are equal. More... | |
template<typename T , typename U , std::size_t DIM> | |
constexpr bool | operator!= (const BasicVector< T, DIM > &lhs, const BasicVector< U, DIM > &rhs) |
Compares two vectors for inequality - any components are different. More... | |
template<typename U , typename T > | |
constexpr bool | operator== (const BasicVector< T, 1 > &lhs, U rhs) |
Compares 1D vector with a scalar. More... | |
template<typename U , typename T > | |
constexpr bool | operator== (U lhs, const BasicVector< T, 1 > &rhs) |
Compares 1D vector with a scalar. More... | |
template<typename U , typename T > | |
constexpr bool | operator!= (const BasicVector< T, 1 > &lhs, U rhs) |
Compares 1D vector with a scalar for inequality. More... | |
template<typename U , typename T > | |
constexpr bool | operator!= (U lhs, const BasicVector< T, 1 > &rhs) |
Compares 1D vector with a scalar for inequality. More... | |
template<typename T , std::size_t DIM> | |
constexpr BasicVector< T, DIM >::ConjugateType | Conjugate (const BasicVector< T, DIM > &vec) |
Computes the complex conjugate of a vector. More... | |
template<typename T , std::size_t DIM, typename = std::enable_if_t<is_complex_v<T>>> | |
constexpr BasicVector< T, DIM >::ConjugateType | Conjugate (BasicVector< T, DIM > &&vec) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
Vector representing a point in DIM-dimensional space.
T | The type of the vector component |
DIM | The dimension of the space |
using ptems::BasicVector< T, DIM >::ConjugateType = BasicVector<typename std::conditional_t<is_complex_v<T>, T, std::complex<T> >,DIM> |
The type of the conjugate of the vector.
Will either be the same type if T is complex, otherwise a vector of std::complex<T>.
|
inlineconstexpr |
Construct a zero vector.
|
inlineexplicitconstexpr |
Construct a vector with all components equal to the specified value.
value | Value to fill in each component of the vector |
|
inlineconstexpr |
Construct a vector for the specified point.
F | Any type explicitly convertible to T |
pt | The components of the vector, must be exactly DIM components |
|
inlineconstexpr |
Construct a vector by copying the specified vector.
U | Type of the vector to copy |
rhs | Vector to copy |
|
inline |
Computes the complex conjugate of the vector.
|
inline |
Overwrites the vector with its complex conjugate.
|
inlineconstexpr |
Computes the dot product of this vector with the specified vector.
U | Type of the components of the vector to dot product with |
rhs | Vector to dot product with this vector |
|
inlineconstexpr |
Computes the length of the vector.
|
inlineconstexpr |
Gets the square of the length of the vector.
|
inlineconstexpr |
Normalises the current vector.
|
inlineconstexpr |
Gets a new vector which is the normalised version of this vector.
|
inlineconstexpr |
Performs elementwise multiplication of all components of this vector by the other vector.
U | Type of the components of the vector to multiply by |
rhs | Vector to multiply by elementwise |
|
inlineconstexpr |
Multiplies all components of this vector by a constant.
U | Type of right hand side |
rhs | Constant to multiple vector by |
|
inlineconstexpr |
Adds another vector to this vector.
U | Type of the components of the vector to add |
rhs | Vector to add |
|
inlineconstexpr |
Adds a constant to every component to this vector.
rhs | Constant to add |
|
inlineconstexpr |
Returns the negated vector.
rhs | Vector to negate |
|
inlineconstexpr |
Subtracts another vector to this vector.
U | Type of the components of the vector to subtract |
rhs | Vector to subtract |
|
inlineconstexpr |
Subtracts constant from every component to this vector.
rhs | Constant to subtract |
|
inlineconstexpr |
Performs elementwise division of all components of this vector by the other vector.
U | Type of the components of the vector to divide by |
rhs | Vector to divide by elementwise |
|
inlineconstexpr |
Divides all components of this vector by a constant.
U | Type of right hand side |
rhs | Constant to divide vector by |
|
inlineconstexpr |
Copy the specified vector to this.
U | Type of the vector to copy |
rhs | Vector to copy |
|
inlineconstexpr |
Set all components tof vector equal to a constants.
rhs | Scalar to set vector to |
|
inlineconstexpr |
Gets a mutable reference to the component of the vector by index.
i | The index of the component of the vector to get (must be less than DIM). |
std::out_of_range | If i is not less than DIM. |
|
inlineconstexpr |
Gets a component of the vector by index.
i | The index of the component of the vector to get (must be less than DIM). |
std::out_of_range | If i is not less than DIM. |
|
inline |
Gets the number of elements in the vector.
|
related |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
|
related |
Computes the complex conjugate of a vector.
T | Type of the components of the vector |
vec | The vector to conjugate |
|
related |
Compares 1D vector with a scalar for inequality.
T | Type of the components of the left hand vector |
U | Type of the scalar |
lhs | The left hand side vector to compare |
rhs | The right hand side scalar to compare |
|
related |
Compares two vectors for inequality - any components are different.
T | Type of the components of the left hand vector |
U | Type of the components of the right hand vector |
DIM | The dimension of the vectors to compare. |
lhs | The left hand side vector to compare |
rhs | The right hand side vector to compare |
|
related |
Compares 1D vector with a scalar for inequality.
T | Type of the components of the right hand vector |
U | Type of the scalar |
lhs | The left hand side scalar to compare |
rhs | The right hand side vector to compare |
|
related |
Computes the vector resulting from (right) multiplying all components of the specified vector by a constant.
T | Type of the components of the left hand vector |
U | Type of the scalar |
DIM | The dimension of the vector |
lhs | The vector to multiply all components by a scalar |
rhs | The scalar to multiply the vector by |
|
related |
Computes the vector resulting from multiplying all components of the first vector by the matching component of the second vector (elementwise multiplication)
T | Type of the components of the left hand vector |
U | Type of the components of the right hand vector |
DIM | The dimension of the vector |
lhs | The vector to multiply all components |
rhs | The vector to multiply by |
|
related |
Computes the vector resulting from (left) multiplying all components of the specified vector by a constant.
T | Type of the components of the right hand vector |
U | Type of the scalar |
DIM | The dimension of the vector |
lhs | The scalar to multiply the vector by |
rhs | The vector to multiply all components by a scalar |
|
related |
Computes the vector resulting from adding a scalar to a vector.
T | Type of the components of the left hand vector |
U | Type of the scalar |
DIM | The dimension of the vectors |
lhs | The left hand side vector of the addition |
rhs | The right hand side scalar of the addition |
|
related |
Computes the vector resulting from the addition of two vectors.
T | Type of the components of the left hand vector |
U | Type of the components of the right hand vector |
DIM | The dimension of the vectors |
lhs | The left hand side vector of the addition |
rhs | The right hand side of the addition |
|
related |
Computes the vector resulting from adding a scalar to a vector.
U | Type of the scalar |
T | Type of the components of the right hand vector |
DIM | The dimension of the vectors |
lhs | The left hand side scalar of the addition |
rhs | The right hand side vector of the addition |
|
related |
Computes the vector resulting from subtracting a scalar from a vector.
T | Type of the components of the left hand vector |
U | Type of the scalar |
DIM | The dimension of the vectors |
lhs | The vector to subtract from |
rhs | The scalar to subtract |
|
related |
Computes the vector resulting from the subtraction of two vectors.
T | Type of the components of the left hand vector |
U | Type of the components of the right hand vector |
DIM | The dimension of the vectors |
lhs | The vector to subtract from |
rhs | The vector to subtract |
|
related |
Computes the vector resulting from subtracting a vector from a scalar.
T | Type of the components of the right hand vector |
U | Type of the scalar |
DIM | The dimension of the vectors |
lhs | The scalar to subtract from |
rhs | The vector to subtract |
|
related |
Computes the vector resulting from dividing all components of the specified vector by a constant.
T | Type of the components of the left hand vector |
U | Type of the scalar |
DIM | The dimension of the vector |
lhs | The vector to divide all components by a scalar |
rhs | The scalar to divide the vector by |
|
related |
Computes the vector resulting from dividing all components of the first vector by the matching component of the second vector (elementwise division)
T | Type of the components of the left hand vector |
U | Type of the components of the right hand vector |
DIM | The dimension of the vector |
lhs | The vector to divide all components of |
rhs | The vector to divide by |
|
related |
Computes the vector resulting from dividing a constant by every component of a vector (elementwise division)
T | Type of the components of the right hand vector |
U | Type of the scalar |
DIM | The dimension of the vector |
lhs | The scalar to divide by all components of a vector |
rhs | The vector to divide the constant by component-wise |
|
related |
Writes a vector to an output stream.
A vector will be written as a comma-separated list of DIM floating point values.
T | Type of the components of the vector |
DIM | The dimension of the vector to write. |
os | The stream to write the vector to |
vec | The vector to write |
|
related |
Compares 1D vector with a scalar.
T | Type of the components of the left hand vector |
U | Type of the scalar |
lhs | The left hand side vector to compare |
rhs | The right hand side scalar to compare |
|
related |
Compares two vectors for equality - all components are equal.
T | Type of the components of the left hand vector |
U | Type of the components of the right hand vector |
DIM | The dimension of the vectors to compare. |
lhs | The left hand side vector to compare |
rhs | The right hand side vector to compare |
|
related |
Compares 1D vector with a scalar.
T | Type of the components of the right hand vector |
U | Type of the scalar |
lhs | The left hand side scalar to compare |
rhs | The right hand side vector to compare |
|
related |
Reads a vector from an input stream.
A vector should be a comma-separated list of DIM floating point values.
T | Type of the components of the vector |
DIM | The dimension of the vector to read. |
is | The stream to read the vector from |
vec | The vector to read into |