Changeset ae09808


Ignore:
Timestamp:
Dec 13, 2019, 7:54:05 PM (5 years ago)
Author:
Dmitry Kobets <dkobets@…>
Branches:
ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
Children:
0f4527d
Parents:
7799f79
Message:

Add vector division and multiplication to vec3 + tests

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/vec/vec3.hfa

    r7799f79 rae09808  
    7171    }
    7272
    73     // Scalar Multiplication
     73    // Multiplication
    7474    forall(| multiply(T)) {
    7575    vec3(T) ?*?(vec3(T) v, T scalar) with (v) { // TODO (can't make this const ref)
     
    7979        return v * scalar;
    8080    }
     81    vec3(T) ?*?(vec3(T) u, vec3(T) v) {
     82        return [u.x * v.x, u.y * v.y, u.z * v.z];
     83    }
    8184    vec3(T)& ?*=?(vec3(T)& v, T scalar) {
    8285        v = v * scalar;
    8386        return v;
    8487    }
     88    vec3(T)& ?*=?(vec3(T)& u, vec3(T) v) {
     89        u = u * v;
     90        return u;
     91    }
    8592    }
    8693
    87     // Scalar Division
     94    // Division
    8895    forall(| divide(T)) {
    8996    vec3(T) ?/?(vec3(T) v, T scalar) with (v) {
    9097        return [x / scalar, y / scalar, z / scalar];
    9198    }
     99    vec3(T) ?/?(vec3(T) u, vec3(T) v) {
     100        return [u.x / v.x, u.y / v.y, u.z / v.z];
     101    }
    92102    vec3(T)& ?/=?(vec3(T)& v, T scalar) with (v) {
    93103        v = v / scalar;
    94104        return v;
     105    }
     106    vec3(T)& ?/=?(vec3(T)& u, vec3(T) v) {
     107        u = u / v;
     108        return u;
    95109    }
    96110    }
  • tests/vector/.expect/vec3_float.txt

    r7799f79 rae09808  
    1414s*v:<4.5,8.25,300.9>
    1515?*=?:<4.5,8.25,300.9>
     16?*?(vec):<2.,6.,13.5>
     17?*=?(vec):<2.,6.,13.5>
    1618?/?:<0.666667,-0.0333333,15.>
    1719?/=?:<0.666667,-0.0333333,15.>
     20?/?(vec):<1.,-0.0333333,0.666667>
     21?/=?(vec):<1.,-0.0333333,0.666667>
    1822dot_1:0.
    1923dot_2:37.8
  • tests/vector/vec3_float.cfa

    r7799f79 rae09808  
    4747    sout | "?*=?:" | v1;
    4848
     49    {
     50        vec3(float) u = {1, 2, 3};
     51        vec3(float) v = {2, 3, 4.5f};
     52        sout | "?*?(vec):" | (u * v);
     53        sout | "?*=?(vec):" | (u *= v);
     54    }
     55
    4956    v1 = (vec3(float)){2, -0.1f, 45};
    5057    sout | "?/?:" | (v1 / 3.f);
     
    5259    v1 /= 3.f;
    5360    sout | "?/=?:" | v1;
     61
     62    {
     63        vec3(float) u = {2, -0.1f, 3};
     64        vec3(float) v = {2, 3, 4.5f};
     65        sout | "?/?(vec):" | (u / v);
     66        sout | "?/=?(vec):" | (u /= v);
     67    }
    5468
    5569    v1 = (vec3(float)){4,2,3};
Note: See TracChangeset for help on using the changeset viewer.