PLaSK library
Loading...
Searching...
No Matches
plask::Vec< 2, T > Struct Template Reference

Vector in 2D space. More...

#include <plask/vector/2d.hpp>

Collaboration diagram for plask::Vec< 2, T >:
[legend]

Public Types

typedef T * iterator
 Type of iterator over components.
 
typedef const T * const_iterator
 Type of const iterator over components.
 

Public Member Functions

T & tran ()
 
constexpr const T & tran () const
 
T & vert ()
 
constexpr const T & vert () const
 
T & rad_r ()
 
constexpr const T & rad_r () const
 
T & rad_z ()
 
constexpr const T & rad_z () const
 
T & se_y ()
 
constexpr const T & se_y () const
 
T & se_z ()
 
constexpr const T & se_z () const
 
T & zup_y ()
 
constexpr const T & z_up_y () const
 
T & zup_z ()
 
constexpr const T & z_up_z () const
 
T & ee_x ()
 
constexpr const T & ee_x () const
 
T & ee_y ()
 
constexpr const T & ee_y () const
 
T & yup_x ()
 
constexpr const T & y_up_x () const
 
T & yup_y ()
 
constexpr const T & y_up_y () const
 
 Vec ()
 Construct uninitialized vector.
 
template<typename OtherT >
constexpr Vec (const Vec< 2, OtherT > &p)
 Copy constructor from all other 2D vectors.
 
constexpr Vec (const T &c0__tran, const T &c1__up)
 Construct vector with given components.
 
template<typename T0 , typename T1 >
constexpr Vec (const std::pair< T0, T1 > &comp)
 Construct vector components given in std::pair.
 
iterator begin ()
 Get begin iterator over components.
 
const_iterator begin () const
 Get begin const iterator over components.
 
iterator end ()
 Get end iterator over components.
 
const_iterator end () const
 Get end const iterator over components.
 
template<typename OtherT >
constexpr bool operator== (const Vec< 2, OtherT > &p) const
 Compare two vectors, this and p.
 
template<typename OtherT , typename SuprType >
constexpr bool equals (const Vec< 2, OtherT > &p, const SuprType &abs_supremum) const
 Check if two vectors, this and p are almost equal.
 
template<typename OtherT >
constexpr bool equals (const Vec< 2, OtherT > &p) const
 Check if two vectors, this and p are almost equal.
 
template<typename OtherT >
constexpr bool operator!= (const Vec< 2, OtherT > &p) const
 Compare two vectors, this and p.
 
T & operator[] (size_t i)
 Get i-th component WARNING This function does not check if it is valid (for efficiency reasons)
 
const T & operator[] (size_t i) const
 Get i-th component WARNING This function does not check if it is valid (for efficiency reasons)
 
template<typename OtherT >
constexpr auto operator+ (const Vec< 2, OtherT > &other) const -> Vec< 2, decltype(c0+other.c0)>
 Calculate sum of two vectors, this and other.
 
Vec< 2, T > & operator+= (const Vec< 2, T > &other)
 Increase coordinates of this vector by coordinates of other vector other.
 
template<typename OtherT >
constexpr auto operator- (const Vec< 2, OtherT > &other) const -> Vec< 2, decltype(c0 - other.c0)>
 Calculate difference of two vectors, this and other.
 
Vec< 2, T > & operator-= (const Vec< 2, T > &other)
 Decrease coordinates of this vector by coordinates of other vector other.
 
template<typename OtherT >
constexpr auto operator* (const OtherT scale) const -> Vec< 2, decltype(c0 *scale)>
 Calculate this vector multiplied by scalar scale.
 
Vec< 2, T > & operator*= (const T scalar)
 Multiple coordinates of this vector by scalar.
 
template<typename OtherT >
constexpr auto operator/ (const OtherT scale) const -> Vec< 2, decltype(c0/scale)>
 Calculate this vector divided by scalar scale.
 
Vec< 2, T > & operator/= (const T scalar)
 Divide coordinates of this vector by scalar.
 
constexpr Vec< 2, T > operator- () const
 Calculate vector opposite to this.
 
Vec< 2, T > sqr () const
 Square each component of tensor.
 
Vec< 2, T > & sqr_inplace ()
 Square each component of tensor in place.
 
Vec< 2, T > sqrt () const
 Square root of each component of tensor.
 
Vec< 2, T > & sqrt_inplace ()
 Square root of each component of tensor in place.
 
template<typename OtherT >
Vec< 2, T > pow (OtherT a) const
 Power of each component of tensor.
 
void flip (size_t i)
 Change i-th coordinate to oposite.
 
Vec< 2, T > flipped (size_t i)
 Get vector similar to this but with changed i-th component to oposite.
 
template<class OT >
bool operator< (Vec< 2, OT > const &v) const
 A lexical comparison of two vectors, allow to use vector in std::set and std::map as key type.
 

Static Public Member Functions

template<typename InputIteratorType >
static Vec< 2, T > fromIterator (InputIteratorType inputIt)
 Construct vector with components read from input iterator (including C array).
 

Public Attributes

c0
 
c1
 

Static Public Attributes

static const int DIMS = 2
 

Friends

std::ostream & operator<< (std::ostream &out, const Vec< 2, T > &to_print)
 Print vector to stream using format (where c0 and c1 are vector components): [c0, c1].
 

Detailed Description

template<typename T>
struct plask::Vec< 2, T >

Vector in 2D space.

Definition at line 38 of file 2d.hpp.

Member Typedef Documentation

◆ const_iterator

template<typename T >
typedef const T* plask::Vec< 2, T >::const_iterator

Type of const iterator over components.

Definition at line 89 of file 2d.hpp.

◆ iterator

template<typename T >
typedef T* plask::Vec< 2, T >::iterator

Type of iterator over components.

Definition at line 84 of file 2d.hpp.

Constructor & Destructor Documentation

◆ Vec() [1/4]

template<typename T >
plask::Vec< 2, T >::Vec ( )
inline

Construct uninitialized vector.

Definition at line 92 of file 2d.hpp.

◆ Vec() [2/4]

template<typename T >
template<typename OtherT >
constexpr plask::Vec< 2, T >::Vec ( const Vec< 2, OtherT > &  p)
inlineconstexpr

Copy constructor from all other 2D vectors.

Parameters
pvector to copy from

Definition at line 99 of file 2d.hpp.

◆ Vec() [3/4]

template<typename T >
constexpr plask::Vec< 2, T >::Vec ( const T &  c0__tran,
const T &  c1__up 
)
inlineconstexpr

Construct vector with given components.

Parameters
c0__tran,c1__upcomponents

Definition at line 105 of file 2d.hpp.

◆ Vec() [4/4]

template<typename T >
template<typename T0 , typename T1 >
constexpr plask::Vec< 2, T >::Vec ( const std::pair< T0, T1 > &  comp)
inlineconstexpr

Construct vector components given in std::pair.

Parameters
compcomponents

Definition at line 112 of file 2d.hpp.

Member Function Documentation

◆ begin() [1/2]

template<typename T >
iterator plask::Vec< 2, T >::begin ( )
inline

Get begin iterator over components.

Returns
begin iterator over components

Definition at line 131 of file 2d.hpp.

◆ begin() [2/2]

template<typename T >
const_iterator plask::Vec< 2, T >::begin ( ) const
inline

Get begin const iterator over components.

Returns
begin const iterator over components

Definition at line 137 of file 2d.hpp.

◆ ee_x() [1/2]

template<typename T >
T & plask::Vec< 2, T >::ee_x ( )
inline

Definition at line 69 of file 2d.hpp.

◆ ee_x() [2/2]

template<typename T >
constexpr const T & plask::Vec< 2, T >::ee_x ( ) const
inlineconstexpr

Definition at line 70 of file 2d.hpp.

◆ ee_y() [1/2]

template<typename T >
T & plask::Vec< 2, T >::ee_y ( )
inline

Definition at line 71 of file 2d.hpp.

◆ ee_y() [2/2]

template<typename T >
constexpr const T & plask::Vec< 2, T >::ee_y ( ) const
inlineconstexpr

Definition at line 72 of file 2d.hpp.

◆ end() [1/2]

template<typename T >
iterator plask::Vec< 2, T >::end ( )
inline

Get end iterator over components.

Returns
end iterator over components

Definition at line 143 of file 2d.hpp.

◆ end() [2/2]

template<typename T >
const_iterator plask::Vec< 2, T >::end ( ) const
inline

Get end const iterator over components.

Returns
end const iterator over components

Definition at line 149 of file 2d.hpp.

◆ equals() [1/2]

template<typename T >
template<typename OtherT >
constexpr bool plask::Vec< 2, T >::equals ( const Vec< 2, OtherT > &  p) const
inlineconstexpr

Check if two vectors, this and p are almost equal.

Parameters
pvector to compare
Returns
true only if this vector and p have almost equals coordinates

Definition at line 175 of file 2d.hpp.

◆ equals() [2/2]

template<typename T >
constexpr bool plask::Vec< 2, T >::equals ( const Vec< 2, OtherT > &  p,
const SuprType abs_supremum 
) const
inlineconstexpr

Check if two vectors, this and p are almost equal.

Parameters
pvector to compare
abs_supremummaximal allowed difference for one coordinate
Returns
true only if this vector and p have almost equals coordinates

Definition at line 166 of file 2d.hpp.

◆ flip()

template<typename T >
void plask::Vec< 2, T >::flip ( size_t  i)
inline

Change i-th coordinate to oposite.

WARNING This function does not check if it is valid (for efficiency reasons)

Parameters
inumber of coordinate

Definition at line 352 of file 2d.hpp.

◆ flipped()

template<typename T >
Vec< 2, T > plask::Vec< 2, T >::flipped ( size_t  i)
inline

Get vector similar to this but with changed i-th component to oposite.

WARNING This function does not check if it is valid (for efficiency reasons)

Parameters
inumber of coordinate
Returns
vector similar to this but with changed i-th component to oposite

Definition at line 363 of file 2d.hpp.

◆ fromIterator()

template<typename T >
static Vec< 2, T > plask::Vec< 2, T >::fromIterator ( InputIteratorType  inputIt)
inlinestatic

Construct vector with components read from input iterator (including C array).

Parameters
inputItinput iterator with minimum 3 objects available
Template Parameters
InputIteratorTypeinput iterator type, must allow for postincrementation and dereference operation

Definition at line 120 of file 2d.hpp.

◆ operator!=()

template<typename T >
template<typename OtherT >
constexpr bool plask::Vec< 2, T >::operator!= ( const Vec< 2, OtherT > &  p) const
inlineconstexpr

Compare two vectors, this and p.

Parameters
pvector to compare
Returns
true only if this vector and p don't have equals coordinates

Definition at line 184 of file 2d.hpp.

◆ operator*()

template<typename T >
template<typename OtherT >
constexpr auto plask::Vec< 2, T >::operator* ( const OtherT  scale) const -> Vec<2,decltype(c0*scale)>
inlineconstexpr

Calculate this vector multiplied by scalar scale.

Parameters
scalescalar
Returns
this vector multiplied by scalar

Definition at line 256 of file 2d.hpp.

◆ operator*=()

template<typename T >
Vec< 2, T > & plask::Vec< 2, T >::operator*= ( const scalar)
inline

Multiple coordinates of this vector by scalar.

Parameters
scalarscalar
Returns
*this (after scale)

Definition at line 267 of file 2d.hpp.

◆ operator+()

template<typename T >
template<typename OtherT >
constexpr auto plask::Vec< 2, T >::operator+ ( const Vec< 2, OtherT > &  other) const -> Vec<2,decltype(c0 + other.c0)>
inlineconstexpr

Calculate sum of two vectors, this and other.

Parameters
othervector to add, can have different data type (than result type will be found using C++ types promotions rules)
Returns
vectors sum

Definition at line 214 of file 2d.hpp.

◆ operator+=()

template<typename T >
Vec< 2, T > & plask::Vec< 2, T >::operator+= ( const Vec< 2, T > &  other)
inline

Increase coordinates of this vector by coordinates of other vector other.

Parameters
othervector to add
Returns
*this (after increase)

Definition at line 223 of file 2d.hpp.

◆ operator-() [1/2]

template<typename T >
constexpr Vec< 2, T > plask::Vec< 2, T >::operator- ( ) const
inlineconstexpr

Calculate vector opposite to this.

Returns
Vec<2,T>(-c0, -c1)

Definition at line 300 of file 2d.hpp.

◆ operator-() [2/2]

template<typename T >
template<typename OtherT >
constexpr auto plask::Vec< 2, T >::operator- ( const Vec< 2, OtherT > &  other) const -> Vec<2,decltype(c0 - other.c0)>
inlineconstexpr

Calculate difference of two vectors, this and other.

Parameters
othervector to subtract from this, can have different data type (than result type will be found using C++ types promotions rules)
Returns
vectors difference

Definition at line 235 of file 2d.hpp.

◆ operator-=()

template<typename T >
Vec< 2, T > & plask::Vec< 2, T >::operator-= ( const Vec< 2, T > &  other)
inline

Decrease coordinates of this vector by coordinates of other vector other.

Parameters
othervector to subtract
Returns
*this (after decrease)

Definition at line 244 of file 2d.hpp.

◆ operator/()

template<typename T >
template<typename OtherT >
constexpr auto plask::Vec< 2, T >::operator/ ( const OtherT  scale) const -> Vec<2,decltype(c0/scale)>
inlineconstexpr

Calculate this vector divided by scalar scale.

Parameters
scalescalar
Returns
this vector divided by scalar

Definition at line 279 of file 2d.hpp.

◆ operator/=()

template<typename T >
Vec< 2, T > & plask::Vec< 2, T >::operator/= ( const scalar)
inline

Divide coordinates of this vector by scalar.

Parameters
scalarscalar
Returns
*this (after divide)

Definition at line 290 of file 2d.hpp.

◆ operator<()

template<typename T >
template<class OT >
bool plask::Vec< 2, T >::operator< ( Vec< 2, OT > const v) const
inline

A lexical comparison of two vectors, allow to use vector in std::set and std::map as key type.

It supports NaN-s (which, due to this method, is greater than all other numbers).

Parameters
vvectors to compare
Returns
true only if this is smaller than the v

Definition at line 387 of file 2d.hpp.

◆ operator==()

template<typename T >
template<typename OtherT >
constexpr bool plask::Vec< 2, T >::operator== ( const Vec< 2, OtherT > &  p) const
inlineconstexpr

Compare two vectors, this and p.

Parameters
pvector to compare
Returns
true only if this vector and p have equals coordinates

Definition at line 157 of file 2d.hpp.

◆ operator[]() [1/2]

template<typename T >
T & plask::Vec< 2, T >::operator[] ( size_t  i)
inline

Get i-th component WARNING This function does not check if it is valid (for efficiency reasons)

Parameters
inumber of coordinate
Returns
i-th component

Definition at line 192 of file 2d.hpp.

◆ operator[]() [2/2]

template<typename T >
const T & plask::Vec< 2, T >::operator[] ( size_t  i) const
inline

Get i-th component WARNING This function does not check if it is valid (for efficiency reasons)

Parameters
inumber of coordinate
Returns
i-th component

Definition at line 203 of file 2d.hpp.

◆ pow()

template<typename T >
template<typename OtherT >
Vec< 2, T > plask::Vec< 2, T >::pow ( OtherT  a) const
inline

Power of each component of tensor.

Returns
squared tensor

Definition at line 343 of file 2d.hpp.

◆ rad_r() [1/2]

template<typename T >
T & plask::Vec< 2, T >::rad_r ( )
inline

Definition at line 51 of file 2d.hpp.

◆ rad_r() [2/2]

template<typename T >
constexpr const T & plask::Vec< 2, T >::rad_r ( ) const
inlineconstexpr

Definition at line 52 of file 2d.hpp.

◆ rad_z() [1/2]

template<typename T >
T & plask::Vec< 2, T >::rad_z ( )
inline

Definition at line 53 of file 2d.hpp.

◆ rad_z() [2/2]

template<typename T >
constexpr const T & plask::Vec< 2, T >::rad_z ( ) const
inlineconstexpr

Definition at line 54 of file 2d.hpp.

◆ se_y() [1/2]

template<typename T >
T & plask::Vec< 2, T >::se_y ( )
inline

Definition at line 57 of file 2d.hpp.

◆ se_y() [2/2]

template<typename T >
constexpr const T & plask::Vec< 2, T >::se_y ( ) const
inlineconstexpr

Definition at line 58 of file 2d.hpp.

◆ se_z() [1/2]

template<typename T >
T & plask::Vec< 2, T >::se_z ( )
inline

Definition at line 59 of file 2d.hpp.

◆ se_z() [2/2]

template<typename T >
constexpr const T & plask::Vec< 2, T >::se_z ( ) const
inlineconstexpr

Definition at line 60 of file 2d.hpp.

◆ sqr()

template<typename T >
Vec< 2, T > plask::Vec< 2, T >::sqr ( ) const
inline

Square each component of tensor.

Returns
squared tensor

Definition at line 308 of file 2d.hpp.

◆ sqr_inplace()

template<typename T >
Vec< 2, T > & plask::Vec< 2, T >::sqr_inplace ( )
inline

Square each component of tensor in place.

Returns
*this (squared)

Definition at line 316 of file 2d.hpp.

◆ sqrt()

template<typename T >
Vec< 2, T > plask::Vec< 2, T >::sqrt ( ) const
inline

Square root of each component of tensor.

Returns
squared tensor

Definition at line 325 of file 2d.hpp.

◆ sqrt_inplace()

template<typename T >
Vec< 2, T > & plask::Vec< 2, T >::sqrt_inplace ( )
inline

Square root of each component of tensor in place.

Returns
*this (squared)

Definition at line 333 of file 2d.hpp.

◆ tran() [1/2]

template<typename T >
T & plask::Vec< 2, T >::tran ( )
inline

Definition at line 44 of file 2d.hpp.

◆ tran() [2/2]

template<typename T >
constexpr const T & plask::Vec< 2, T >::tran ( ) const
inlineconstexpr

Definition at line 45 of file 2d.hpp.

◆ vert() [1/2]

template<typename T >
T & plask::Vec< 2, T >::vert ( )
inline

Definition at line 47 of file 2d.hpp.

◆ vert() [2/2]

template<typename T >
constexpr const T & plask::Vec< 2, T >::vert ( ) const
inlineconstexpr

Definition at line 48 of file 2d.hpp.

◆ y_up_x()

template<typename T >
constexpr const T & plask::Vec< 2, T >::y_up_x ( ) const
inlineconstexpr

Definition at line 76 of file 2d.hpp.

◆ y_up_y()

template<typename T >
constexpr const T & plask::Vec< 2, T >::y_up_y ( ) const
inlineconstexpr

Definition at line 78 of file 2d.hpp.

◆ yup_x()

template<typename T >
T & plask::Vec< 2, T >::yup_x ( )
inline

Definition at line 75 of file 2d.hpp.

◆ yup_y()

template<typename T >
T & plask::Vec< 2, T >::yup_y ( )
inline

Definition at line 77 of file 2d.hpp.

◆ z_up_y()

template<typename T >
constexpr const T & plask::Vec< 2, T >::z_up_y ( ) const
inlineconstexpr

Definition at line 64 of file 2d.hpp.

◆ z_up_z()

template<typename T >
constexpr const T & plask::Vec< 2, T >::z_up_z ( ) const
inlineconstexpr

Definition at line 66 of file 2d.hpp.

◆ zup_y()

template<typename T >
T & plask::Vec< 2, T >::zup_y ( )
inline

Definition at line 63 of file 2d.hpp.

◆ zup_z()

template<typename T >
T & plask::Vec< 2, T >::zup_z ( )
inline

Definition at line 65 of file 2d.hpp.

Friends And Related Symbol Documentation

◆ operator<<

template<typename T >
std::ostream & operator<< ( std::ostream &  out,
const Vec< 2, T > &  to_print 
)
friend

Print vector to stream using format (where c0 and c1 are vector components): [c0, c1].

Parameters
outprint destination, output stream
to_printvector to print
Returns
out stream

Definition at line 375 of file 2d.hpp.

Member Data Documentation

◆ c0

template<typename T >
T plask::Vec< 2, T >::c0

Definition at line 42 of file 2d.hpp.

◆ c1

template<typename T >
T plask::Vec< 2, T >::c1

Definition at line 42 of file 2d.hpp.

◆ DIMS

template<typename T >
const int plask::Vec< 2, T >::DIMS = 2
static

Definition at line 40 of file 2d.hpp.


The documentation for this struct was generated from the following file: