HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Friends
v1::geo::vector< T, D > Class Template Reference

#include <hikogui/geometry/vector.hpp>

Public Types

using value_type = T
 
using array_type = numeric_array<value_type, 4>
 

Public Member Functions

constexpr vector (vector const &) noexcept=default
 
constexpr vector (vector &&) noexcept=default
 
constexpr vectoroperator= (vector const &) noexcept=default
 
constexpr vectoroperator= (vector &&) noexcept=default
 
template<int E>
requires (E < D)
constexpr vector (vector< value_type, E > const &other) noexcept
 Construct a vector from a lower dimension vector.
 
template<int E>
requires (E > D)
constexpr vector (vector< value_type, E > const &other) noexcept
 Construct a vector from a higher dimension vector.
 
constexpr operator array_type () const noexcept
 Convert a vector to its array_type-nummeric_array.
 
constexpr vector (array_type const &other) noexcept
 Construct a vector from a array_type-numeric_array.
 
constexpr vector () noexcept
 Construct a empty vector / zero length.
 
constexpr vector (value_type x, value_type y) noexcept
 Construct a 2D vector from x and y elements.
 
constexpr vector (value_type x, value_type y, value_type z=value_type{0}) noexcept
 Construct a 3D vector from x, y and z elements.
 
constexpr value_type & x () noexcept
 Access the x element from the vector.
 
constexpr value_type & y () noexcept
 Access the y element from the vector.
 
constexpr value_type & z () noexcept
 Access the z element from the vector.
 
constexpr value_type constx () const noexcept
 Access the x element from the vector.
 
constexpr value_type consty () const noexcept
 Access the y element from the vector.
 
constexpr value_type constz () const noexcept
 Access the z element from the vector.
 
constexpr vector operator- () const noexcept
 Mirror this vector.
 
template<int E>
requires (E <= D)
constexpr vectoroperator+= (vector< value_type, E > const &rhs) noexcept
 
constexpr bool holds_invariant () const noexcept
 Check if the vector is valid.
 

Friends

constexpr friend vector operator+ (vector const &lhs, vector const &rhs) noexcept
 Add two vectors from each other.
 
constexpr friend vector operator- (vector const &lhs, vector const &rhs) noexcept
 Subtract two vectors from each other.
 
constexpr friend vector operator* (vector const &lhs, value_type const &rhs) noexcept
 Scale the vector by a scaler.
 
constexpr friend vector operator* (value_type const &lhs, vector const &rhs) noexcept
 Scale the vector by a scaler.
 
constexpr friend bool operator== (vector const &lhs, vector const &rhs) noexcept
 Compare if two vectors are equal.
 
constexpr friend value_type squared_hypot (vector const &rhs) noexcept
 Get the squared length of the vector.
 
constexpr friend value_type hypot (vector const &rhs) noexcept
 Get the length of the vector.
 
constexpr friend value_type rcp_hypot (vector const &rhs) noexcept
 Get the length of the vector.
 
constexpr friend vector normalize (vector const &rhs) noexcept
 Normalize a vector to a unit vector.
 
constexpr friend value_type dot (vector const &lhs, vector const &rhs) noexcept
 Get the dot product between two vectors.
 
constexpr friend value_type det (vector const &lhs, vector const &rhs) noexcept
 Get the determinate between two vectors.
 
template<int E>
constexpr auto min (vector const &lhs, vector< value_type, E > const &rhs) noexcept
 Mix the two vectors and get the lowest value of each element.
 
template<int E>
constexpr auto max (vector const &lhs, vector< value_type, E > const &rhs) noexcept
 Mix the two vectors and get the highest value of each element.
 
constexpr vector round (vector const &rhs) noexcept
 Round the elements of the vector toward nearest integer.
 
constexpr vector ceil (vector const &rhs) noexcept
 Round the elements of the vector toward upward and to the right.
 
constexpr vector floor (vector const &rhs) noexcept
 Round the elements of the vector toward downward and to the left.
 
std::string to_string (vector const &rhs) noexcept
 
std::ostreamoperator<< (std::ostream &lhs, vector const &rhs) noexcept
 

Detailed Description

template<typename T, int D>
class v1::geo::vector< T, D >

A high-level geometric vector Part of the high-level vector, point, mat and color types.

A vector, for both 2D or 3D is internally represented as a 4D homogeneous vector. Which can be efficiently implemented as a __m128 SSE register.

Constructor & Destructor Documentation

◆ vector() [1/6]

template<typename T , int D>
template<int E>
requires (E < D)
constexpr v1::geo::vector< T, D >::vector ( vector< value_type, E > const & other)
inlineconstexprnoexcept

Construct a vector from a lower dimension vector.

◆ vector() [2/6]

template<typename T , int D>
template<int E>
requires (E > D)
constexpr v1::geo::vector< T, D >::vector ( vector< value_type, E > const & other)
inlineexplicitconstexprnoexcept

Construct a vector from a higher dimension vector.

This will clear the values in the higher dimensions.

◆ vector() [3/6]

template<typename T , int D>
constexpr v1::geo::vector< T, D >::vector ( array_type const & other)
inlineexplicitconstexprnoexcept

Construct a vector from a array_type-numeric_array.

◆ vector() [4/6]

template<typename T , int D>
constexpr v1::geo::vector< T, D >::vector ( )
inlineconstexprnoexcept

Construct a empty vector / zero length.

◆ vector() [5/6]

template<typename T , int D>
constexpr v1::geo::vector< T, D >::vector ( value_type x,
value_type y )
inlineconstexprnoexcept

Construct a 2D vector from x and y elements.

Parameters
xThe x element.
yThe y element.

◆ vector() [6/6]

template<typename T , int D>
constexpr v1::geo::vector< T, D >::vector ( value_type x,
value_type y,
value_type z = value_type{0} )
inlineconstexprnoexcept

Construct a 3D vector from x, y and z elements.

Parameters
xThe x element.
yThe y element.
zThe z element.

Member Function Documentation

◆ holds_invariant()

template<typename T , int D>
constexpr bool v1::geo::vector< T, D >::holds_invariant ( ) const
inlineconstexprnoexcept

Check if the vector is valid.

This function will check if w is zero, and with 2D vector is z is zero.

◆ operator array_type()

template<typename T , int D>
constexpr v1::geo::vector< T, D >::operator array_type ( ) const
inlineexplicitconstexprnoexcept

Convert a vector to its array_type-nummeric_array.

◆ operator-()

template<typename T , int D>
constexpr vector v1::geo::vector< T, D >::operator- ( ) const
inlineconstexprnoexcept

Mirror this vector.

Returns
The mirrored vector.

◆ x() [1/2]

template<typename T , int D>
constexpr value_type const & v1::geo::vector< T, D >::x ( ) const
inlineconstexprnoexcept

Access the x element from the vector.

Returns
a reference to the x element.

◆ x() [2/2]

template<typename T , int D>
constexpr value_type & v1::geo::vector< T, D >::x ( )
inlineconstexprnoexcept

Access the x element from the vector.

Returns
a reference to the x element.

◆ y() [1/2]

template<typename T , int D>
constexpr value_type const & v1::geo::vector< T, D >::y ( ) const
inlineconstexprnoexcept

Access the y element from the vector.

Returns
a reference to the y element.

◆ y() [2/2]

template<typename T , int D>
constexpr value_type & v1::geo::vector< T, D >::y ( )
inlineconstexprnoexcept

Access the y element from the vector.

Returns
a reference to the y element.

◆ z() [1/2]

template<typename T , int D>
constexpr value_type const & v1::geo::vector< T, D >::z ( ) const
inlineconstexprnoexcept

Access the z element from the vector.

Returns
a reference to the z element.

◆ z() [2/2]

template<typename T , int D>
constexpr value_type & v1::geo::vector< T, D >::z ( )
inlineconstexprnoexcept

Access the z element from the vector.

Returns
a reference to the z element.

Friends And Related Symbol Documentation

◆ ceil

template<typename T , int D>
constexpr vector ceil ( vector< T, D > const & rhs)
friend

Round the elements of the vector toward upward and to the right.

◆ det

template<typename T , int D>
constexpr friend value_type det ( vector< T, D > const & lhs,
vector< T, D > const & rhs )
friend

Get the determinate between two vectors.

Parameters
lhsThe first vector.
rhsThe second vector.
Returns
The dot product from the two given vectors.

◆ dot

template<typename T , int D>
constexpr friend value_type dot ( vector< T, D > const & lhs,
vector< T, D > const & rhs )
friend

Get the dot product between two vectors.

Parameters
lhsThe first vector.
rhsThe second vector.
Returns
The dot product from the two given vectors.

◆ floor

template<typename T , int D>
constexpr vector floor ( vector< T, D > const & rhs)
friend

Round the elements of the vector toward downward and to the left.

◆ hypot

template<typename T , int D>
constexpr friend value_type hypot ( vector< T, D > const & rhs)
friend

Get the length of the vector.

Parameters
rhsThe vector.
Returns
The length of the vector.

◆ max

template<typename T , int D>
template<int E>
constexpr auto max ( vector< T, D > const & lhs,
vector< value_type, E > const & rhs )
friend

Mix the two vectors and get the highest value of each element.

Parameters
lhsThe first vector.
rhsThe first vector.
Returns
A vector that points the most right of both vectors, and most upward of both vectors.

◆ min

template<typename T , int D>
template<int E>
constexpr auto min ( vector< T, D > const & lhs,
vector< value_type, E > const & rhs )
friend

Mix the two vectors and get the lowest value of each element.

Parameters
lhsThe first vector.
rhsThe first vector.
Returns
A vector that points the most left of both vectors, and most downward of both vectors.

◆ normalize

template<typename T , int D>
constexpr friend vector normalize ( vector< T, D > const & rhs)
friend

Normalize a vector to a unit vector.

Parameters
rhsThe vector.
Returns
A vector with the same direction as the given vector, but its length is 1.0.

◆ operator* [1/2]

template<typename T , int D>
constexpr friend vector operator* ( value_type const & lhs,
vector< T, D > const & rhs )
friend

Scale the vector by a scaler.

Parameters
lhsThe vector to scale.
rhsThe scaling factor.
Returns
The scaled vector.

◆ operator* [2/2]

template<typename T , int D>
constexpr friend vector operator* ( vector< T, D > const & lhs,
value_type const & rhs )
friend

Scale the vector by a scaler.

Parameters
lhsThe vector to scale.
rhsThe scaling factor.
Returns
The scaled vector.

◆ operator+

template<typename T , int D>
constexpr friend vector operator+ ( vector< T, D > const & lhs,
vector< T, D > const & rhs )
friend

Add two vectors from each other.

Parameters
lhsThe first vector.
rhsThe second vector.
Returns
A new vector.

◆ operator-

template<typename T , int D>
constexpr friend vector operator- ( vector< T, D > const & lhs,
vector< T, D > const & rhs )
friend

Subtract two vectors from each other.

Parameters
lhsThe first vector.
rhsThe second vector.
Returns
A new vector.

◆ operator==

template<typename T , int D>
constexpr friend bool operator== ( vector< T, D > const & lhs,
vector< T, D > const & rhs )
friend

Compare if two vectors are equal.

Parameters
lhsThe first vector.
rhsThe second vector.
Returns
True if both vectors are completely equal to each other.

◆ rcp_hypot

template<typename T , int D>
constexpr friend value_type rcp_hypot ( vector< T, D > const & rhs)
friend

Get the length of the vector.

Parameters
rhsThe vector.
Returns
One over the length of the vector.

◆ round

template<typename T , int D>
constexpr vector round ( vector< T, D > const & rhs)
friend

Round the elements of the vector toward nearest integer.

◆ squared_hypot

template<typename T , int D>
constexpr friend value_type squared_hypot ( vector< T, D > const & rhs)
friend

Get the squared length of the vector.

Parameters
rhsThe vector.
Returns
The length of the vector.

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