HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
hi::v1::vector3 Class Reference

#include <hikogui/geometry/vector3.hpp>

Public Types

using array_type = simd<float, 4>
using value_type = array_type::value_type

Public Member Functions

constexpr vector3 (vector3 const &) noexcept=default
constexpr vector3 (vector3 &&) noexcept=default
constexpr vector3 & operator= (vector3 const &) noexcept=default
constexpr vector3 & operator= (vector3 &&) noexcept=default
constexpr vector3 (vector2 const &other) noexcept
 Construct a vector from a lower dimension vector.
constexpr operator vector2 () 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 vector3 (array_type const &other) noexcept
 Construct a vector from a array_type-simd.
constexpr vector3 () noexcept
 Construct a empty vector / zero length.
constexpr vector3 (float x, float y, float z=0.0f) noexcept
 Construct a 3D vector from x, y and z elements.
constexpr float & x () noexcept
 Access the x element from the vector.
constexpr float & y () noexcept
 Access the y element from the vector.
constexpr float & z () noexcept
 Access the z element from the vector.
constexpr float x () const noexcept
 Access the x element from the vector.
constexpr float y () const noexcept
 Access the y element from the vector.
constexpr float z () const noexcept
 Access the z element from the vector.
constexpr vector3 operator- () const noexcept
 Mirror this vector.
constexpr vector3 & operator+= (vector3 const &rhs) noexcept
constexpr vector3 & operator-= (vector3 const &rhs) noexcept
constexpr vector3 & operator*= (float const &rhs) noexcept
constexpr bool holds_invariant () const noexcept
 Check if the vector is valid.

Friends

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

Detailed Description

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

◆ vector3() [1/4]

hi::v1::vector3::vector3 ( vector2 const & other)
inlinenodiscardconstexprnoexcept

Construct a vector from a lower dimension vector.

◆ vector3() [2/4]

hi::v1::vector3::vector3 ( array_type const & other)
inlineexplicitnodiscardconstexprnoexcept

Construct a vector from a array_type-simd.

◆ vector3() [3/4]

hi::v1::vector3::vector3 ( )
inlinenodiscardconstexprnoexcept

Construct a empty vector / zero length.

◆ vector3() [4/4]

hi::v1::vector3::vector3 ( float x,
float y,
float z = 0.0f )
inlinenodiscardconstexprnoexcept

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()

bool hi::v1::vector3::holds_invariant ( ) const
inlinenodiscardconstexprnoexcept

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()

hi::v1::vector3::operator array_type ( ) const
inlineexplicitnodiscardconstexprnoexcept

Convert a vector to its array_type-nummeric_array.

◆ operator vector2()

hi::v1::vector3::operator vector2 ( )
inlineexplicitnodiscardconstexprnoexcept

Construct a vector from a higher dimension vector.

This will clear the values in the higher dimensions.

◆ operator-()

vector3 hi::v1::vector3::operator- ( ) const
inlinenodiscardconstexprnoexcept

Mirror this vector.

Returns
The mirrored vector.

◆ x() [1/2]

float hi::v1::vector3::x ( ) const
inlinenodiscardconstexprnoexcept

Access the x element from the vector.

Returns
a reference to the x element.

◆ x() [2/2]

float & hi::v1::vector3::x ( )
inlinenodiscardconstexprnoexcept

Access the x element from the vector.

Returns
a reference to the x element.

◆ y() [1/2]

float hi::v1::vector3::y ( ) const
inlinenodiscardconstexprnoexcept

Access the y element from the vector.

Returns
a reference to the y element.

◆ y() [2/2]

float & hi::v1::vector3::y ( )
inlinenodiscardconstexprnoexcept

Access the y element from the vector.

Returns
a reference to the y element.

◆ z() [1/2]

float hi::v1::vector3::z ( ) const
inlinenodiscardconstexprnoexcept

Access the z element from the vector.

Returns
a reference to the z element.

◆ z() [2/2]

float & hi::v1::vector3::z ( )
inlinenodiscardconstexprnoexcept

Access the z element from the vector.

Returns
a reference to the z element.

◆ ceil

vector3 ceil ( vector3 const & rhs)
friend

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

◆ cross

friend vector3 cross ( vector3 const & lhs,
vector3 const & rhs )
friend

Get the cross product between two 3D vectors.

Parameters
lhsThe first vector.
rhsThe second vector.
Returns
A vector that is perpendicular to the given vectors.

◆ dot

friend float dot ( vector3 const & lhs,
vector3 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

vector3 floor ( vector3 const & rhs)
friend

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

◆ hypot

float hypot ( vector3 const & rhs)
friend

Get the length of the vector.

Parameters
rhsThe vector.
Returns
The length of the vector.

◆ max

vector3 max ( vector3 const & lhs,
vector3 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

vector3 min ( vector3 const & lhs,
vector3 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.

◆ normal

friend vector3 normal ( vector3 const & rhs,
float angle )
friend

Get the normal on a 3D vector.

Parameters
rhsThe vector.
angleThe angle around the vector, only value_type{0} is implemented (xy-plane)
Returns
A normal on the vector.

◆ normalize

friend vector3 normalize ( vector3 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]

friend vector3 operator* ( float const & lhs,
vector3 const & rhs )
friend

Scale the vector by a scaler.

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

◆ operator* [2/2]

friend vector3 operator* ( vector3 const & lhs,
float const & rhs )
friend

Scale the vector by a scaler.

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

◆ operator+

friend vector3 operator+ ( vector3 const & lhs,
vector3 const & rhs )
friend

Add two vectors from each other.

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

◆ operator-

friend vector3 operator- ( vector3 const & lhs,
vector3 const & rhs )
friend

Subtract two vectors from each other.

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

◆ operator==

friend bool operator== ( vector3 const & lhs,
vector3 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

friend float rcp_hypot ( vector3 const & rhs)
friend

Get the length of the vector.

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

◆ round

vector3 round ( vector3 const & rhs)
friend

Round the elements of the vector toward nearest integer.

◆ squared_hypot

friend float squared_hypot ( vector3 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: