Manifold 3.0
Robust geometry
Loading...
Searching...
No Matches
Mat

linalg::mat<T,M,N> defines a fixed-size matrix containing exactly M rows and N columns of type T, in column-major order. More...

Classes

struct  mat< T, M, 1 >
struct  mat< T, M, 2 >
struct  mat< T, M, 3 >
struct  mat< T, M, 4 >

Detailed Description

linalg::mat<T,M,N> defines a fixed-size matrix containing exactly M rows and N columns of type T, in column-major order.

This data structure is supported by a set of algebraic and component-wise functions, as well as a set of standard reductions.

mat<T,M,N>:

  • is DefaultConstructible:
    float2x2 m; // m contains columns 0,0; 0,0
  • is constructible from N columns of type vec<T,M>:
    float2x2 m {{1,2},{3,4}}; // m contains columns 1,2; 3,4
  • is constructible from linalg::identity:
    float3x3 m = linalg::identity; // m contains columns 1,0,0; 0,1,0; 0,0,1
  • is CopyConstructible and CopyAssignable:
    float2x2 m {{1,2},{3,4}}; // m contains columns 1,2; 3,4
    float2x2 n {m}; // n contains columns 1,2; 3,4
    float2x2 p; // p contains columns 0,0; 0,0
    p = n; // p contains columns 1,2; 3,4
  • is EqualityComparable and LessThanComparable:
    if(m == n) cout << "m and n contain equal elements in the same positions" <<
    endl; if(m < n) cout << "m precedes n lexicographically when compared in
    column-major order" << endl;
  • is explicitly constructible from a single element of type T:
    float2x2 m {5}; // m contains columns 5,5; 5,5
  • is explicitly constructible from a mat<U,M,N> of some other type U:
    float2x2 m {int2x2{{5,6},{7,8}}}; // m contains columns 5,6; 7,8
  • supports indexing into columns:
    float2x3 m {{1,2},{3,4},{5,6}}; // m contains columns 1,2; 3,4; 5,6
    float2 c = m[0]; // c contains 1,2
    m[1] = {7,8}; // m contains columns 1,2; 7,8; 5,6
  • supports retrieval (but not assignment) of rows:
    float2x3 m {{1,2},{3,4},{5,6}}; // m contains columns 1,2; 3,4; 5,6
    float3 r = m.row(1); // r contains 2,4,6
  • supports unary operators +, -, ! and ~ in component-wise fashion:
    float2x2 m {{1,2},{3,4}}; // m contains columns 1,2; 3,4
    float2x2 n = -m; // n contains columns -1,-2; -3,-4
  • supports binary operators +, -, *, /, %, |, &, ^, << and >> in component-wise fashion:
    float2x2 a {{0,0},{2,2}}; // a contains columns 0,0; 2,2
    float2x2 b {{1,2},{1,2}}; // b contains columns 1,2; 1,2
    float2x2 c = a + b; // c contains columns 1,2; 3,4
  • supports binary operators with a scalar on the left or the right:
    auto m = 2 * float2x2{{1,2},{3,4}}; // m is float2x2{{2,4},{6,8}}
  • supports operators +=, -=, *=, /=, %=, |=, &=, ^=, <<= and >>= with matrices or scalars on the right:
    float2x2 v {{5,4},{3,2}};
    v *= 3; // v is float2x2{{15,12},{9,6}}
  • supports operations on mixed element types:
  • supports range-based for over columns
  • has a flat memory layout