Vector.clear

Sets all values of the vector to value

struct Vector(type, int dim)
@safe pure nothrow
void
clear
(
valueType value
)
if (
(dim >= 2) &&
(dim <= 4)
)

Examples

Unittest Construction TODO: Split up these Unittests

1 vec3 vecClear;
2 assert( !vecClear.ok );
3 vecClear.clear( 1.0f );
4 assert( vecClear.ok );
5 assert( vecClear.data == [ 1.0f, 1.0f, 1.0f ] );
6 assert( vecClear.data == vec3( 1.0f ).data );
7 vecClear.clear( float.infinity );
8 assert( !vecClear.ok );
9 vecClear.clear( float.nan );
10 assert( !vecClear.ok );
11 vecClear.clear( 1.0f );
12 assert( vecClear.ok );
13 
14 vec4 b = vec4( 1.0f, vecClear );
15 assert( b.ok );
16 assert( b.data == [ 1.0f, 1.0f, 1.0f, 1.0f ] );
17 assert( b.data == vec4( 1.0f ).data );
18 
19 vec2 v2_1 = vec2( vec2( 0.0f, 1.0f ));
20 assert( v2_1.data == [ 0.0f, 1.0f ] );
21 
22 vec2 v2_2 = vec2( 1.0f, 1.0f );
23 assert( v2_2.data == [ 1.0f, 1.0f ] );
24 
25 vec3 v3 = vec3( v2_1, 2.0f );
26 assert( v3.data == [ 0.0f, 1.0f, 2.0f ] );
27 
28 vec4 v4_1 = vec4( 1.0f, vec2( 2.0f, 3.0f ), 4.0f );
29 assert( v4_1.data == [  1.0f, 2.0f, 3.0f, 4.0f ] );
30 assert( vec3( v4_1 ).data == [ 1.0f, 2.0f, 3.0f ] );
31 assert( vec2( vec3( v4_1 )).data == [ 1.0f, 2.0f ] );
32 assert( vec2( vec3( v4_1 )).data == vec2( v4_1 ).data );
33 assert( v4_1.data == vec4( [ 1.0f, 2.0f, 3.0f, 4.0f ] ).data );
34 
35 vec4 v4_2 = vec4( vec2( 1.0f, 2.0f ), vec2( 3.0f, 4.0f ));
36 assert( v4_2.data == [  1.0f, 2.0f, 3.0f, 4.0f ] );
37 assert( vec3( v4_2 ).data == [ 1.0f, 2.0f, 3.0f ] );
38 assert( vec2( vec3( v4_2 )).data == [ 1.0f, 2.0f ] );
39 assert( vec2( vec3( v4_2 )).data == vec2( v4_2 ).data );
40 assert( v4_2.data == vec4([ 1.0f, 2.0f, 3.0f, 4.0f ] ).data );
41 
42 float[2] f2 = [ 1.0f, 2.0f ];
43 float[3] f3 = [ 1.0f, 2.0f, 3.0f ];
44 float[4] f4 = [ 1.0f, 2.0f, 3.0f, 4.0f ];
45 assert( vec2( 1.0f, 2.0f ).data == vec2(f2).data);
46 assert( vec3( 1.0f, 2.0f, 3.0f ).data == vec3( f3 ).data );
47 assert( vec3( 1.0f, 2.0f, 3.0f ).data == vec3( f2, 3.0f ).data );
48 assert( vec4( 1.0f, 2.0f, 3.0f, 4.0f ).data == vec4( f4 ).data );
49 assert( vec4( 1.0f, 2.0f, 3.0f, 4.0f ).data == vec4( f3, 4.0f ).data );
50 assert( vec4( 1.0f, 2.0f, 3.0f, 4.0f ).data == vec4( f2, 3.0f, 4.0f ).data );
51 // useful for: "vec4 v4 = […]" or "vec4 v4 = other_vector.rgba"
52 
53 assert( vec3( vec3i( 1, 2, 3 )) == vec3( 1.0, 2.0, 3.0 ));
54 assert( vec3d( vec3( 1.0, 2.0, 3.0 )) == vec3d( 1.0, 2.0, 3.0 ));

Meta