HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Friends
hi::v1::vector2 Class Reference

#include <hikogui/geometry/vector2.hpp>

Public Types

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

Public Member Functions

constexpr vector2 (vector2 const &) noexcept=default
 
constexpr vector2 (vector2 &&) noexcept=default
 
constexpr vector2operator= (vector2 const &) noexcept=default
 
constexpr vector2operator= (vector2 &&) noexcept=default
 
constexpr operator array_type () const noexcept
 Convert a vector to its array_type-nummeric_array.
 
constexpr vector2 (array_type const &other) noexcept
 Construct a vector from a array_type-simd.
 
constexpr vector2 () noexcept
 Construct a empty vector / zero length.
 
constexpr vector2 (float x, float y) 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 x () const noexcept
 Access the x element from the vector.
 
constexpr float y () const noexcept
 Access the y element from the vector.
 
constexpr vector2 operator- () const noexcept
 Mirror this vector.
 
constexpr vector2operator+= (vector2 const &rhs) noexcept
 
constexpr vector2operator-= (vector2 const &rhs) noexcept
 
constexpr vector2operator*= (float const &rhs) noexcept
 
constexpr bool holds_invariant () const noexcept
 Check if the vector is valid.
 

Friends

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

◆ vector2() [1/3]

constexpr hi::v1::vector2::vector2 ( array_type const & other)
inlineexplicitconstexprnoexcept

Construct a vector from a array_type-simd.

◆ vector2() [2/3]

constexpr hi::v1::vector2::vector2 ( )
inlineconstexprnoexcept

Construct a empty vector / zero length.

◆ vector2() [3/3]

constexpr hi::v1::vector2::vector2 ( float x,
float y )
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()

constexpr bool hi::v1::vector2::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()

constexpr hi::v1::vector2::operator array_type ( ) const
inlineexplicitconstexprnoexcept

Convert a vector to its array_type-nummeric_array.

◆ operator-()

constexpr vector2 hi::v1::vector2::operator- ( ) const
inlineconstexprnoexcept

Mirror this vector.

Returns
The mirrored vector.

◆ x() [1/2]

constexpr float hi::v1::vector2::x ( ) const
inlineconstexprnoexcept

Access the x element from the vector.

Returns
a reference to the x element.

◆ x() [2/2]

constexpr float & hi::v1::vector2::x ( )
inlineconstexprnoexcept

Access the x element from the vector.

Returns
a reference to the x element.

◆ y() [1/2]

constexpr float hi::v1::vector2::y ( ) const
inlineconstexprnoexcept

Access the y element from the vector.

Returns
a reference to the y element.

◆ y() [2/2]

constexpr float & hi::v1::vector2::y ( )
inlineconstexprnoexcept

Access the y element from the vector.

Returns
a reference to the y element.

Friends And Related Symbol Documentation

◆ ceil

constexpr vector2 ceil ( vector2 const & rhs)
friend

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

◆ cross [1/2]

constexpr friend float cross ( vector2 const & lhs,
vector2 const & rhs )
friend

Get the cross product between two 2D vectors.

This function is useful for finding the winding direction of the vectors, when doing ray casting.

Parameters
lhsThe first vector.
rhsThe second vector.
Returns
A scaler representing the sharpness of the corner between the two vectors.

◆ cross [2/2]

constexpr friend vector2 cross ( vector2 const & rhs)
friend

Get the cross product of one 2D vectors.

Parameters
rhsThe vector.
Returns
A vector perpendicular to the given vector.

◆ det

constexpr friend float det ( vector2 const & lhs,
vector2 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

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

constexpr vector2 floor ( vector2 const & rhs)
friend

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

◆ hypot

float hypot ( vector2 const & rhs)
friend

Get the length of the vector.

Parameters
rhsThe vector.
Returns
The length of the vector.

◆ max

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

constexpr vector2 min ( vector2 const & lhs,
vector2 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

constexpr friend vector2 normal ( vector2 const & rhs)
friend

Get the normal on a 2D vector.

Parameters
rhsThe vector.
Returns
A normal on the vector.

◆ normalize

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

constexpr friend vector2 operator* ( float const & lhs,
vector2 const & rhs )
friend

Scale the vector by a scaler.

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

◆ operator* [2/2]

constexpr friend vector2 operator* ( vector2 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+

constexpr friend vector2 operator+ ( vector2 const & lhs,
vector2 const & rhs )
friend

Add two vectors from each other.

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

◆ operator-

constexpr friend vector2 operator- ( vector2 const & lhs,
vector2 const & rhs )
friend

Subtract two vectors from each other.

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

◆ operator==

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

constexpr friend float rcp_hypot ( vector2 const & rhs)
friend

Get the length of the vector.

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

◆ round

constexpr vector2 round ( vector2 const & rhs)
friend

Round the elements of the vector toward nearest integer.

◆ squared_hypot

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