Changes in libcfa/src/vec/vec.hfa [250dbae:fd54fef]
- File:
-
- 1 edited
-
libcfa/src/vec/vec.hfa (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/vec/vec.hfa
r250dbae rfd54fef 1 // 2 // Cforall Version 1.0.0 Copyright (C) 2021 University of Waterloo 3 // 4 // The contents of this file are covered under the licence agreement in the 5 // file "LICENCE" distributed with Cforall. 6 // 7 // io/types.hfa -- 8 // 9 // Author : Dimitry Kobets 10 // Created On : 11 // Last Modified By : 12 // Last Modified On : 13 // Update Count : 14 // 15 1 16 #pragma once 2 17 3 18 #include <math.hfa> 4 19 5 trait fromint( otypeT) {20 trait fromint(T) { 6 21 void ?{}(T&, int); 7 22 }; 8 trait zeroinit( otypeT) {23 trait zeroinit(T) { 9 24 void ?{}(T&, zero_t); 10 25 }; 11 trait zero_assign( otypeT) {26 trait zero_assign(T) { 12 27 T ?=?(T&, zero_t); 13 28 }; 14 trait subtract( otypeT) {29 trait subtract(T) { 15 30 T ?-?(T, T); 16 31 }; 17 trait negate( otypeT) {32 trait negate(T) { 18 33 T -?(T); 19 34 }; 20 trait add( otypeT) {35 trait add(T) { 21 36 T ?+?(T, T); 22 37 }; 23 trait multiply( otypeT) {38 trait multiply(T) { 24 39 T ?*?(T, T); 25 40 }; 26 trait divide( otypeT) {41 trait divide(T) { 27 42 T ?/?(T, T); 28 43 }; 29 trait lessthan( otypeT) {44 trait lessthan(T) { 30 45 int ?<?(T, T); 31 46 }; 32 trait equality( otypeT) {47 trait equality(T) { 33 48 int ?==?(T, T); 34 49 }; 35 trait sqrt( otypeT) {50 trait sqrt(T) { 36 51 T sqrt(T); 37 52 }; … … 53 68 } 54 69 55 trait dottable( otype V, otypeT) {70 trait dottable(V, T) { 56 71 T dot(V, V); 57 72 }; … … 59 74 static inline { 60 75 61 forall( otype T | sqrt(T), otypeV | dottable(V, T))76 forall(T | sqrt(T), V | dottable(V, T)) 62 77 T length(V v) { 63 78 return sqrt(dot(v, v)); 64 79 } 65 80 66 forall( otype T, otypeV | dottable(V, T))81 forall(T, V | dottable(V, T)) 67 82 T length_squared(V v) { 68 83 return dot(v, v); 69 84 } 70 85 71 forall( otype T, otypeV | { T length(V); } | subtract(V))86 forall(T, V | { T length(V); } | subtract(V)) 72 87 T distance(V v1, V v2) { 73 88 return length(v1 - v2); 74 89 } 75 90 76 forall( otype T, otypeV | { T length(V); V ?/?(V, T); })91 forall(T, V | { T length(V); V ?/?(V, T); }) 77 92 V normalize(V v) { 78 93 return v / length(v); … … 80 95 81 96 // Project vector u onto vector v 82 forall( otype T, otypeV | dottable(V, T) | { V normalize(V); V ?*?(V, T); })97 forall(T, V | dottable(V, T) | { V normalize(V); V ?*?(V, T); }) 83 98 V project(V u, V v) { 84 99 V v_norm = normalize(v); … … 87 102 88 103 // Reflect incident vector v with respect to surface with normal n 89 forall( otype T | fromint(T), otypeV | { V project(V, V); V ?*?(T, V); V ?-?(V,V); })104 forall(T | fromint(T), V | { V project(V, V); V ?*?(T, V); V ?-?(V,V); }) 90 105 V reflect(V v, V n) { 91 106 return v - (T){2} * project(v, n); … … 96 111 // entering material (i.e., from air to water, eta = 1/1.33) 97 112 // v and n must already be normalized 98 forall( otypeT | fromint(T) | subtract(T) | multiply(T) | add(T) | lessthan(T) | sqrt(T),99 otypeV | dottable(V, T) | { V ?*?(T, V); V ?-?(V,V); void ?{}(V&, zero_t); })113 forall(T | fromint(T) | subtract(T) | multiply(T) | add(T) | lessthan(T) | sqrt(T), 114 V | dottable(V, T) | { V ?*?(T, V); V ?-?(V,V); void ?{}(V&, zero_t); }) 100 115 V refract(V v, V n, T eta) { 101 116 T dotValue = dot(n, v); … … 113 128 // i is the incident vector 114 129 // ng is the geometric normal of the surface 115 forall( otype T | lessthan(T) | zeroinit(T), otypeV | dottable(V, T) | negate(V))130 forall(T | lessthan(T) | zeroinit(T), V | dottable(V, T) | negate(V)) 116 131 V faceforward(V n, V i, V ng) { 117 132 return dot(ng, i) < (T){0} ? n : -n;
Note:
See TracChangeset
for help on using the changeset viewer.