mat2

Header file: include/mat2.h

mat2 is a column-major matrix with 2 columns and 2 rows.

\(mat2 = \begin{bmatrix} x.x & y.x \\ x.y & y.y \end{bmatrix}\)

Class variables

Type

Name

Description

nml::vec2

x

The first column of the mat2.

nml::vec2

y

The second column of the mat2.

Class functions

Constructors

Name

Description

mat2()

Construct a ([0.0, 0.0], [0.0, 0.0]) matrix.

mat2(float _value)

Construct a ([_value, _value], [_value, _value]) matrix.

mat2(float _xx, float _xy, float _yx, float _yy)

Construct a ([_xx, _xy], [_yx, _yy]) matrix.

mat2(float _xx, float _xy, const nml::vec2& _y)

Construct a ([_xx, _xy], [_y.x, _y.y]) matrix.

mat2(const nml::vec2& _x, float _yx, float _yy)

Construct a ([_x.x, _x.y], [_yx, _yy]) matrix.

mat2(const nml::vec2& _x, const nml::vec2& _y)

Construct a ([_x.x, _x.y], [_y.x, _y.y]) matrix.

mat2(const float* _ptr)

Construct a matrix from a pointer.

mat2(const nml::mat3& _mat)

Construct a ([_mat.x.x, _mat.x.y], [_mat.y.x, _mat.y.y]) matrix.

mat2(const nml::mat4& _mat)

Construct a ([_mat.x.x, _mat.x.y], [_mat.y.x, _mat.y.y]) matrix.

Operators

Name

Description

nml::mat2& operator+=(const nml::mat2& other)

Add a mat2 to the current mat2.

nml::mat2& operator-=(const nml::mat2& other)

Substract a mat2 from the current mat2.

nml::mat2& operator*=(const nml::mat2& other)

Multiply the current mat2 by a mat2.

nml::mat2& operator*=(const float other)

Multiply the current mat2 by a scalar.

nml::mat2& operator/=(const float other)

Divide the current mat2 by a scalar.

nml::vec2& operator[](size_t index)

Return a reference to x if index is 0 or a reference to y if index is 1, else, throw an exception.

const nml::vec2& operator[](size_t index) const

Return a const reference to x if index is 0 or a const reference to y if index is 1, else, throw an exception.

Functions

Name

Description

float det() const

Return the determinant of the matrix.

float* data()

Return a pointer to the matrix’s elements.

Static Functions

Name

Description

nml::mat2 nml::mat2::identity()

Return a ([1.0, 0.0], [0.0, 1.0]) identity matrix.

Namespace functions

Operators

Name

Description

nml::mat2 operator+(nml::mat2 lhs, const nml::mat2& rhs)

Return a mat2 that is the sum between two mat2.

nml::mat2 operator-(nml::mat2 lhs, const nml::mat2& rhs)

Return a mat2 that is the difference between two mat2.

nml::mat2 operator*(nml::mat2 lhs, const nml::mat2& rhs)

Return a mat2 that is the product between two mat2.

nml::vec2 operator*(nml::mat2 lhs, const nml::vec2& rhs)

Return a vec2 that is the product between a mat2 and a vec2.

nml::mat2 operator*(nml::mat2 lhs, const float rhs)

Return a mat2 that is the product between a mat2 and a scalar.

nml::mat2 operator*(float lhs, const nml::mat2& rhs)

Return a mat2 that is the product between a scalar and a mat2.

nml::mat2 operator/(nml::mat2 lhs, const float rhs)

Return a mat2 that is the quotient between a mat2 and a scalar.

bool operator==(const nml::mat2& lhs, const nml::mat2& rhs)

Return true if the two mat2 are identical, else, return false.

bool operator!=(const nml::mat2& lhs, const nml::mat2& rhs)

Return true if the two mat2 are different, else, return false.

Functions

Name

Description

nml::mat2 transpose(const nml::mat2& mat)

Return a mat2 where the columns of mat are the rows and the rows of mat are the columns.

nml::mat2 inverse(const nml::mat2& mat)

Return the inverse of a mat2.

std::string nml::to_string(const nml::mat2& mat)

Return a mat2 as a string under the format “[[x.x, x.y], [y.x, y.y]]”.