HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Friends
hi::v1::geo::matrix< D > Class Template Reference

#include <hikogui/geometry/matrix.hpp>

Public Member Functions

constexpr matrix (matrix const &) noexcept=default
 
constexpr matrix (matrix &&) noexcept=default
 
constexpr matrixoperator= (matrix const &) noexcept=default
 
constexpr matrixoperator= (matrix &&) noexcept=default
 
constexpr matrix () noexcept
 Constructs an identity matrix.
 
constexpr matrix (f32x4 col0, f32x4 col1, f32x4 col2, f32x4 col3=f32x4{0.0f, 0.0f, 0.0f, 1.0f}) noexcept
 Construct a matrix from four columns.
 
constexpr matrix (vector3 col0, vector3 col1, vector3 col2, vector3 col3=vector3{}) noexcept
 Construct a matrix from four vectors.
 
constexpr matrix (float c0r0, float c1r0, float c2r0, float c0r1, float c1r1, float c2r1, float c0r2, float c1r2, float c2r2) noexcept
 Construct a 3x3 matrix from scalar values.
 
constexpr matrix (float c0r0, float c1r0, float c2r0, float c3r0, float c0r1, float c1r1, float c2r1, float c3r1, float c0r2, float c1r2, float c2r2, float c3r2, float c0r3, float c1r3, float c2r3, float c3r3) noexcept
 Construct a 4x4 matrix from scalar values.
 
template<int E>
requires (E < D)
constexpr matrix (matrix< E > const &other) noexcept
 Copy-construct a matrix from a smaller matrix.
 
template<int E>
requires (E < D)
constexpr matrixoperator= (matrix< E > const &rhs) noexcept
 Copy-assign a matrix from a smaller matrix.
 
constexpr operator std::array< f32x4, 4 > () const noexcept
 Convert a point to its f32x4-nummeric_array.
 
constexpr bool holds_invariant () const noexcept
 
constexpr f32x4 operator* (f32x4 const &rhs) const noexcept
 Transform a f32x4 numeric array by the matrix.
 
constexpr float operator* (float const &rhs) const noexcept
 Transform a float by the scaling factor of the matrix.
 
constexpr corner_radii operator* (corner_radii const &rhs) const noexcept
 Transform a float by the scaling factor of the matrix.
 
template<int E>
constexpr auto operator* (vector< float, E > const &rhs) const noexcept
 Transform a vector by the matrix.
 
template<int E>
constexpr auto operator* (extent< float, E > const &rhs) const noexcept
 Transform a extent by the matrix.
 
template<int E>
constexpr auto operator* (point< float, E > const &rhs) const noexcept
 Transform a point by the matrix.
 
constexpr rectangle operator* (aarectangle const &rhs) const noexcept
 Transform an axis-aligned rectangle by the matrix.
 
constexpr rectangle operator* (rectangle const &rhs) const noexcept
 Transform a rectangle by the matrix.
 
constexpr quad operator* (quad const &rhs) const noexcept
 Transform a quad by the matrix.
 
constexpr circle operator* (circle const &rhs) const noexcept
 Transform a circle by the matrix.
 
constexpr line_segment operator* (line_segment const &rhs) const noexcept
 Transform a line-segment by the matrix.
 
constexpr auto operator* (matrix const &rhs) const noexcept
 Matrix/Matrix multiplication.
 
template<int E>
constexpr bool operator== (matrix< E > const &rhs) const noexcept
 Compare two matrices potentially of different dimensions.
 
constexpr matrix operator~ () const
 Invert matrix.
 

Static Public Member Functions

static constexpr matrix uniform (aarectangle src_rectangle, aarectangle dst_rectangle, alignment alignment) noexcept
 Create a transformation matrix to translate and uniformly-scale a src_rectangle to a dst_rectangle.
 

Friends

template<int I>
constexpr f32x4 const & get (matrix const &rhs) noexcept
 Get a column.
 
template<int I>
constexpr f32x4 & get (matrix &rhs) noexcept
 Get a column.
 
constexpr matrix transpose (matrix const &rhs) noexcept
 Matrix transpose.
 
template<char DstX, char DstY, char DstZ, char DstW = 'w'>
requires (D == 3)
constexpr matrix reflect (matrix const &rhs) noexcept
 Reflect axis of a matrix.
 

Detailed Description

template<int D>
class hi::v1::geo::matrix< D >

A 2D or 3D homogenius matrix for transforming homogenious vectors and points.

This matrix is in column major order. It is implemented as 4 columns made from a f32x4 numeric-array.

Constructor & Destructor Documentation

◆ matrix() [1/6]

template<int D>
constexpr hi::v1::geo::matrix< D >::matrix ( )
inlineconstexprnoexcept

Constructs an identity matrix.

◆ matrix() [2/6]

template<int D>
constexpr hi::v1::geo::matrix< D >::matrix ( f32x4 col0,
f32x4 col1,
f32x4 col2,
f32x4 col3 = f32x4{0.0f, 0.0f, 0.0f, 1.0f} )
inlineconstexprnoexcept

Construct a matrix from four columns.

Parameters
col0The 1st f32x4 column.
col1The 2nd f32x4 column.
col2The 3rd f32x4 column.
col3The 4th f32x4 column.

◆ matrix() [3/6]

template<int D>
constexpr hi::v1::geo::matrix< D >::matrix ( vector3 col0,
vector3 col1,
vector3 col2,
vector3 col3 = vector3{} )
inlineconstexprnoexcept

Construct a matrix from four vectors.

Parameters
col0The 1st vector3 column.
col1The 2nd vector3 column.
col2The 3rd vector3 column.
col3The 4th vector3 column.

◆ matrix() [4/6]

template<int D>
constexpr hi::v1::geo::matrix< D >::matrix ( float c0r0,
float c1r0,
float c2r0,
float c0r1,
float c1r1,
float c2r1,
float c0r2,
float c1r2,
float c2r2 )
inlineconstexprnoexcept

Construct a 3x3 matrix from scalar values.

The function parameters are in row-major order for pretty formatting in source code. The matrix itself remains in column-major order.

Parameters
c0r0Value for column 0, row 0
c1r0Value for column 1, row 0
c2r0Value for column 2, row 0
c0r1Value for column 0, row 1
c1r1Value for column 1, row 1
c2r1Value for column 2, row 1
c0r2Value for column 0, row 2
c1r2Value for column 1, row 2
c2r2Value for column 2, row 2

◆ matrix() [5/6]

template<int D>
constexpr hi::v1::geo::matrix< D >::matrix ( float c0r0,
float c1r0,
float c2r0,
float c3r0,
float c0r1,
float c1r1,
float c2r1,
float c3r1,
float c0r2,
float c1r2,
float c2r2,
float c3r2,
float c0r3,
float c1r3,
float c2r3,
float c3r3 )
inlineconstexprnoexcept

Construct a 4x4 matrix from scalar values.

The function parameters are in row-major order for pretty formatting in source code. The matrix itself remains in column-major order.

Parameters
c0r0Value for column 0, row 0
c1r0Value for column 1, row 0
c2r0Value for column 2, row 0
c3r0Value for column 3, row 0
c0r1Value for column 0, row 1
c1r1Value for column 1, row 1
c2r1Value for column 2, row 1
c3r1Value for column 3, row 1
c0r2Value for column 0, row 2
c1r2Value for column 1, row 2
c2r2Value for column 2, row 2
c3r2Value for column 3, row 2
c0r3Value for column 0, row 3
c1r3Value for column 1, row 3
c2r3Value for column 2, row 3
c3r3Value for column 3, row 3

◆ matrix() [6/6]

template<int D>
template<int E>
requires (E < D)
constexpr hi::v1::geo::matrix< D >::matrix ( matrix< E > const & other)
inlineconstexprnoexcept

Copy-construct a matrix from a smaller matrix.

Member Function Documentation

◆ operator std::array< f32x4, 4 >()

template<int D>
constexpr hi::v1::geo::matrix< D >::operator std::array< f32x4, 4 > ( ) const
inlineexplicitconstexprnoexcept

Convert a point to its f32x4-nummeric_array.

◆ operator*() [1/12]

template<int D>
constexpr rectangle hi::v1::geo::matrix< D >::operator* ( aarectangle const & rhs) const
inlineconstexprnoexcept

Transform an axis-aligned rectangle by the matrix.

After transformation it can not be guaranteed that an axis-aligned rectangle remained aligned to axis, therefor a normal rectangle is returned

Note
It is undefined behavior to perspective transform a rectangle
Parameters
rhsThe axis-aligned rectangle to be transformed.
Returns
The transformed rectangle

◆ operator*() [2/12]

template<int D>
constexpr circle hi::v1::geo::matrix< D >::operator* ( circle const & rhs) const
inlineconstexprnoexcept

Transform a circle by the matrix.

Parameters
rhsThe circle to be transformed.
Returns
The transformed circle

◆ operator*() [3/12]

template<int D>
constexpr corner_radii hi::v1::geo::matrix< D >::operator* ( corner_radii const & rhs) const
inlineconstexprnoexcept

Transform a float by the scaling factor of the matrix.

The floating point number is transformed into a vector laying on the x-axis, then transformed, then extracting the hypot from it.

◆ operator*() [4/12]

template<int D>
template<int E>
constexpr auto hi::v1::geo::matrix< D >::operator* ( extent< float, E > const & rhs) const
inlineconstexprnoexcept

Transform a extent by the matrix.

Extents will not be translated.

Parameters
rhsThe extent to be transformed.
Returns
The transformed extent.

◆ operator*() [5/12]

template<int D>
constexpr f32x4 hi::v1::geo::matrix< D >::operator* ( f32x4 const & rhs) const
inlineconstexprnoexcept

Transform a f32x4 numeric array by the matrix.

Parameters
rhsThe f32x4 numeric array to transform.
Returns
The transformed numeric array.

◆ operator*() [6/12]

template<int D>
constexpr float hi::v1::geo::matrix< D >::operator* ( float const & rhs) const
inlineconstexprnoexcept

Transform a float by the scaling factor of the matrix.

The floating point number is transformed into a vector laying on the x-axis, then transformed, then extracting the hypot from it.

◆ operator*() [7/12]

template<int D>
constexpr line_segment hi::v1::geo::matrix< D >::operator* ( line_segment const & rhs) const
inlineconstexprnoexcept

Transform a line-segment by the matrix.

Parameters
rhsThe line-segment to be transformed.
Returns
The transformed line-segment

◆ operator*() [8/12]

template<int D>
constexpr auto hi::v1::geo::matrix< D >::operator* ( matrix< D > const & rhs) const
inlineconstexprnoexcept

Matrix/Matrix multiplication.

◆ operator*() [9/12]

template<int D>
template<int E>
constexpr auto hi::v1::geo::matrix< D >::operator* ( point< float, E > const & rhs) const
inlineconstexprnoexcept

Transform a point by the matrix.

Parameters
rhsThe point to be transformed.
Returns
The transformed point.

◆ operator*() [10/12]

template<int D>
constexpr quad hi::v1::geo::matrix< D >::operator* ( quad const & rhs) const
inlineconstexprnoexcept

Transform a quad by the matrix.

Parameters
rhsThe quad to be transformed.
Returns
The transformed quad

◆ operator*() [11/12]

template<int D>
constexpr rectangle hi::v1::geo::matrix< D >::operator* ( rectangle const & rhs) const
inlineconstexprnoexcept

Transform a rectangle by the matrix.

Note
It is undefined behavior to perspective transform a rectangle
Parameters
rhsThe rectangle to be transformed.
Returns
The transformed rectangle

◆ operator*() [12/12]

template<int D>
template<int E>
constexpr auto hi::v1::geo::matrix< D >::operator* ( vector< float, E > const & rhs) const
inlineconstexprnoexcept

Transform a vector by the matrix.

Vectors will not be translated.

Parameters
rhsThe vector to be transformed.
Returns
The transformed vector.

◆ operator=()

template<int D>
template<int E>
requires (E < D)
constexpr matrix & hi::v1::geo::matrix< D >::operator= ( matrix< E > const & rhs)
inlineconstexprnoexcept

Copy-assign a matrix from a smaller matrix.

◆ operator==()

template<int D>
template<int E>
constexpr bool hi::v1::geo::matrix< D >::operator== ( matrix< E > const & rhs) const
inlineconstexprnoexcept

Compare two matrices potentially of different dimensions.

Parameters
rhsThe right-hand-side matrix.
Return values
trueWhen the two matrices compare equal.

◆ operator~()

template<int D>
constexpr matrix hi::v1::geo::matrix< D >::operator~ ( ) const
inlineconstexpr

Invert matrix.

◆ uniform()

template<int D>
constexpr matrix< D > v1::geo::matrix::uniform ( aarectangle src_rectangle,
aarectangle dst_rectangle,
alignment alignment )
staticconstexprnoexcept

Create a transformation matrix to translate and uniformly-scale a src_rectangle to a dst_rectangle.

The implementation is located in scale.hpp since the definition requires both scale and translate.

Parameters
src_rectangleThe rectangle to be transformed.
dst_rectangleThe rectangle after transformation.
alignmentHow the src_rectangle should be aligned inside the dst_rectangle after scaling and moving.
Returns
A transformation matrix to move and scale the src_rectangle to the dst_rectangle.

Friends And Related Symbol Documentation

◆ get [1/2]

template<int D>
template<int I>
constexpr f32x4 & get ( matrix< D > & rhs)
friend

Get a column.

Template Parameters
IThe index of the column.
Returns
A reference to the selected column as a f32x4.

◆ get [2/2]

template<int D>
template<int I>
constexpr f32x4 const & get ( matrix< D > const & rhs)
friend

Get a column.

Template Parameters
IThe index of the column.
Returns
A const reference to the selected column as a f32x4.

◆ reflect

template<int D>
template<char DstX, char DstY, char DstZ, char DstW = 'w'>
requires (D == 3)
constexpr matrix reflect ( matrix< D > const & rhs)
friend

Reflect axis of a matrix.

The default axis of HikoGUI's geometry system are:

+y
| -z (away from camera)
| /
| /
|/
-x ----+---- +x
/|
/ |
/ |
+z |
-y

In Vulkan the Y axis is downward; so to translate a matrix from HikoGUI to Vulkan you can use:

auto vulkan_M = reflect<'x', 'Y', 'z'>(hikogui_M);

The original axis are defined as the lower-case characters 'x', 'y', 'z' and 'w'; or for the negated axis as the upper-case characters 'X', 'Y', 'Z' and 'W'.

Template Parameters
DstXWhich of the original axis to use for the new matrix's x-axis.
DstYWhich of the original axis to use for the new matrix's y-axis.
DstZWhich of the original axis to use for the new matrix's z-axis.
DstWWhich of the original axis to use for the new matrix's w-axis.
Parameters
rhsThe matrix to reflect
Returns
The reflected matrix.

◆ transpose

template<int D>
constexpr matrix transpose ( matrix< D > const & rhs)
friend

Matrix transpose.


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