Easy3D 2.6.1
Loading...
Searching...
No Matches
Vec< 2, T > Class Template Reference

Specialization of Vec for 2D vectors (used for representing 2D points or vectors). More...

#include <easy3d/core/vec.h>

Public Types

typedef Vec< 2, T > thisclass
 The type of this class.
 

Public Member Functions

 Vec ()
 Default constructor. Initializes x and y to zero.
 
 Vec (T x_in, T y_in)
 Constructs a 2D vector with the given x and y values.
 
 Vec (const Vec< 3, T > &v)
 Constructs a 2D vector from a 3D vector (drops the z-coordinate).
 
 Vec (const T &s)
 Constructs a 2D vector with all elements initialized to a scalar value.
 
template<class T2 >
 Vec (const Vec< 2, T2 > &v)
 Constructs a 2D vector from another 2D vector of a different scalar type.
 
template<class T2 >
 Vec (const T2 *v)
 Constructs a 2D vector from an array of values.
 
T length2 () const
 Returns the squared length of this vector.
 
T length () const
 Returns the length of this vector.
 
T norm () const
 Returns the norm (i.e., length/magnitude) of this vector.
 
T distance2 (const thisclass &rhs) const
 Returns the squared Euclidean distance to another vector.
 
thisclass & normalize ()
 Normalizes this vector.
 
thisclass & operator+= (const thisclass &v)
 Compound addition with another vector.
 
thisclass & operator-= (const thisclass &v)
 Compound subtraction with another vector.
 
thisclass & operator*= (const thisclass &v)
 Compound component-wise multiplication with another vector.
 
thisclass & operator/= (const thisclass &v)
 Compound component-wise division with another vector.
 
template<class T2 >
thisclass & operator*= (T2 s)
 Compound vector-scalar multiplication.
 
template<class T2 >
thisclass & operator/= (T2 s)
 Compound vector-scalar division.
 
thisclass operator+ (const thisclass &v) const
 Addition with another vector.
 
thisclass operator- (const thisclass &v) const
 Subtraction with another vector.
 
template<class T2 >
thisclass operator* (T2 s) const
 Vector-scalar multiplication.
 
template<class T2 >
thisclass operator/ (T2 s) const
 Vector-scalar division.
 
thisclass operator- () const
 Negates this vector (i.e., adds a minus sign).
 
T * data ()
 Returns the memory address of the vector.
 
const T * data () const
 Returns the constant memory address of the vector.
 
 operator const T * () const
 Conversion operator returning the constant memory address of the data. Very convenient to pass this vector as a data pointer to functions.
 
 operator T* ()
 Conversion operator returning the memory address of the data. Very convenient to pass this vector as a data pointer to functions.
 

Static Public Member Functions

static size_t dimension ()
 Returns the dimension/size of this vector.
 
static size_t size ()
 Returns the dimension/size of this vector.
 

Public Attributes

union easy3d::Vec< 2, T >:: { ... }  
 Data intentionally left public to allow direct access (e.g., vec.x).
 

Detailed Description

template<class T>
class easy3d::Vec< 2, T >

Specialization of Vec for 2D vectors (used for representing 2D points or vectors).

Template Parameters
TThe scalar type of vector elements.

Member Typedef Documentation

◆ thisclass

template<class T >
typedef Vec<2, T> thisclass

The type of this class.

This typedef represents the type of the current class.

Constructor & Destructor Documentation

◆ Vec() [1/5]

template<class T >
Vec ( T  x_in,
T  y_in 
)
inline

Constructs a 2D vector with the given x and y values.

Parameters
x_inThe x-coordinate.
y_inThe y-coordinate.

◆ Vec() [2/5]

template<class T >
Vec ( const Vec< 3, T > &  v)
inlineexplicit

Constructs a 2D vector from a 3D vector (drops the z-coordinate).

Parameters
vThe 3D vector to promote from.

◆ Vec() [3/5]

template<class T >
Vec ( const T &  s)
inlineexplicit

Constructs a 2D vector with all elements initialized to a scalar value.

Parameters
sThe scalar value to initialize all elements of the vector.

◆ Vec() [4/5]

template<class T >
template<class T2 >
Vec ( const Vec< 2, T2 > &  v)
inlineexplicit

Constructs a 2D vector from another 2D vector of a different scalar type.

Template Parameters
T2The scalar type of the source vector.
Parameters
vThe source vector.

◆ Vec() [5/5]

template<class T >
template<class T2 >
Vec ( const T2 *  v)
inlineexplicit

Constructs a 2D vector from an array of values.

Template Parameters
T2The scalar type of the source array.
Parameters
vThe source array.

Member Function Documentation

◆ data() [1/2]

template<class T >
T * data ( )
inline

Returns the memory address of the vector.

Returns
A pointer to the underlying data array.

◆ data() [2/2]

template<class T >
const T * data ( ) const
inline

Returns the constant memory address of the vector.

Returns
A const pointer to the underlying data array.

◆ dimension()

template<class T >
static size_t dimension ( )
inlinestatic

Returns the dimension/size of this vector.

Returns
The dimension of the vector (always 2).

◆ distance2()

template<class T >
T distance2 ( const thisclass &  rhs) const
inline

Returns the squared Euclidean distance to another vector.

Parameters
rhsThe other vector.
Returns
The squared distance between this vector and rhs.

◆ length()

template<class T >
T length ( ) const
inline

Returns the length of this vector.

Returns
The length of the vector.

◆ length2()

template<class T >
T length2 ( ) const
inline

Returns the squared length of this vector.

Returns
The squared length of the vector.

◆ norm()

template<class T >
T norm ( ) const
inline

Returns the norm (i.e., length/magnitude) of this vector.

Returns
The norm of the vector.

◆ normalize()

template<class T >
thisclass & normalize ( )
inline

Normalizes this vector.

Returns
A reference to this vector after normalization.

◆ operator const T *()

template<class T >
operator const T * ( ) const
inline

Conversion operator returning the constant memory address of the data. Very convenient to pass this vector as a data pointer to functions.

Returns
A const pointer to the underlying data array.

◆ operator T*()

template<class T >
operator T* ( )
inline

Conversion operator returning the memory address of the data. Very convenient to pass this vector as a data pointer to functions.

Returns
A pointer to the underlying data array.

◆ operator*()

template<class T >
template<class T2 >
thisclass operator* ( T2  s) const
inline

Vector-scalar multiplication.

Template Parameters
T2The scalar type.
Parameters
sThe scalar to multiply.
Returns
The resulting vector after multiplication.

◆ operator*=() [1/2]

template<class T >
thisclass & operator*= ( const thisclass &  v)
inline

Compound component-wise multiplication with another vector.

Parameters
vThe vector to multiply.
Returns
A reference to this vector after multiplication.

◆ operator*=() [2/2]

template<class T >
template<class T2 >
thisclass & operator*= ( T2  s)
inline

Compound vector-scalar multiplication.

Template Parameters
T2The scalar type.
Parameters
sThe scalar to multiply.
Returns
A reference to this vector after multiplication.

◆ operator+()

template<class T >
thisclass operator+ ( const thisclass &  v) const
inline

Addition with another vector.

Parameters
vThe vector to add.
Returns
The resulting vector after addition.

◆ operator+=()

template<class T >
thisclass & operator+= ( const thisclass &  v)
inline

Compound addition with another vector.

Parameters
vThe vector to add.
Returns
A reference to this vector after addition.

◆ operator-() [1/2]

template<class T >
thisclass operator- ( ) const
inline

Negates this vector (i.e., adds a minus sign).

Returns
The negated vector.

◆ operator-() [2/2]

template<class T >
thisclass operator- ( const thisclass &  v) const
inline

Subtraction with another vector.

Parameters
vThe vector to subtract.
Returns
The resulting vector after subtraction.

◆ operator-=()

template<class T >
thisclass & operator-= ( const thisclass &  v)
inline

Compound subtraction with another vector.

Parameters
vThe vector to subtract.
Returns
A reference to this vector after subtraction.

◆ operator/()

template<class T >
template<class T2 >
thisclass operator/ ( T2  s) const
inline

Vector-scalar division.

Template Parameters
T2The scalar type.
Parameters
sThe scalar to divide.
Returns
The resulting vector after division.

◆ operator/=() [1/2]

template<class T >
thisclass & operator/= ( const thisclass &  v)
inline

Compound component-wise division with another vector.

Parameters
vThe vector to divide.
Returns
A reference to this vector after division.

◆ operator/=() [2/2]

template<class T >
template<class T2 >
thisclass & operator/= ( T2  s)
inline

Compound vector-scalar division.

Template Parameters
T2The scalar type.
Parameters
sThe scalar to divide.
Returns
A reference to this vector after division.

◆ size()

template<class T >
static size_t size ( )
inlinestatic

Returns the dimension/size of this vector.

Returns
The size of the vector (always 2).

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