t
Loading...
Searching...
No Matches
t::Vector4 Class Reference

The 4D vector class. More...

#include <Vector4.hpp>

Public Member Functions

 Vector4 (double _x, double _y, double _z, double _w)
 Creates a new 4D vector with the specified components.
 
 Vector4 (const Vector3 &vector3, double w)
 Creates a new 4D vector with the same x, y, and z components as the specified 3D vector and the specified w component.
 
Vector4 clone () const
 Returns a copy of this 4D vector.
 
Vector4copy (const Vector4 &source)
 Copies the components of the specified 4D vector to this 4D vector.
 
Vector4set (double _x, double _y, double _z, double _w)
 Sets the components of this 4D vector.
 
Vector3 toVector3 () const
 Returns the 3D vector represented by the x, y, and z components of this 4D vector with perspective division.
 
double length () const
 Returns the length of this 4D vector.
 
Vector4 unit () const
 Returns the unit vector of this 4D vector.
 
Vector4normalize ()
 Normalizes this 4D vector.
 
Vector4 absolute () const
 Returns a new 4D vector with the absolute values of the components of this 4D vector.
 
Vector4abs ()
 Sets the components of this 4D vector to their absolute values.
 
Vector4clamp (const Vector4 &min, const Vector4 &max)
 Clamps the components of this 4D vector to the specified minimum and maximum 4D vectors component-wise.
 
Vector4clamp (double min, double max)
 Clamps the components of this 4D vector to the specified minimum and maximum values.
 
double operator[] (std::size_t index) const
 Returns the component at the specified index of this 4D vector.
 
Vector4operator+= (const Vector4 &v)
 Adds the specified 4D vector to this vector.
 
Vector4operator+= (double s)
 Adds the specified constant to all components in this 4D vector.
 
Vector4operator-= (const Vector4 &v)
 Subtracts the specified 4D vector from this vector.
 
Vector4operator-= (double s)
 Subtracts the specified constant from all components in this 4D vector.
 
Vector4operator*= (const Vector4 &v)
 Multiplies the components of this vector with the corresponding components of the specified 4D vector.
 
Vector4operator*= (double s)
 Multiplies all components of this 4D vector with the specified constant.
 
Vector4operator/= (const Vector4 &v)
 Divides the components of this vector by the corresponding components of another 4D vector.
 
Vector4operator/= (double s)
 Divides the components of this 4D vector by the specified constant.
 

Public Attributes

double x
 The x component of this 4D vector.
 
double y
 The y component of this 4D vector.
 
double z
 The w component of this 4D vector.
 
double w
 The z component of this 4D vector.
 

Friends

bool operator== (const Vector4 &a, const Vector4 &b)=default
 Returns whether if two 4D vectors are equal.
 
Vector4 operator- (const Vector4 &a)
 Returns the negation of this 4D vector.
 
Vector4 operator+ (const Vector4 &a, const Vector4 &b)
 Adds two 4D vectors.
 
Vector4 operator+ (const Vector4 &a, double s)
 Adds a constant to all components of a 4D vector.
 
Vector4 operator+ (double s, const Vector4 &a)
 Adds a constant to all components of a 4D vector.
 
Vector4 operator- (const Vector4 &a, const Vector4 &b)
 Subtracts two 4D vectors.
 
Vector4 operator- (const Vector4 &a, double s)
 Subtracts a constant from all components of a 4D vector.
 
Vector4 operator- (double s, const Vector4 &a)
 Subtracts a 4D vector from a constant 4D vector.
 
Vector4 operator* (const Vector4 &a, const Vector4 &b)
 Returns the element-wise product of two 4D vectors, also known as the Hadamard product.
 
Vector4 operator* (const Vector4 &a, double s)
 Multiplies all components of a 4D vector with a constant.
 
Vector4 operator* (double s, const Vector4 &a)
 Multiplies all components of a 4D vector with a constant.
 
Vector4 operator/ (const Vector4 &a, const Vector4 &b)
 Returns the element-wise division of two 4D vectors.
 
Vector4 operator/ (const Vector4 &a, double s)
 Divides the components of a 4D vector by a constant.
 
Vector4 operator/ (double s, const Vector4 &a)
 Returns the element-wise division of a constant 4D vector and a 4D vector.
 

Detailed Description

The 4D vector class.

A 4D vector is a triplet of numbers labeled x, y, z, and w which can be used to represent a number of things e.g. 4D homogeneous coordinates, RGBA colors, etc.

Constructor & Destructor Documentation

◆ Vector4() [1/2]

t::Vector4::Vector4 ( double _x,
double _y,
double _z,
double _w )
inline

Creates a new 4D vector with the specified components.

Parameters
_xThe x component of the new 4D vector.
_yThe y component of the new 4D vector.
_zThe z component of the new 4D vector.
_wThe w component of the new 4D vector.

◆ Vector4() [2/2]

t::Vector4::Vector4 ( const Vector3 & vector3,
double w )
inline

Creates a new 4D vector with the same x, y, and z components as the specified 3D vector and the specified w component.

Parameters
vector3A 3D vector to copy the x, y, and z components from.
wThe w component of the new 4D vector.

Member Function Documentation

◆ abs()

Vector4 & t::Vector4::abs ( )
inline

Sets the components of this 4D vector to their absolute values.

Note that this method modifies this instance. If you want to avoid modification, use absolute instead.

Returns
This vector.

◆ absolute()

Vector4 t::Vector4::absolute ( ) const
inline

Returns a new 4D vector with the absolute values of the components of this 4D vector.

Returns
A new vector with the absolute values of the components of this vector.

◆ clamp() [1/2]

Vector4 & t::Vector4::clamp ( const Vector4 & min,
const Vector4 & max )
inline

Clamps the components of this 4D vector to the specified minimum and maximum 4D vectors component-wise.

Parameters
minThe minimum 4D vector.
maxThe maximum 4D vector.
Returns
This vector.

◆ clamp() [2/2]

Vector4 & t::Vector4::clamp ( double min,
double max )
inline

Clamps the components of this 4D vector to the specified minimum and maximum values.

Parameters
minThe minimum value.
maxThe maximum value.
Returns
This vector.

◆ clone()

Vector4 t::Vector4::clone ( ) const
inline

Returns a copy of this 4D vector.

Returns
A new 4D vector with the same components as this vector.

◆ copy()

Vector4 & t::Vector4::copy ( const Vector4 & source)
inline

Copies the components of the specified 4D vector to this 4D vector.

Parameters
sourceA 4D vector to copy the components from.
Returns
This vector.

◆ length()

double t::Vector4::length ( ) const
inline

Returns the length of this 4D vector.

Specifically, returns the Euclidean length.

Returns
The length of this vector.

◆ normalize()

Vector4 & t::Vector4::normalize ( )
inline

Normalizes this 4D vector.

Note that this method modifies this instance. If you want to avoid modification, use unit instead.

Returns
This vector.

◆ operator*=() [1/2]

Vector4 & t::Vector4::operator*= ( const Vector4 & v)
inline

Multiplies the components of this vector with the corresponding components of the specified 4D vector.

Parameters
vA 4D vector.
Returns
This vector.

◆ operator*=() [2/2]

Vector4 & t::Vector4::operator*= ( double s)
inline

Multiplies all components of this 4D vector with the specified constant.

Parameters
sA constant.
Returns
This vector.

◆ operator+=() [1/2]

Vector4 & t::Vector4::operator+= ( const Vector4 & v)
inline

Adds the specified 4D vector to this vector.

Parameters
vA 4D vector.
Returns
This vector.

◆ operator+=() [2/2]

Vector4 & t::Vector4::operator+= ( double s)
inline

Adds the specified constant to all components in this 4D vector.

Parameters
sA constant.
Returns
This vector.

◆ operator-=() [1/2]

Vector4 & t::Vector4::operator-= ( const Vector4 & v)
inline

Subtracts the specified 4D vector from this vector.

Parameters
vA 4D vector.
Returns
This vector.

◆ operator-=() [2/2]

Vector4 & t::Vector4::operator-= ( double s)
inline

Subtracts the specified constant from all components in this 4D vector.

Parameters
sA constant.
Returns
This vector.

◆ operator/=() [1/2]

Vector4 & t::Vector4::operator/= ( const Vector4 & v)
inline

Divides the components of this vector by the corresponding components of another 4D vector.

Parameters
vA 4D vector.
Returns
This vector.

◆ operator/=() [2/2]

Vector4 & t::Vector4::operator/= ( double s)
inline

Divides the components of this 4D vector by the specified constant.

Parameters
sA constant.
Returns
This vector.

◆ operator[]()

double t::Vector4::operator[] ( std::size_t index) const
inline

Returns the component at the specified index of this 4D vector.

Parameters
indexA 0-based index. Must be 0, 1, 2, or 3.
Returns
The component at index.
Exceptions
std::invalid_argumentif index is not 0, 1, 2, or 3.

◆ set()

Vector4 & t::Vector4::set ( double _x,
double _y,
double _z,
double _w )
inline

Sets the components of this 4D vector.

Parameters
_xThe new x component.
_yThe new y component.
_zThe new z component.
_wThe new w component.
Returns
This vector.

◆ toVector3()

Vector3 t::Vector4::toVector3 ( ) const
inline

Returns the 3D vector represented by the x, y, and z components of this 4D vector with perspective division.

That is, if this 4D vector is \((x, y, z, w)\), then return the 3D vector \((x/w, y/w, z/w)\).

Returns
The 3D vector represented by the x, y, and z components of this 4D vector with perspective division.

◆ unit()

Vector4 t::Vector4::unit ( ) const
inline

Returns the unit vector of this 4D vector.

Returns
The unit vector of this vector.

Friends And Related Symbol Documentation

◆ operator* [1/3]

Vector4 operator* ( const Vector4 & a,
const Vector4 & b )
friend

Returns the element-wise product of two 4D vectors, also known as the Hadamard product.

Parameters
aA 4D vector.
bAnother 4D vector.
Returns
The element-wise product of a and b.

◆ operator* [2/3]

Vector4 operator* ( const Vector4 & a,
double s )
friend

Multiplies all components of a 4D vector with a constant.

Parameters
aA 4D vector.
sA constant.
Returns
The resulting vector when multiplying the components of a with s.

◆ operator* [3/3]

Vector4 operator* ( double s,
const Vector4 & a )
friend

Multiplies all components of a 4D vector with a constant.

Parameters
sA constant.
aA 4D vector.
Returns
The resulting vector when multiplying the components of a with s.

◆ operator+ [1/3]

Vector4 operator+ ( const Vector4 & a,
const Vector4 & b )
friend

Adds two 4D vectors.

Parameters
aA 4D vector.
bAnother 4D vector.
Returns
The sum of a and b.

◆ operator+ [2/3]

Vector4 operator+ ( const Vector4 & a,
double s )
friend

Adds a constant to all components of a 4D vector.

Parameters
aA 4D vector.
sA constant.
Returns
The resulting vector when adding s to the components of a.

◆ operator+ [3/3]

Vector4 operator+ ( double s,
const Vector4 & a )
friend

Adds a constant to all components of a 4D vector.

Parameters
sA constant.
aA 4D vector.
Returns
The resulting vector when adding s to the components of a.

◆ operator- [1/4]

Vector4 operator- ( const Vector4 & a)
friend

Returns the negation of this 4D vector.

Returns
The negation of this 4D vector.

◆ operator- [2/4]

Vector4 operator- ( const Vector4 & a,
const Vector4 & b )
friend

Subtracts two 4D vectors.

Parameters
aA 4D vector.
bAnother 4D vector.
Returns
The difference of a and b.

◆ operator- [3/4]

Vector4 operator- ( const Vector4 & a,
double s )
friend

Subtracts a constant from all components of a 4D vector.

Parameters
aA 4D vector.
sA constant.
Returns
The resulting vector when subtracting s from the components of a.

◆ operator- [4/4]

Vector4 operator- ( double s,
const Vector4 & a )
friend

Subtracts a 4D vector from a constant 4D vector.

A constant vector is a vector whose components are all the same.

Parameters
sA constant for the constant 4D vector.
aA 4D vector.
Returns
The resulting vector when subtracting the components of a from the constant vector of s.

◆ operator/ [1/3]

Vector4 operator/ ( const Vector4 & a,
const Vector4 & b )
friend

Returns the element-wise division of two 4D vectors.

Parameters
aA 4D vector.
bAnother 4D vector.
Returns
The element-wise division a and b.

◆ operator/ [2/3]

Vector4 operator/ ( const Vector4 & a,
double s )
friend

Divides the components of a 4D vector by a constant.

Parameters
aA 4D vector.
sA constant.
Returns
The resulting vector when dividing the components of a by s.

◆ operator/ [3/3]

Vector4 operator/ ( double s,
const Vector4 & a )
friend

Returns the element-wise division of a constant 4D vector and a 4D vector.

A constant vector is a vector whose components are all the same.

Parameters
sA constant for the constant 4D vector.
aA 4D vector.
Returns
The element-wise division of the constant 4D vector and a.

◆ operator==

bool operator== ( const Vector4 & a,
const Vector4 & b )
friend

Returns whether if two 4D vectors are equal.

Returns
true if the two vectors are equal, false otherwise.

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