Mat

Generic struct that represents a matrix with rowCount rows and colCount columns, holding elements of type T. A matrix must be at least 1x1.

struct Mat (
T
size_t rowCount
size_t colCount
) if (
isNumeric!T &&
rowCount > 0
&&
colCount > 0
) {}

Constructors

this
this(T[rowCount * colCount] elements)

Constructs a matrix from the given elements.

this
this(T[] elements)

Constructs a matrix from the given elements.

this
this(T[colCount][rowCount] elements)

Constructs a matrix from the given 2-dimensional array.

this
this(Mat!(T, rowCount, colCount) other)

Constructs a matrix as a copy of another.

this
this(T value)

Constructs a matrix with all elements initialized to the given value.

Members

Aliases

N
alias N = rowCount
Undocumented in source.

Functions

add
Mat!(T, rowCount, colCount) add(Mat!(T, rowCount, colCount) other)

Adds a given matrix to this one.

adjugate
Mat!(T, N, N) adjugate()

Gets an adjugate matrix.

cofactor
Mat!(T, N, N) cofactor()

Gets a cofactor matrix.

copy
Mat!(T, rowCount, colCount) copy()

Gets a copy of this matrix.

det
T det()

Gets the determinant of this matrix.

div
Mat!(T, rowCount, colCount) div(T factor)

Divides this matrix by a factor.

getCol
Vec!(T, rowCount) getCol(size_t col)

Gets a specified column as a vector.

getRow
Vec!(T, colCount) getRow(size_t row)

Gets a specified row as a vector.

inv
Mat!(T, N, N) inv()

Gets the inverse of this matrix.

invertible
bool invertible()

Determines if this matrix is invertible, which simply means a non-zero determinant.

map
Vec!(T, 2) map(Vec!(T, 2) v)

Maps the given 2D vector using this matrix.

mul
Mat!(T, rowCount, colCount) mul(T factor)

Multiplies this matrix by a factor.

mul
Mat!(T, rowCount, otherColCount) mul(Mat!(T, otherRowCount, otherColCount) other)

Computes the matrix multiplication of this * other.

mul
Vec!(T, rowCount) mul(Vec!(T, colCount) vector)

Multiplies a vector against this matrix.

opIndex
T opIndex(size_t i, size_t j)

Gets the value at a specified location in the matrix. For example, with a Mat!(float, 2, 2) m, we can say float v = m[0, 1];

opIndexAssign
void opIndexAssign(T value, size_t i, size_t j)

Sets the value at a specified location in the matrix.

rotate
Mat!(T, N, N) rotate(T theta)

Applies a 2D rotation to this matrix.

rotate
Mat!(T, N, N) rotate(T x, T y, T z)

Applies a 3D rotation to this matrix about the x, y, and then z axes.

rotateX
Mat!(T, N, N) rotateX(T theta)

Applies a rotation to this matrix about the x-axis.

rotateY
Mat!(T, N, N) rotateY(T theta)

Applies a rotation to this matrix about the y-axis.

rotateZ
Mat!(T, N, N) rotateZ(T theta)

Applies a rotation to this matrix about the z-axis.

rowAdd
Mat!(T, rowCount, colCount) rowAdd(size_t rowI, T factor, size_t rowJ)

Adds a row, multiplied by a factor, to another row.

rowMultiply
Mat!(T, rowCount, colCount) rowMultiply(size_t row, T factor)

Multiplies a row by a factor.

rowSwitch
Mat!(T, rowCount, colCount) rowSwitch(size_t rowI, size_t rowJ)

Switches two rows in this matrix.

scale
Mat!(T, N, N) scale(T sx, T sy)

Applies a 2D scaling to this matrix.

scale
Mat!(T, N, N) scale(T s)

Applies a uniform 2D scaling to this matrix on all axes.

scale
Mat!(T, N, N) scale(T sx, T sy, T sz)

Applies a 3D scaling to this matrix.

scale
Mat!(T, N, N) scale(T s)

Applies a uniform 3D scaling to this matrix on all axes.

setCol
Mat!(T, rowCount, colCount) setCol(size_t col, Vec!(T, rowCount) vector)

Sets a specified column to the given vector of elements.

setData
Mat!(T, rowCount, colCount) setData(T[rowCount * colCount] elements)

Sets all elements of this matrix using the given elements.

setRow
Mat!(T, rowCount, colCount) setRow(size_t row, Vec!(T, colCount) vector)

Sets a specified row to the given vector of elements.

shear
Mat!(T, N, N) shear(T sx, T sy)

Applies a 2D shear to this matrix.

sub
Mat!(T, rowCount, colCount) sub(Mat!(T, rowCount, colCount) other)

Subtracts a given matrix from this one.

subMatrix
Mat!(T, rowCount - n, colCount - m) subMatrix(size_t[n] rows, size_t[m] cols)

Gets a submatrix of this matrix, with the given rows and columns removed.

toString
string toString()

Converts this matrix to a string.

translate
Mat!(T, N, N) translate(T dx, T dy)

Applies a 2D translation to this matrix.

translate
Mat!(T, N, N) translate(T dx, T dy, T dz)

Applies a 3D translation to this matrix.

transpose
Mat!(T, rowCount, colCount) transpose()

Gets the transpose of this matrix, and stores it in this matrix.

Static functions

identity
Mat!(T, N, N) identity()

Gets an identity matrix.

Static variables

HEIGHT
size_t HEIGHT;
Undocumented in source.
WIDTH
size_t WIDTH;
Undocumented in source.

Variables

data
T[rowCount * colCount] data;

The internal static array storing the elements in row-major form.

Meta