HighMap library (C++)
Loading...
Searching...
No Matches
hmap::Vec4< T > Struct Template Reference

Vec4 class for basic manipulation of 4D vectors. More...

#include <algebra.hpp>

Public Member Functions

 Vec4 ()
 Default constructor initializing the vector to (0, 0, 0, 0).
 
 Vec4 (T a, T b, T c, T d)
 Parameterized constructor initializing the vector to given values.
 
 Vec4 (const std::vector< T > &vec)
 Constructs a Vec4 object from a std::vector.
 
bool operator== (const Vec4 &other_vec) const
 Equality operator.
 
bool operator!= (const Vec4 &other_vec) const
 Inequality operator.
 
Vec4operator/= (const T value)
 Division-assignment operator.
 
Vec4 operator/ (const Vec4 &other_vec) const
 Division operator.
 
Vec4 operator* (const Vec4 &other_vec) const
 Multiplication operator.
 
Vec4 operator+ (const Vec4 &other_vec) const
 Addition operator.
 
Vec4 operator- (const Vec4 &other_vec) const
 Subtraction operator.
 
Vec4 operator* (T scalar) const
 Scalar multiplication (Vec4 * scalar).
 
Vec4< T > adjust (float da, float db, float dc, float dd)
 Adjusts the components of the vector by the given offsets.
 

Public Attributes

a
 
b
 
c
 
d
 The a, b, c, and d components of the vector.
 

Friends

Vec4 operator* (T scalar, const Vec4 &vec)
 Scalar multiplication (scalar * Vec4).
 
float dot (const Vec4 v1, const Vec4 v2)
 Friend function to calculate the dot product of two vectors.
 

Detailed Description

template<typename T>
struct hmap::Vec4< T >

Vec4 class for basic manipulation of 4D vectors.

This class provides basic operations for 4D vectors, such as addition, subtraction, multiplication, division, and dot product calculation. The class supports various data types through templating.

Template Parameters
TData type for the vector components (e.g., int, float, double).

Constructor & Destructor Documentation

◆ Vec4() [1/3]

template<typename T >
hmap::Vec4< T >::Vec4 ( )
inline

Default constructor initializing the vector to (0, 0, 0, 0).

Initializes the a, b, c, and d components to zero.

◆ Vec4() [2/3]

template<typename T >
hmap::Vec4< T >::Vec4 ( a,
b,
c,
d 
)
inline

Parameterized constructor initializing the vector to given values.

Parameters
aThe a component of the vector.
bThe b component of the vector.
cThe c component of the vector.
dThe d component of the vector.

◆ Vec4() [3/3]

template<typename T >
hmap::Vec4< T >::Vec4 ( const std::vector< T > &  vec)
inline

Constructs a Vec4 object from a std::vector.

This constructor takes a vector containing exactly four elements and assigns the first element to a, the second to b, the third to c, and the fourth to d.

Template Parameters
TThe type of elements in the vector (e.g., float, int, double).
Parameters
vecA const reference to a vector of size 4, where the first element corresponds to a, the second to b, the third to c, and the fourth to d.
Exceptions
std::invalid_argumentIf the vector does not contain exactly four elements.

Member Function Documentation

◆ operator==()

template<typename T >
bool hmap::Vec4< T >::operator== ( const Vec4< T > &  other_vec) const
inline

Equality operator.

Compares two vectors for equality.

Parameters
other_vecThe vector to compare with.
Returns
true if the vectors are equal, false otherwise.

◆ operator!=()

template<typename T >
bool hmap::Vec4< T >::operator!= ( const Vec4< T > &  other_vec) const
inline

Inequality operator.

Compares two vectors for inequality.

Parameters
other_vecThe vector to compare with.
Returns
true if the vectors are not equal, false otherwise.

◆ operator/=()

template<typename T >
Vec4 & hmap::Vec4< T >::operator/= ( const T  value)
inline

Division-assignment operator.

Divides all components of the vector by a scalar value and assigns the result.

Parameters
valueThe scalar value to divide by.
Returns
A reference to the current vector after division.

◆ operator/()

template<typename T >
Vec4 hmap::Vec4< T >::operator/ ( const Vec4< T > &  other_vec) const
inline

Division operator.

Divides each component of the vector by the corresponding component of another vector.

Parameters
other_vecThe vector to divide by.
Returns
A new vector that is the result of the division.

◆ operator*() [1/2]

template<typename T >
Vec4 hmap::Vec4< T >::operator* ( const Vec4< T > &  other_vec) const
inline

Multiplication operator.

Multiplies each component of the vector by the corresponding component of another vector.

Parameters
other_vecThe vector to multiply by.
Returns
A new vector that is the result of the multiplication.

◆ operator+()

template<typename T >
Vec4 hmap::Vec4< T >::operator+ ( const Vec4< T > &  other_vec) const
inline

Addition operator.

Adds each component of the vector to the corresponding component of another vector.

Parameters
other_vecThe vector to add.
Returns
A new vector that is the result of the addition.

◆ operator-()

template<typename T >
Vec4 hmap::Vec4< T >::operator- ( const Vec4< T > &  other_vec) const
inline

Subtraction operator.

Subtracts each component of another vector from the corresponding component of this vector.

Parameters
other_vecThe vector to subtract.
Returns
A new vector that is the result of the subtraction.

◆ operator*() [2/2]

template<typename T >
Vec4 hmap::Vec4< T >::operator* ( scalar) const
inline

Scalar multiplication (Vec4 * scalar).

Multiplies each component of the vector by a scalar value.

Parameters
scalarThe scalar value to multiply with.
Returns
Vec4 A new vector with each component multiplied by the scalar.

◆ adjust()

template<typename T >
Vec4< T > hmap::Vec4< T >::adjust ( float  da,
float  db,
float  dc,
float  dd 
)
inline

Adjusts the components of the vector by the given offsets.

This method creates a new vector by adding the specified offsets to the respective components of the current vector.

Template Parameters
TThe type of the vector components.
Parameters
daThe offset to add to the first component (a).
dbThe offset to add to the second component (b).
dcThe offset to add to the third component (c).
ddThe offset to add to the fourth component (d).
Returns
Vec4<T> A new vector with adjusted components.

Friends And Related Symbol Documentation

◆ operator*

template<typename T >
Vec4 operator* ( scalar,
const Vec4< T > &  vec 
)
friend

Scalar multiplication (scalar * Vec4).

Multiplies each component of the vector by a scalar value. This function allows expressions where the scalar is on the left side of the multiplication operator.

Parameters
scalarThe scalar value to multiply with.
vecThe vector to multiply.
Returns
Vec4 A new vector with each component multiplied by the scalar.

◆ dot

template<typename T >
float dot ( const Vec4< T >  v1,
const Vec4< T >  v2 
)
friend

Friend function to calculate the dot product of two vectors.

The dot product is the sum of the products of the corresponding components of the vectors.

Parameters
v1The first vector.
v2The second vector.
Returns
The dot product of the two vectors.

Member Data Documentation

◆ a

template<typename T >
T hmap::Vec4< T >::a

◆ b

template<typename T >
T hmap::Vec4< T >::b

◆ c

template<typename T >
T hmap::Vec4< T >::c

◆ d

template<typename T >
T hmap::Vec4< T >::d

The a, b, c, and d components of the vector.


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