rvecD

alias rvecD = Vector!(0, real)

Examples

static assert( Vector!(3,float).isStatic == true );
static assert( Vector!(3,float).isDynamic == false );

static assert( Vector!(0,float).isStatic == false );
static assert( Vector!(0,float).isDynamic == true );

static assert( isVector!(Vector!(3,float)) );
static assert( isVector!(Vector!(0,float)) );

static assert( !__traits(compiles,Vector!(3,float,"x y")) );
static assert( !__traits(compiles,Vector!(3,float,"x y")) );
static assert(  __traits(compiles,Vector!(3,float,"x y z")) );

static assert( Vector!(3,float,"x y z").sizeof == float.sizeof * 3 );
static assert( Vector!(0,float).sizeof == (float[]).sizeof );

static assert( Vector!(3,float,"x y z").length == 3 );
assert( eq( Vector!(3,float)(1,2,3), [1,2,3] ) );

auto a = Vector!(3,float)(1,2,3);
assert( eq( Vector!(5,int)(0,a,4), [0,1,2,3,4] ) );

static assert( !__traits(compiles, { auto v = Vector!(2,int)(1,2,3); } ) );
assert( !mustExcept( { auto v = Vector!(0,int)(1,2,3); } ) );
assert( !mustExcept( { auto v = Vector!(3,int)(1); } ) );
auto b = Vector!(0,float)(1,2,3);
assert( b.length == 3 );

auto c = Vector!(3,float)(1);
assert( eq( c, [1,1,1] ) );
auto d = c;
assert( eq( c, d ) );
static struct Test1 { float x,y,z; }
static assert( !__traits(compiles,Vector!(3,float)(Test1.init)) );

static struct Test2 { float[3] data; }
static assert( __traits(compiles,Vector!(3,float)(Test2.init)) );

convert vectors

auto a = ivec2(1,2);
auto b = vec2(a);
assert( eq( a, b ) );
auto c = ivec2(b);
assert( eq( a, c ) );
auto a = Vector!(3,int,"x y z|u v t|r g b")(1,2,3);
assert( a.x == a.r );
assert( a.y == a.g );
assert( a.z == a.b );
assert( a.x == a.u );
assert( a.y == a.v );
assert( a.z == a.t );

auto b = Vector!(2,int,"near far|n f")(1,100);
assert( b.near == b.n );
assert( b.far  == b.f );

b.nf = ivec2( 10,20 );
assert( b.near == 10 );
assert( b.far == 20 );
auto a = vec3(1,2,3);
auto b = vecD(1,2,3);
auto c = a + b;
assert( is( typeof(c) == vec3 ) );
auto d = b + a;
assert( is( typeof(d) == vecD ) );
assert( eq(c,d) );
auto f = ivec3(1,2,3);
auto c1 = a + f;
assert( is( typeof(c1) == vec3 ) );
auto d1 = ivec3(f) + ivec3(a);
assert( is( typeof(d1) == ivec3 ) );
assert( eq(c1,d) );
assert( eq(c,d1) );

a *= 2;
b *= 2;
auto e = b *= 2;
assert( eq(a,[2,4,6]) );
assert( eq(b,a*2) );

auto x = 2 * a;
assert( eq(x,[4,8,12]) );

assert( !!x );
x[0] = float.nan;
assert( !x );
auto a = vecD(1,2,3);

auto b = vec3(a);
auto c = vecD(b);

assert( eq( a, b ) );
assert( eq( a, c ) );
auto a = vec3(2,2,1);
assert( eq(a.rebase(vec3(2,0,0),vec3(0,2,0),vec3(0,0,2)), [1,1,.5] ) );
auto a = vec3(1,2,3);

assert( a.opDispatch!"x" == 1 );
assert( a.y == 2 );
assert( a.z == 3 );

a.x = 2;
assert( a.x == 2 );
alias Vector!(4,float,"x y dx dy") vec2p;

auto a = vec2p(1,2,0,0);

assert( a.opDispatch!"x" == 1 );
assert( a.dx == 0 );
auto a = vec3(1,2,3);

auto b = a.opDispatch!"xy";
auto c = a.xx;
auto d = a.xxxyyzyx;

static assert( is(typeof(b) == Vector!(2,float,"x y") ) );
static assert( is(typeof(c) == Vector!(2,float) ) );
static assert( is(typeof(d) == Vector!(8,float) ) );

assert( eq( b, [1,2] ) );
assert( eq( c, [1,1] ) );
assert( eq( d, [1,1,1,2,2,3,2,1] ) );
auto a = vec3(1,2,3);
auto b = dvec4(4,5,6,7);
auto c = vecD( 9, 10 );
a.xz = b.yw;
assert( eq( a, [5,2,7] ) );
a.zy = c;
assert( eq( a, [5,10,9] ) );
static assert( !__traits(compiles, a.xy=vec3(1,2,3)) );
static assert( !__traits(compiles, a.xx=vec2(1,2)) );
auto d = a.zxy = b.wyx;
static assert( d.access_string == "z x y" );
static assert( is( d.datatype == float ) );
assert( eq( d, [ 7,5,4 ] ) );
assert( eq( a, [ 5,4,7 ] ) );
a.yzx = a.zxz;
assert( eq( a, [ 7,7,5 ] ) );
auto a = vec3(1,2,3);
auto b = ivec3(1,2,3);
auto k = a.len2;
assert( is( typeof(k) == float ) );

auto l = b.len2;
assert( is( typeof(l) == int ) );

auto m = b.len;
assert( is( typeof(m) == float ) );

auto n = b.len!real;
assert( is( typeof(n) == real ) );

assert( is( typeof( vec3( 1, 2, 3 ).e ) == vec3 ) );
assert( abs( a.e.len - 1 ) < float.epsilon );
alias Vector!(3,cfloat) cvec3;

auto a = cvec3( 1-1i, 2, 3i );
static assert( __traits(compiles, a.e) );
assert( !mustExcept({ auto k = a.e; }) );
alias Vector!(3,Vector!(3,float)) mat3;
auto a = mat3( vec3(1,0,0), vec3(0,1,0), vec3(0,0,1) );

a *= 2;
a += a;

assert( a[0][0] == 4 );
assert( a[1][1] == 4 );
assert( a[2][2] == 4 );

assert( a[0][1] == 0 );
assert( a[1][2] == 0 );
assert( a[2][1] == 0 );

a ^^= 2;

assert( a[0][0] == 16 );
assert( a[1][1] == 16 );
assert( a[2][2] == 16 );

auto b = -a;

assert( b[0][0] == -16 );
assert( b[1][1] == -16 );
assert( b[2][2] == -16 );

Meta