HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Friends
tt::vec Class Reference

#include <TTauri/Foundation/vec.hpp>

Public Member Functions

tt_force_inline vec (vec const &rhs) noexcept=default
 
tt_force_inline vecoperator= (vec const &rhs) noexcept=default
 
tt_force_inline vec (vec &&rhs) noexcept=default
 
tt_force_inline vecoperator= (vec &&rhs) noexcept=default
 
tt_force_inline vec (__m128 rhs) noexcept
 
tt_force_inline vecoperator= (__m128 rhs) noexcept
 
tt_force_inline operator __m128 () const noexcept
 
tt_force_inline vec (std::array< float, 4 > const &rhs) noexcept
 
tt_force_inline vecoperator= (std::array< float, 4 > const &rhs) noexcept
 
tt_force_inline operator std::array< float, 4 > () const noexcept
 
tt_force_inline vec (std::array< float, 2 > const &rhs) noexcept
 
tt_force_inline vecoperator= (std::array< float, 2 > const &rhs) noexcept
 
tt_force_inline operator std::array< float, 2 > () const noexcept
 
tt_force_inline vec (std::array< float16, 4 > const &rhs) noexcept
 
tt_force_inline vecoperator= (std::array< float16, 4 > const &rhs) noexcept
 
tt_force_inline operator std::array< float16, 4 > () const noexcept
 
template<typename T , std::enable_if_t< std::is_arithmetic_v< T >, int > = 0>
tt_force_inline vec (T rhs) noexcept
 Initialize a vec with all elements set to a value.
 
tt_force_inline vecoperator= (float rhs) noexcept
 Initialize a vec with all elements set to a value.
 
tt_force_inline vec (float x, float y, float z=0.0f, float w=0.0f) noexcept
 Create a vec out of 2 to 4 values.
 
tt_force_inline vec (double x, double y) noexcept
 
tt_force_inline vec (double x, double y, double z, double w=0.0f) noexcept
 
tt_force_inline vec (int x, int y, int z=0, int w=0) noexcept
 
template<size_t I>
tt_force_inline vecset (float rhs) noexcept
 
template<size_t I>
tt_force_inline float get () const noexcept
 
tt_force_inline bool is_point () const noexcept
 
tt_force_inline bool is_vector () const noexcept
 
tt_force_inline bool is_opaque () const noexcept
 
tt_force_inline bool is_transparent () const noexcept
 
constexpr size_t size () const noexcept
 
tt_force_inline float operator[] (size_t i) const noexcept
 
tt_force_inline vecx (float rhs) noexcept
 
tt_force_inline vecy (float rhs) noexcept
 
tt_force_inline vecz (float rhs) noexcept
 
tt_force_inline vecw (float rhs) noexcept
 
tt_force_inline vecr (float rhs) noexcept
 
tt_force_inline vecg (float rhs) noexcept
 
tt_force_inline vecb (float rhs) noexcept
 
tt_force_inline veca (float rhs) noexcept
 
tt_force_inline vecwidth (float rhs) noexcept
 
tt_force_inline vecheight (float rhs) noexcept
 
tt_force_inline vecdepth (float rhs) noexcept
 
tt_force_inline float x () const noexcept
 
tt_force_inline float y () const noexcept
 
tt_force_inline float z () const noexcept
 
tt_force_inline float w () const noexcept
 
tt_force_inline float r () const noexcept
 
tt_force_inline float g () const noexcept
 
tt_force_inline float b () const noexcept
 
tt_force_inline float a () const noexcept
 
tt_force_inline float width () const noexcept
 
tt_force_inline float height () const noexcept
 
tt_force_inline float depth () const noexcept
 
tt_force_inline vecoperator+= (vec const &rhs) noexcept
 
tt_force_inline vecoperator-= (vec const &rhs) noexcept
 
tt_force_inline vecoperator*= (vec const &rhs) noexcept
 
tt_force_inline vecoperator/= (vec const &rhs) noexcept
 
vec resize2DRetainingAspectRatio (vec const &rhs) noexcept
 Resize an extent while retaining aspect ratio.
 
template<char a, char b, char c, char d>
tt_force_inline vec swizzle () const noexcept
 

Static Public Member Functions

template<typename T , std::enable_if_t< std::is_arithmetic_v< T >, int > = 0>
static tt_force_inline vec make_x (T x) noexcept
 
template<typename T , std::enable_if_t< std::is_arithmetic_v< T >, int > = 0>
static tt_force_inline vec make_y (T y) noexcept
 
template<typename T , std::enable_if_t< std::is_arithmetic_v< T >, int > = 0>
static tt_force_inline vec make_z (T z) noexcept
 
template<typename T , std::enable_if_t< std::is_arithmetic_v< T >, int > = 0>
static tt_force_inline vec make_w (T w) noexcept
 
static tt_force_inline vec point (float x=0.0f, float y=0.0f, float z=0.0f) noexcept
 Create a point out of 2 to 4 values.
 
static tt_force_inline vec point (int x=0.0f, int y=0.0f, int z=0.0f) noexcept
 
static tt_force_inline vec point (vec rhs) noexcept
 Create a point out of 2 to 4 values.
 
static tt_force_inline vec origin () noexcept
 Get a origin vector(0.0, 0.0, 0.0, 1.0).
 
static tt_force_inline vec color (float r, float g, float b, float a=1.0f) noexcept
 Create a color out of 3 to 4 values.
 
static vec colorFromSRGB (float r, float g, float b, float a=1.0f) noexcept
 
static vec colorFromSRGB (uint8_t r, uint8_t g, uint8_t b, uint8_t a=255) noexcept
 
static vec colorFromSRGB (std::string_view str)
 
template<char a, char b, char c, char d>
static constexpr int swizzle_permute_mask () noexcept
 
template<char a, char b, char c, char d>
static constexpr int swizzle_zero_mask () noexcept
 
template<char a, char b, char c, char d>
static constexpr int swizzle_number_mask () noexcept
 

Friends

tt_force_inline friend vec operator- (vec const &rhs) noexcept
 
tt_force_inline friend vec operator+ (vec const &lhs, vec const &rhs) noexcept
 
tt_force_inline friend vec operator- (vec const &lhs, vec const &rhs) noexcept
 
tt_force_inline friend vec operator* (vec const &lhs, vec const &rhs) noexcept
 
template<typename T , std::enable_if_t< std::is_arithmetic_v< T >, int > = 0>
tt_force_inline friend vec operator* (vec const &lhs, T const &rhs) noexcept
 
template<typename T , std::enable_if_t< std::is_arithmetic_v< T >, int > = 0>
tt_force_inline friend vec operator* (T const &lhs, vec const &rhs) noexcept
 
tt_force_inline friend vec operator/ (vec const &lhs, vec const &rhs) noexcept
 
tt_force_inline friend vec max (vec const &lhs, vec const &rhs) noexcept
 
tt_force_inline friend vec min (vec const &lhs, vec const &rhs) noexcept
 
tt_force_inline friend vec abs (vec const &rhs) noexcept
 
tt_force_inline friend int eq (vec const &lhs, vec const &rhs) noexcept
 Equal to.
 
tt_force_inline friend int ne (vec const &lhs, vec const &rhs) noexcept
 Not equal to.
 
tt_force_inline friend bool operator== (vec const &lhs, vec const &rhs) noexcept
 
tt_force_inline friend bool operator!= (vec const &lhs, vec const &rhs) noexcept
 
tt_force_inline friend int operator< (vec const &lhs, vec const &rhs) noexcept
 Less than.
 
tt_force_inline friend int operator<= (vec const &lhs, vec const &rhs) noexcept
 Less than or equal.
 
tt_force_inline friend int operator> (vec const &lhs, vec const &rhs) noexcept
 Greater than.
 
tt_force_inline friend int operator>= (vec const &lhs, vec const &rhs) noexcept
 Greater than or equal.
 
tt_force_inline friend __m128 _length_squared (vec const &rhs) noexcept
 
tt_force_inline friend float length_squared (vec const &rhs) noexcept
 
tt_force_inline friend float length (vec const &rhs) noexcept
 
tt_force_inline friend vec normalize (vec const &rhs) noexcept
 
tt_force_inline friend vec homogeneous_divide (vec const &rhs) noexcept
 
tt_force_inline friend float dot (vec const &lhs, vec const &rhs) noexcept
 
tt_force_inline friend vec reciprocal (vec const &rhs) noexcept
 
template<bool nx, bool ny, bool nz, bool nw>
vec neg (vec const &rhs) noexcept
 
tt_force_inline friend vec hadd (vec const &lhs, vec const &rhs) noexcept
 
tt_force_inline friend vec hsub (vec const &lhs, vec const &rhs) noexcept
 
tt_force_inline friend float viktor_cross (vec const &lhs, vec const &rhs) noexcept
 
vec cross (vec const &lhs, vec const &rhs) noexcept
 
tt_force_inline friend vec normal (vec const &rhs) noexcept
 Calculate the 2D normal on a 2D vector.
 
vec ceil (vec const &rhs) noexcept
 
vec floor (vec const &rhs) noexcept
 
vec round (vec const &rhs) noexcept
 
std::array< vec, 4 > transpose (vec col0, vec col1, vec col2, vec col3) noexcept
 
vec midpoint (vec const &p1, vec const &p2) noexcept
 Find a point at the midpoint between two points.
 
vec desaturate (vec const &color, float brightness) noexcept
 
vec composit (vec const &under, vec const &over) noexcept
 
vec reflect_point (vec const &p, vec const anchor) noexcept
 Find the point on the other side and at the same distance of an anchor-point.
 
std::string to_string (vec const &rhs) noexcept
 
std::ostream friend & operator<< (std::ostream &lhs, vec const &rhs) noexcept
 
template<std::size_t I>
tt_force_inline friend float get (vec const &rhs) noexcept
 

Detailed Description

A 4D vector.

If you need a 2D or 3D vector, point or color, you can use this vector class as a homogenious coordinate.

This class supports swizzeling. Swizzeling is done using member functions which will return a vec. The name of the member function consists of 2 to 4 of the following characters: 'x', 'y', 'z', 'w', 'r', 'g', 'b', 'a', '0' & '1'. If the swizzle member function name would start with a '0' or '1' character it will be prefixed with an underscore '_'.

Since swizzle member functions always return a 4D vec, the third and forth element will default to '0' and 'w'. This allows a 2D vector to maintain its homogeniousness, or a color to maintain its alpha value.

Constructor & Destructor Documentation

◆ vec() [1/2]

template<typename T , std::enable_if_t< std::is_arithmetic_v< T >, int > = 0>
tt_force_inline tt::vec::vec ( T rhs)
inlineexplicitnoexcept

Initialize a vec with all elements set to a value.

Useful as a scalar converter, when combined with an arithmatic operator.

◆ vec() [2/2]

tt_force_inline tt::vec::vec ( float x,
float y,
float z = 0.0f,
float w = 0.0f )
inlinenoexcept

Create a vec out of 2 to 4 values.

This vector is used as a homogenious coordinate, meaning:

  • vectors have w=0.0 (A direction and distance)
  • points have w=1.0 (A position in space)

When this vector is used for color then:

  • x=Red, y=Green, z=Blue, w=Alpha

Member Function Documentation

◆ color()

static tt_force_inline vec tt::vec::color ( float r,
float g,
float b,
float a = 1.0f )
inlinestaticnoexcept

Create a color out of 3 to 4 values.

If you use this vector as a color:

  • Red = x, Green = y, Blue = z, Alpha = w.
  • Alpha is linear: 0.0 is transparent, 1.0 is opaque. The Red/Green/Blue are not pre-multiplied with the alpha.
  • Red/Green/Blue are based on the linear-extended-sRGB floating point format: values between 0.0 and 1.0 is equal to linear-sRGB (no gamma curve). 1.0,1.0,1.0 equals 80 cd/m2 and should be the maximum value for user interfaces. Values above 1.0 would cause brighter colors on HDR (high dynamic range) displays. Values below 0.0 will cause colours outside the sRGB color gamut for use with high-gamut displays

◆ operator=()

tt_force_inline vec & tt::vec::operator= ( float rhs)
inlinenoexcept

Initialize a vec with all elements set to a value.

Useful as a scalar converter, when combined with an arithmatic operator.

◆ origin()

static tt_force_inline vec tt::vec::origin ( )
inlinestaticnoexcept

Get a origin vector(0.0, 0.0, 0.0, 1.0).

The origin of a window or image are in the left-bottom corner. The center of the first pixel in the left-bottom corner is at coordinate (0.5, 0.5). The origin of a glyph lies on the crossing of the baseline and left-side-bearing. Paths have a specific location of the origin.

◆ point() [1/2]

static tt_force_inline vec tt::vec::point ( float x = 0.0f,
float y = 0.0f,
float z = 0.0f )
inlinestaticnoexcept

Create a point out of 2 to 4 values.

This vector is used as a homogeneous coordinate, meaning:

  • vectors have w=0.0 (A direction and distance)
  • points have w=1.0 (A position in space)

When this vector is used for color then:

  • x=Red, y=Green, z=Blue, w=Alpha

◆ point() [2/2]

static tt_force_inline vec tt::vec::point ( vec rhs)
inlinestaticnoexcept

Create a point out of 2 to 4 values.

This vector is used as a homogeneous coordinate, meaning:

  • vectors have w=0.0 (A direction and distance)
  • points have w=1.0 (A position in space)

When this vector is used for color then:

  • x=Red, y=Green, z=Blue, w=Alpha

◆ resize2DRetainingAspectRatio()

vec tt::vec::resize2DRetainingAspectRatio ( vec const & rhs)
inlinenoexcept

Resize an extent while retaining aspect ratio.

Parameters
rhsThe extent to match.
Returns
The extent resized to match rhs, while retaining aspect ratio.

Friends And Related Symbol Documentation

◆ eq

tt_force_inline friend int eq ( vec const & lhs,
vec const & rhs )
friend

Equal to.

Returns
boolean bit field, bit 0=x, 1=y, 2=z, 3=w.

◆ midpoint

vec midpoint ( vec const & p1,
vec const & p2 )
friend

Find a point at the midpoint between two points.

◆ ne

tt_force_inline friend int ne ( vec const & lhs,
vec const & rhs )
friend

Not equal to.

Returns
boolean bit field, bit 0=x, 1=y, 2=z, 3=w.

◆ normal

tt_force_inline friend vec normal ( vec const & rhs)
friend

Calculate the 2D normal on a 2D vector.

◆ operator<

tt_force_inline friend int operator< ( vec const & lhs,
vec const & rhs )
friend

Less than.

Returns
boolean bit field, bit 0=x, 1=y, 2=z, 3=w.

◆ operator<=

tt_force_inline friend int operator<= ( vec const & lhs,
vec const & rhs )
friend

Less than or equal.

Returns
boolean bit field, bit 0=x, 1=y, 2=z, 3=w.

◆ operator>

tt_force_inline friend int operator> ( vec const & lhs,
vec const & rhs )
friend

Greater than.

Returns
boolean bit field, bit 0=x, 1=y, 2=z, 3=w.

◆ operator>=

tt_force_inline friend int operator>= ( vec const & lhs,
vec const & rhs )
friend

Greater than or equal.

Returns
boolean bit field, bit 0=x, 1=y, 2=z, 3=w.

◆ reflect_point

vec reflect_point ( vec const & p,
vec const anchor )
friend

Find the point on the other side and at the same distance of an anchor-point.


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