Vector.opBinary

Componentwise binary operation with aonther vector: addition, subtraction, multiplication, division

  1. Vector opBinary(valueType s)
  2. Vector opBinary(Vector v)
    struct Vector(type, int dim)
    @safe pure nothrow
    opBinary
    const
    (
    string op
    )
    if (
    (op == "+") ||
    (op == "-")
    ||
    (op == "*")
    ||
    (op == "/")
    )
    if (
    (dim >= 2) &&
    (dim <= 4)
    )

Examples

Unittest OpBinary

1 vec2 v2 = vec2( 1.0f, 3.0f );
2 cast( void )( 2 * v2 );
3 assert(( v2 * 2.5f ).data == [ 2.5f, 7.5f ] );
4 assert(( v2 + vec2( 3.0f, 1.0f )).data == [ 4.0f, 4.0f ] );
5 assert(( v2 - vec2( 1.0f, 3.0f )).data == [ 0.0f, 0.0f ] );
6 assert(( v2 * vec2( 2.0f, 2.0f ))  == vec2( 2.0f, 6.0f ));
7 
8 vec3 v3 = vec3( 1.0f, 3.0f, 5.0f );
9 assert(( v3 * 2.5f ).data == [ 2.5f, 7.5f, 12.5f ] );
10 assert(( v3 + vec3( 3.0f, 1.0f,  - 1.0f )).data == [ 4.0f, 4.0f, 4.0f ] );
11 assert(( v3 - vec3( 1.0f, 3.0f, 5.0f )).data == [ 0.0f, 0.0f,  0.0f ] );
12 assert(( v3 * vec3( 2.0f, 2.0f, 2.0f ))  == vec3( 2.0f, 6.0f, 10.0f ));
13 
14 vec4 v4 = vec4( 1.0f, 3.0f, 5.0f, 7.0f );
15 assert(( v4 * 2.5f ).data == [ 2.5f, 7.5f, 12.5f, 17.5 ] );
16 assert(( v4 + vec4( 3.0f, 1.0f, - 1.0f, - 3.0f )).data == [ 4.0f, 4.0f, 4.0f, 4.0f ] );
17 assert(( v4 - vec4( 1.0f, 3.0f, 5.0f, 7.0f )).data == [ 0.0f, 0.0f,  0.0f,  0.0f ] );
18 assert(( v4 * vec4( 2.0f, 2.0f, 2.0f, 2.0f ))  == vec4( 2.0f, 6.0f, 10.0f, 14.0f ));
19 

Meta