rmatD

Undocumented in source.
alias rmatD = Matrix!(0, 0, real)

Examples

static struct Test
{
    union
    {
        mat3 um;
        float[9] uf;
    }
}

Test tt;

foreach( i, ref v; tt.uf ) v = i+1;
assert( eq( tt.um, [[1,2,3],[4,5,6],[7,8,9]] ) );
auto a = matDx3( 1,2,3,4,5,6,7,8,9 );
assert( mustExcept( {matDx3(1,2,3,4);} ) );
assert( a.height == 3 );
assert( a.width == 3 );
assert( eq( a, [[1,2,3],[4,5,6],[7,8,9]] ) );
assert( mustExcept({ a.resize(2,2); }) );
a.resize(2,3);
assert( eq( a, [[1,2,3],[4,5,6]] ) );
assert( a.height == 2 );
a.fill(1);
assert( eq( a, [[1,1,1],[1,1,1]] ) );
a.resize(0,3);
assert( a.width == 3 );
a.resize(2,3);
a.fill(1);

auto b = a;
assert( eq( b, [[1,1,1],[1,1,1]] ) );
auto a = mat3( 1,2,3,4,5,6,7,8,9 );
auto b = matD( 3,3, 1,2,3,4,5,6,7,8,9 );
auto c = mat3xD( 1,2,3,4,5,6,7,8,9 );
auto d = matDx3( 1,2,3,4,5,6,7,8,9 );

auto eha = a.expandHeight( 8,8,8 );
auto ehb = b.expandHeight( 8,8,8 );
auto ehc = c.expandHeight( 8,8,8 );
auto ehd = d.expandHeight( 8,8,8 );

assert( eq( eha, [[1,2,3],[4,5,6],[7,8,9],[8,8,8]] ));
assert( eha.height == 4 );
assert( ehb.height == 4 );
assert( ehc.height == 4 );
assert( ehd.height == 4 );
assert( eq( eha, ehb ) );
assert( eq( eha, ehc ) );
assert( eq( eha, ehd ) );

static assert( is(typeof(eha) == Matrix!(0,3,float)) );
static assert( is(typeof(ehd) == Matrix!(0,3,float)) );

static assert( is(typeof(ehb) == Matrix!(0,0,float)) );
static assert( is(typeof(ehc) == Matrix!(0,0,float)) );

auto ewa = a.expandWidth( 8,8,8 );
auto ewb = b.expandWidth( 8,8,8 );
auto ewc = c.expandWidth( 8,8,8 );
auto ewd = d.expandWidth( 8,8,8 );

assert( eq( ewa, [[1,2,3,8],[4,5,6,8],[7,8,9,8]] ));
assert( ewa.width == 4 );
assert( ewb.width == 4 );
assert( ewc.width == 4 );
assert( ewd.width == 4 );
assert( eq( ewa, ewb ) );
assert( eq( ewa, ewc ) );
assert( eq( ewa, ewd ) );

static assert( is(typeof(ewa) == Matrix!(3,0,float)) );
static assert( is(typeof(ewc) == Matrix!(3,0,float)) );

static assert( is(typeof(ewb) == Matrix!(0,0,float)) );
static assert( is(typeof(ewd) == Matrix!(0,0,float)) );

auto aa = a.expandHeight(a);
assert( eq( aa, [[1,2,3],[4,5,6],[7,8,9],[1,2,3],[4,5,6],[7,8,9]] ));
assert( aa.height == 6 );
static assert( is(typeof(aa) == Matrix!(0,3,float)) );
auto a = matD(4,4,0).fillDiag(1);
assert( eq( a, mat4() ) );
assert( eq( a.inv, a ) );
auto a = mat4x2( 1,2,3,4,5,6,7,8 );
auto b = mat4( 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16 );
auto c = a.T * b * a;
static assert( c.height == 2 && c.width == 2 );
auto a = mat3.diag(1);
assert( eq(a,[[1,0,0],[0,1,0],[0,0,1]]) );
auto b = mat3xD.diag(1,2);
assert( eq(b,[[1,0,0],[0,2,0],[0,0,1]]) );
auto c = mat3xD.diag(1,2,3);
assert( eq(c,[[1,0,0],[0,2,0],[0,0,3]]) );
static assert( !__traits(compiles,matD.diag(1)) );
auto d = matD(3,3).fill(0).fillDiag(1);
assert( eq(d,[[1,0,0],[0,1,0],[0,0,1]]) );
auto a = mat3( 1,2,3,4,5,6,7,8,9 );
auto sha = a.sliceHeight(1);
assert( eq(sha,[[4,5,6],[7,8,9]]) );
auto swsha = sha.sliceWidth(0,1);
assert( eq(swsha,[[4],[7]]) );
auto a = mat3.diag(1);
assert( eq( -a,[[-1,0,0],[0,-1,0],[0,0,-1]]) );
auto a = rmat3( 3,2,2, 1,3,1, 5,3,4 );
auto ainv = rmat3xD( 9,-2,-4,  1,2,-1, -12,1,7 ) / 5;

auto b = a * ainv;
static assert( is( typeof(b) == Matrix!(3,0,real) ) );
assert( eq( b, mat3.diag(1) ) );

static assert( !__traits(compiles,a *= ainv ) );
a *= rmat3(ainv);
assert( eq( a, mat3.diag(1) ) );
alias Matrix!(4,5,float) mat4x5;

auto a = mat2x4.init * mat4xD.init;
assert( mustExcept({ mat4xD.init * mat2x4.init; }) );
auto b = mat2x4.init * mat4x5.init;

static assert( is( typeof(a) == Matrix!(2,0,float) ) );
static assert( is( typeof(b) == Matrix!(2,5,float) ) );
static assert( is( typeof(mat4xD.init * mat2x4.init) == Matrix!(4,4,float) ) );
auto b = mat3.diag(2) * vec3(2,3,4);
assert( is( typeof(b) == vec3 ) );
assert( eq( b, [4,6,8] ) );

auto c = vec3(1,1,1) * mat3.diag(1,2,3);
assert( is( typeof(c) == vec3 ) );
assert( eq( c, [1,2,3] ) );
auto mtr = matD(2,3).fill( 1,2,3, 
                           3,4,7 );

auto a = mtr * vec3(1,1,1);

assert( is( typeof(a) == Vector!(0,float) ) );
assert( a.length == 2 );
assert( eq( a, [ 6, 14 ] ) );

auto b = vec3(1,1,1) * mtr.T;
assert( eq( a, b ) );
void check(E)( E mtr ) if( isMatrix!E )
{
    mtr.fill( 1,2,3,4,
              5,6,7,8,
              9,10,11,12,
              13,14,15,16 );
    auto sm = mtr.subWithout( [0,3,3,3], [1,2] );
    assert( is( typeof(sm) == matD ) );
    assert( sm.width == 2 );
    assert( sm.height == 2 );
    assert( eq( sm, [ [5,8], [9,12] ] ) );
    assert( mustExcept({ mtr.sub( [0,4], [1,2] ); }) );
    auto sm2 = mtr.subWithout( [], [1,2] );
    assert( sm2.width == 2 );
    assert( sm2.height == 4 );
    assert( eq( sm2, [ [1,4],[5,8],[9,12],[13,16] ] ) );
}

check( matD(4,4) );
check( mat4() );
auto mtr = mat4().setRect(0,0,mat3.diag(1)).setCol(3,1,2,3,4);
assert( eq( mtr, [[1,0,0,1],
                  [0,1,0,2],
                  [0,0,1,3],
                  [0,0,0,4]] ) );

Meta