Changeset 250dbae for libcfa/src/vec


Ignore:
Timestamp:
Dec 31, 2019, 12:19:53 PM (4 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:
f8a8fb1
Parents:
94df8de
git-author:
Dmitry Kobets <dkobets@…> (12/31/19 12:13:34)
git-committer:
Dmitry Kobets <dkobets@…> (12/31/19 12:19:53)
Message:

Refactor vector library classes

Location:
libcfa/src/vec
Files:
4 edited

Legend:

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

    r94df8de r250dbae  
    7474}
    7575
    76 
    7776forall(otype T, otype V | { T length(V); V ?/?(V, T); })
    7877V normalize(V v) {
     
    114113// i is the incident vector
    115114// ng is the geometric normal of the surface
    116 /* forall(| add(T) | multiply(T) | lessthan(T) | fromint(T) | subtract(T)) */
    117115forall(otype T | lessthan(T) | zeroinit(T), otype V | dottable(V, T) | negate(V))
    118116V faceforward(V n, V i, V ng) {
  • libcfa/src/vec/vec2.hfa

    r94df8de r250dbae  
    1010}
    1111
    12 
    1312forall (otype T) {
    1413    static inline {
     
    3130    }
    3231
    33     // Assignment
    3432    void ?=?(vec2(T)& vec, vec2(T) other) with (vec) {
    3533        [x,y] = other.[x,y];
     
    4240    // Primitive mathematical operations
    4341
     42    // -
    4443    forall(| subtract(T)) {
    45     vec2(T) ?-?(vec2(T) u, vec2(T) v) { // TODO( can't make this const ref )
     44    vec2(T) ?-?(vec2(T) u, vec2(T) v) {
    4645        return [u.x - v.x, u.y - v.y];
    4746    }
     
    6968    }
    7069
     70    // +
    7171    forall(| add(T)) {
    72     vec2(T) ?+?(vec2(T) u, vec2(T) v) { // TODO( can't make this const ref )
     72    vec2(T) ?+?(vec2(T) u, vec2(T) v) {
    7373        return [u.x + v.x, u.y + v.y];
    7474    }
     
    9292    }
    9393
     94    // *
    9495    forall(| multiply(T)) {
    95     vec2(T) ?*?(vec2(T) v, T scalar) with (v) { // TODO (can't make this const ref)
     96    vec2(T) ?*?(vec2(T) v, T scalar) with (v) {
    9697        return [x * scalar, y * scalar];
    9798    }
    98     vec2(T) ?*?(T scalar, vec2(T) v) { // TODO (can't make this const ref)
     99    vec2(T) ?*?(T scalar, vec2(T) v) {
    99100        return v * scalar;
    100101    }
     
    112113    }
    113114
     115    // /
    114116    forall(| divide(T)) {
    115117    vec2(T) ?/?(vec2(T) v, T scalar) with (v) {
     
    119121        return [u.x / v.x, u.y / v.y];
    120122    }
    121     vec2(T)& ?/=?(vec2(T)& v, T scalar) with (v) {
     123    vec2(T)& ?/=?(vec2(T)& v, T scalar) {
    122124        v = v / scalar;
    123125        return v;
     
    129131    }
    130132
     133    // %
    131134    forall(| { T ?%?(T,T); }) {
    132135    vec2(T) ?%?(vec2(T) v, T scalar) with (v) {
     
    146149    }
    147150
     151    // &
    148152    forall(| { T ?&?(T,T); }) {
    149153    vec2(T) ?&?(vec2(T) v, T scalar) with (v) {
     
    163167    }
    164168
     169    // |
    165170    forall(| { T ?|?(T,T); }) {
    166171    vec2(T) ?|?(vec2(T) v, T scalar) with (v) {
     
    180185    }
    181186
     187    // ^
    182188    forall(| { T ?^?(T,T); }) {
    183189    vec2(T) ?^?(vec2(T) v, T scalar) with (v) {
     
    197203    }
    198204
     205    // <<
    199206    forall(| { T ?<<?(T,T); }) {
    200207    vec2(T) ?<<?(vec2(T) v, T scalar) with (v) {
     
    214221    }
    215222
     223    // >>
    216224    forall(| { T ?>>?(T,T); }) {
    217225    vec2(T) ?>>?(vec2(T) v, T scalar) with (v) {
     
    231239    }
    232240
     241    // ~
    233242    forall(| { T ~?(T); })
    234243    vec2(T) ~?(vec2(T) v) with (v) {
     
    236245    }
    237246
    238     // Relational Operators
     247    // relational
    239248    forall(| equality(T)) {
    240249    bool ?==?(vec2(T) u, vec2(T) v) with (u) {
  • libcfa/src/vec/vec3.hfa

    r94df8de r250dbae  
    1010}
    1111
    12 
    1312forall (otype T) {
    1413    static inline {
     
    3130    }
    3231
    33     // Assignment
    3432    void ?=?(vec3(T)& vec, vec3(T) other) with (vec) {
    3533        [x,y,z] = other.[x,y,z];
     
    4442    // -
    4543    forall(| subtract(T)) {
    46     vec3(T) ?-?(vec3(T) u, vec3(T) v) { // TODO( can't make this const ref )
     44    vec3(T) ?-?(vec3(T) u, vec3(T) v) {
    4745        return [u.x - v.x, u.y - v.y, u.z - v.z];
    4846    }
     
    5250    }
    5351    }
    54 
    5552    forall(| negate(T)) {
    5653    vec3(T) -?(vec3(T) v) with (v) {
     
    5855    }
    5956    }
    60 
    6157    forall(| { T --?(T&); }) {
    6258    vec3(T)& --?(vec3(T)& v) {
     
    7571    // +
    7672    forall(| add(T)) {
    77     vec3(T) ?+?(vec3(T) u, vec3(T) v) { // TODO( can't make this const ref )
     73    vec3(T) ?+?(vec3(T) u, vec3(T) v) {
    7874        return [u.x + v.x, u.y + v.y, u.z + v.z];
    7975    }
     
    8379    }
    8480    }
    85 
    8681
    8782    forall(| { T ++?(T&); }) {
     
    10196    // *
    10297    forall(| multiply(T)) {
    103     vec3(T) ?*?(vec3(T) v, T scalar) with (v) { // TODO (can't make this const ref)
     98    vec3(T) ?*?(vec3(T) v, T scalar) with (v) {
    10499        return [x * scalar, y * scalar, z * scalar];
    105100    }
    106     vec3(T) ?*?(T scalar, vec3(T) v) { // TODO (can't make this const ref)
     101    vec3(T) ?*?(T scalar, vec3(T) v) {
    107102        return v * scalar;
    108103    }
     
    128123        return [u.x / v.x, u.y / v.y, u.z / v.z];
    129124    }
    130     vec3(T)& ?/=?(vec3(T)& v, T scalar) with (v) {
     125    vec3(T)& ?/=?(vec3(T)& v, T scalar) {
    131126        v = v / scalar;
    132127        return v;
  • libcfa/src/vec/vec4.hfa

    r94df8de r250dbae  
    1010}
    1111
    12 
    1312forall (otype T) {
    1413    static inline {
     
    3130    }
    3231
    33     // Assignment
    3432    void ?=?(vec4(T)& vec, vec4(T) other) with (vec) {
    3533        [x,y,z,w] = other.[x,y,z,w];
     
    4442    // -
    4543    forall(| subtract(T)) {
    46     vec4(T) ?-?(vec4(T) u, vec4(T) v) { // TODO( can't make this const ref )
     44    vec4(T) ?-?(vec4(T) u, vec4(T) v) {
    4745        return [u.x - v.x, u.y - v.y, u.z - v.z, u.w - v.w];
    4846    }
     
    5250    }
    5351    }
    54 
    5552    forall(| negate(T)) {
    5653    vec4(T) -?(vec4(T) v) with (v) {
     
    5855    }
    5956    }
    60 
    6157    forall(| { T --?(T&); }) {
    6258    vec4(T)& --?(vec4(T)& v) {
     
    10298    // *
    10399    forall(| multiply(T)) {
    104     vec4(T) ?*?(vec4(T) v, T scalar) with (v) { // TODO (can't make this const ref)
     100    vec4(T) ?*?(vec4(T) v, T scalar) with (v) {
    105101        return [x * scalar, y * scalar, z * scalar, w * scalar];
    106102    }
    107     vec4(T) ?*?(T scalar, vec4(T) v) { // TODO (can't make this const ref)
     103    vec4(T) ?*?(T scalar, vec4(T) v) {
    108104        return v * scalar;
    109105    }
     
    121117    }
    122118
    123     // Scalar Division
     119    // /
    124120    forall(| divide(T)) {
    125121    vec4(T) ?/?(vec4(T) v, T scalar) with (v) {
     
    129125        return [u.x / v.x, u.y / v.y, u.z / v.z, u.w / v.w];
    130126    }
    131     vec4(T)& ?/=?(vec4(T)& v, T scalar) with (v) {
     127    vec4(T)& ?/=?(vec4(T)& v, T scalar) {
    132128        v = v / scalar;
    133129        return v;
     
    253249    }
    254250
    255     // Relational Operators
     251    // relational
    256252    forall(| equality(T)) {
    257253    bool ?==?(vec4(T) u, vec4(T) v) with (u) {
Note: See TracChangeset for help on using the changeset viewer.