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