Kale
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
Kale::Matrix< w, h, T > Class Template Reference

#include <Matrix.hpp>

+ Inheritance diagram for Kale::Matrix< w, h, T >:

Public Member Functions

 Matrix ()
 
 Matrix (const std::array< T, w *h > &arr)
 
 Matrix (std::array< T, w *h > &&arr)
 
size_t width () const
 
size_t height () const
 
Toperator[] (size_t i)
 
const Toperator[] (size_t i) const
 
Toperator() (size_t col, size_t row)
 
const Toperator() (size_t col, size_t row) const
 
Tget (size_t i)
 
const Tget (size_t i) const
 
Tget (size_t col, size_t row)
 
const Tget (size_t col, size_t row) const
 
Matrix< w, h, Toperator+ (const Matrix< w, h, T > &other) const
 
Matrix< w, h, Toperator+ (Matrix< w, h, T > &&other) const
 
void operator+= (const Matrix< w, h, T > &other)
 
Matrix< w, h, Toperator- (const Matrix< w, h, T > &other) const
 
Matrix< w, h, Toperator- (Matrix< w, h, T > &&other) const
 
void operator-= (const Matrix< w, h, T > &other)
 
Matrix< w, h, Toperator* (T scalar) const
 
void operator*= (T scalar)
 
template<size_t w2>
Matrix< w2, h, Toperator* (const Matrix< w2, w, T > &other) const
 
Matrix< h, w, Ttranspose () const
 
void swapRows (size_t row1, size_t row2)
 
void scaleRow (size_t row, T scalar)
 
void addScaledRow (size_t row1, size_t row2, T scalar)
 
template<size_t W = w, size_t H = h>
std::enable_if< W==2 &&H==2, Vector2< T > >::type operator* (const Vector2< T > &vec) const
 
template<size_t W = w, size_t H = h>
std::enable_if< W==2 &&H==2, Vector2< T > >::type operator* (Vector2< T > &&vec) const
 
template<size_t W = w, size_t H = h>
std::enable_if< W==3 &&H==3, Vector3< T > >::type operator* (const Vector3< T > &vec) const
 
template<size_t W = w, size_t H = h>
std::enable_if< W==3 &&H==3, Vector3< T > >::type operator* (Vector3< T > &&vec) const
 
template<size_t W = w, size_t H = h>
std::enable_if< W==4 &&H==4, Vector4< T > >::type operator* (const Vector4< T > &vec) const
 
template<size_t W = w, size_t H = h>
std::enable_if< W==4 &&H==4, Vector4< T > >::type operator* (Vector4< T > &&vec) const
 
template<typename R , size_t W = w, size_t H = h>
std::enable_if< W==2 &&H==2, R >::type det () const
 
template<typename R , size_t W = w, size_t H = h>
std::enable_if< W==3 &&H==3, R >::type det () const
 
template<typename R , size_t W = w, size_t H = h>
std::enable_if< W==H &&(W >3)&&std::is_signed< R >::value, R >::type det () const
 
template<size_t W = w, size_t H = h>
std::enable_if< W==2 &&H==2, Matrix< W, H, T > >::type inverse ()
 
template<size_t W = w, size_t H = h>
std::enable_if< W==3 &&H==3, Matrix< W, H, T > >::type inverse ()
 

Public Attributes

std::array< T, w *h > data
 

Detailed Description

template<size_t w, size_t h, typename T>
class Kale::Matrix< w, h, T >

Represents a single matrix

Template Parameters
cThe width/columns of the matrix
rThe height/rows of the matrix
TThe number type stored within the matrix

Definition at line 49 of file Matrix.hpp.

Constructor & Destructor Documentation

◆ Matrix() [1/3]

template<size_t w, size_t h, typename T >
Kale::Matrix< w, h, T >::Matrix ( )
inline

Creates a 0 initialized matrix

Definition at line 60 of file Matrix.hpp.

◆ Matrix() [2/3]

template<size_t w, size_t h, typename T >
Kale::Matrix< w, h, T >::Matrix ( const std::array< T, w *h > & arr)
inline

Creates a matrix from an array, the array must have a length of w*h and follow rows -> columns ie { 1, 2, 3, 4, 5, 6, 7, 8, 9 }

Parameters
arrThe array

Definition at line 74 of file Matrix.hpp.

◆ Matrix() [3/3]

template<size_t w, size_t h, typename T >
Kale::Matrix< w, h, T >::Matrix ( std::array< T, w *h > && arr)
inline

Creates a matrix from an array, the array must have a length of w*h and follow rows -> columns ie { 1, 2, 3, 4, 5, 6, 7, 8, 9 }

Parameters
arrThe array

Definition at line 88 of file Matrix.hpp.

Member Function Documentation

◆ addScaledRow()

template<size_t w, size_t h, typename T >
void Kale::Matrix< w, h, T >::addScaledRow ( size_t row1,
size_t row2,
T scalar )
inline

Adds a row scaled to another row and saves it

Parameters
row1The row to add to (this row is modified)
row2The row to scale by and add from
scalarThe scalar to scale row2 by
Exceptions
Indebug mode only if the row is invalid, no release checks/throws are made. It will crash.

Definition at line 344 of file Matrix.hpp.

◆ det() [1/3]

template<size_t w, size_t h, typename T >
template<typename R , size_t W = w, size_t H = h>
std::enable_if< W==2 &&H==2, R >::type Kale::Matrix< w, h, T >::det ( ) const
inline

Retrieves the determinant for any square matrix

Template Parameters
Rthe return type to use (larger matrices may require a large type for determinants)
Returns
The determinant of the matrix

Definition at line 439 of file Matrix.hpp.

◆ det() [2/3]

template<size_t w, size_t h, typename T >
template<typename R , size_t W = w, size_t H = h>
std::enable_if< W==3 &&H==3, R >::type Kale::Matrix< w, h, T >::det ( ) const
inline

Retrieves the determinant for any square matrix

Template Parameters
Rthe return type to use (larger matrices may require a large type for determinants)
Returns
The determinant of the matrix

Definition at line 450 of file Matrix.hpp.

◆ det() [3/3]

template<size_t w, size_t h, typename T >
template<typename R , size_t W = w, size_t H = h>
std::enable_if< W==H &&(W >3)&&std::is_signed< R >::value, R >::type Kale::Matrix< w, h, T >::det ( ) const
inline

Retrieves the determinant for any square matrix

Template Parameters
Rthe return type to use (larger matrices may require a large type for determinants)
Returns
The determinant of the matrix

Definition at line 467 of file Matrix.hpp.

◆ get() [1/4]

template<size_t w, size_t h, typename T >
T & Kale::Matrix< w, h, T >::get ( size_t col,
size_t row )
inline

Returns an element given the column and row

Parameters
colThe column
rowThe row
Returns
The element

Definition at line 190 of file Matrix.hpp.

◆ get() [2/4]

template<size_t w, size_t h, typename T >
const T & Kale::Matrix< w, h, T >::get ( size_t col,
size_t row ) const
inline

Returns an element given the column and row

Parameters
colThe column
rowThe row
Returns
The element

Definition at line 200 of file Matrix.hpp.

◆ get() [3/4]

template<size_t w, size_t h, typename T >
T & Kale::Matrix< w, h, T >::get ( size_t i)
inline

Returns an element directly from the data array of the matrix. Elements are stored by (col, row) => row * width + col

Parameters
iThe element index
Returns
The element

Definition at line 170 of file Matrix.hpp.

◆ get() [4/4]

template<size_t w, size_t h, typename T >
const T & Kale::Matrix< w, h, T >::get ( size_t i) const
inline

Returns an element directly from the data array of the matrix. Elements are stored by (col, row) => row * width + col

Parameters
iThe element index
Returns
The element

Definition at line 180 of file Matrix.hpp.

◆ height()

template<size_t w, size_t h, typename T >
size_t Kale::Matrix< w, h, T >::height ( ) const
inline

Returns the height of the matrix

Returns
the height of the matrix

Definition at line 104 of file Matrix.hpp.

◆ inverse() [1/2]

template<size_t w, size_t h, typename T >
template<size_t W = w, size_t H = h>
std::enable_if< W==2 &&H==2, Matrix< W, H, T > >::type Kale::Matrix< w, h, T >::inverse ( )
inline

Calculates the inverse of the matrix for a square matrix

Returns
The inverted matrix

Definition at line 476 of file Matrix.hpp.

◆ inverse() [2/2]

template<size_t w, size_t h, typename T >
template<size_t W = w, size_t H = h>
std::enable_if< W==3 &&H==3, Matrix< W, H, T > >::type Kale::Matrix< w, h, T >::inverse ( )
inline

Calculates the inverse of the matrix for a square matrix

Returns
The inverted matrix

Definition at line 488 of file Matrix.hpp.

◆ operator()() [1/2]

template<size_t w, size_t h, typename T >
T & Kale::Matrix< w, h, T >::operator() ( size_t col,
size_t row )
inline

Returns an element given the column and row

Parameters
colThe column
rowThe row
Returns
The element
Exceptions
Indebug mode only if the col/row is invalid, no release checks/throws are made. It will crash.

Definition at line 143 of file Matrix.hpp.

◆ operator()() [2/2]

template<size_t w, size_t h, typename T >
const T & Kale::Matrix< w, h, T >::operator() ( size_t col,
size_t row ) const
inline

Returns an element given the column and row

Parameters
colThe column
rowThe row
Returns
The element
Exceptions
Indebug mode only if the col/row is invalid, no release checks/throws are made. It will crash.

Definition at line 157 of file Matrix.hpp.

◆ operator*() [1/8]

template<size_t w, size_t h, typename T >
template<size_t w2>
Matrix< w2, h, T > Kale::Matrix< w, h, T >::operator* ( const Matrix< w2, w, T > & other) const
inline

Performs Matrix Multiplication (this * other).

Parameters
otherThe matrix to multiply with
Returns
The resulting matrix from the multiplication

Definition at line 286 of file Matrix.hpp.

◆ operator*() [2/8]

template<size_t w, size_t h, typename T >
template<size_t W = w, size_t H = h>
std::enable_if< W==2 &&H==2, Vector2< T > >::type Kale::Matrix< w, h, T >::operator* ( const Vector2< T > & vec) const
inline

Transforms the vector by this matrix

Parameters
vecThe vector to transform
Returns
The transformed vector

Definition at line 361 of file Matrix.hpp.

◆ operator*() [3/8]

template<size_t w, size_t h, typename T >
template<size_t W = w, size_t H = h>
std::enable_if< W==3 &&H==3, Vector3< T > >::type Kale::Matrix< w, h, T >::operator* ( const Vector3< T > & vec) const
inline

Transforms the vector by this matrix

Parameters
vecThe vector to transform
Returns
The transformed vector

Definition at line 383 of file Matrix.hpp.

◆ operator*() [4/8]

template<size_t w, size_t h, typename T >
template<size_t W = w, size_t H = h>
std::enable_if< W==4 &&H==4, Vector4< T > >::type Kale::Matrix< w, h, T >::operator* ( const Vector4< T > & vec) const
inline

Transforms the vector by this matrix

Parameters
vecThe vector to transform
Returns
The transformed vector

Definition at line 410 of file Matrix.hpp.

◆ operator*() [5/8]

template<size_t w, size_t h, typename T >
Matrix< w, h, T > Kale::Matrix< w, h, T >::operator* ( T scalar) const
inline

Scales the matrix by a scalar and returns the result

Parameters
scalarThe scalar to scale by
Returns
The result of the scaling operation

Definition at line 267 of file Matrix.hpp.

◆ operator*() [6/8]

template<size_t w, size_t h, typename T >
template<size_t W = w, size_t H = h>
std::enable_if< W==2 &&H==2, Vector2< T > >::type Kale::Matrix< w, h, T >::operator* ( Vector2< T > && vec) const
inline

Transforms the vector by this matrix

Parameters
vecThe vector to transform
Returns
The transformed vector

Definition at line 371 of file Matrix.hpp.

◆ operator*() [7/8]

template<size_t w, size_t h, typename T >
template<size_t W = w, size_t H = h>
std::enable_if< W==3 &&H==3, Vector3< T > >::type Kale::Matrix< w, h, T >::operator* ( Vector3< T > && vec) const
inline

Transforms the vector by this matrix

Parameters
vecThe vector to transform
Returns
The transformed vector

Definition at line 397 of file Matrix.hpp.

◆ operator*() [8/8]

template<size_t w, size_t h, typename T >
template<size_t W = w, size_t H = h>
std::enable_if< W==4 &&H==4, Vector4< T > >::type Kale::Matrix< w, h, T >::operator* ( Vector4< T > && vec) const
inline

Transforms the vector by this matrix

Parameters
vecThe vector to transform
Returns
The transformed vector

Definition at line 425 of file Matrix.hpp.

◆ operator*=()

template<size_t w, size_t h, typename T >
void Kale::Matrix< w, h, T >::operator*= ( T scalar)
inline

Scales the matrix by a scalar and stores the result in this matrix

Parameters
scalarThe scalar to scale by

Definition at line 277 of file Matrix.hpp.

◆ operator+() [1/2]

template<size_t w, size_t h, typename T >
Matrix< w, h, T > Kale::Matrix< w, h, T >::operator+ ( const Matrix< w, h, T > & other) const
inline

Adds this matrix to another and returns the result

Parameters
otherThe matrix to add to
Returns
The result of the addition operation

Definition at line 209 of file Matrix.hpp.

◆ operator+() [2/2]

template<size_t w, size_t h, typename T >
Matrix< w, h, T > Kale::Matrix< w, h, T >::operator+ ( Matrix< w, h, T > && other) const
inline

Adds this matrix to another and returns the result

Parameters
otherThe matrix to add to
Returns
The result of the addition operation

Definition at line 220 of file Matrix.hpp.

◆ operator+=()

template<size_t w, size_t h, typename T >
void Kale::Matrix< w, h, T >::operator+= ( const Matrix< w, h, T > & other)
inline

Adds this matrix to another and saves the result in this matrix

Parameters
otherThe matrix to add to

Definition at line 229 of file Matrix.hpp.

◆ operator-() [1/2]

template<size_t w, size_t h, typename T >
Matrix< w, h, T > Kale::Matrix< w, h, T >::operator- ( const Matrix< w, h, T > & other) const
inline

Subtracts another matrix from this matrix (this - other)

Parameters
otherThe matrix to subtract
Returns
The result of the subtraction operation

Definition at line 238 of file Matrix.hpp.

◆ operator-() [2/2]

template<size_t w, size_t h, typename T >
Matrix< w, h, T > Kale::Matrix< w, h, T >::operator- ( Matrix< w, h, T > && other) const
inline

Subtracts another matrix from this matrix (this - other)

Parameters
otherThe matrix to subtract
Returns
The result of the subtraction operation

Definition at line 249 of file Matrix.hpp.

◆ operator-=()

template<size_t w, size_t h, typename T >
void Kale::Matrix< w, h, T >::operator-= ( const Matrix< w, h, T > & other)
inline

Subtracts another matrix from this matrix (this - other) and saves the result in this matrix

Parameters
otherThe matrix to subtract

Definition at line 258 of file Matrix.hpp.

◆ operator[]() [1/2]

template<size_t w, size_t h, typename T >
T & Kale::Matrix< w, h, T >::operator[] ( size_t i)
inline

Returns an element directly from the data array of the matrix. Elements are stored by (col, row) => row * width + col

Parameters
iThe element index
Returns
The element
Exceptions
Indebug mode only if the index is invalid, no release checks/throws are made. It will crash.

Definition at line 115 of file Matrix.hpp.

◆ operator[]() [2/2]

template<size_t w, size_t h, typename T >
const T & Kale::Matrix< w, h, T >::operator[] ( size_t i) const
inline

Returns an element directly from the data array of the matrix. Elements are stored by (col, row) => row * width + col

Parameters
iThe element index
Returns
The element
Exceptions
Indebug mode only if the index is invalid, no release checks/throws are made. It will crash.

Definition at line 129 of file Matrix.hpp.

◆ scaleRow()

template<size_t w, size_t h, typename T >
void Kale::Matrix< w, h, T >::scaleRow ( size_t row,
T scalar )
inline

Scales a row within the matrix

Parameters
rowThe row to scale
scalarThe scalar to scale by
Exceptions
Indebug mode only if the row is invalid, no release checks/throws are made. It will crash.

Definition at line 328 of file Matrix.hpp.

◆ swapRows()

template<size_t w, size_t h, typename T >
void Kale::Matrix< w, h, T >::swapRows ( size_t row1,
size_t row2 )
inline

Swaps 2 rows within the matrix

Parameters
row1The first row
row2The second row
Exceptions
Indebug mode only if the row is invalid, no release checks/throws are made. It will crash.

Definition at line 315 of file Matrix.hpp.

◆ transpose()

template<size_t w, size_t h, typename T >
Matrix< h, w, T > Kale::Matrix< w, h, T >::transpose ( ) const
inline

Transposes the matrix and returns the result of the operation

Returns
The transposed matrix

Definition at line 299 of file Matrix.hpp.

◆ width()

template<size_t w, size_t h, typename T >
size_t Kale::Matrix< w, h, T >::width ( ) const
inline

Returns the width of the matrix

Returns
the width of the matrix

Definition at line 96 of file Matrix.hpp.

Member Data Documentation

◆ data

template<size_t w, size_t h, typename T >
std::array<T, w*h> Kale::Matrix< w, h, T >::data

The matrix internal data

Definition at line 55 of file Matrix.hpp.


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