1pub trait ShaderMath{
4 fn abs(self)->Self;
5
6 fn sin(self)->Self;
7 fn cos(self)->Self;
8 fn tan(self)->Self;
9 fn asin(self)->Self;
10 fn acos(self)->Self;
11 fn atan(self)->Self;
12
13 fn sinh(self)->Self;
14 fn cosh(self)->Self;
15 fn tanh(self)->Self;
16 fn asinh(self)->Self;
17 fn acosh(self)->Self;
18 fn atanh(self)->Self;
19
20 fn fract(self)->Self;
21 fn ceil(self)->Self;
22 fn floor(self)->Self;
23 fn min(self, v:Self)->Self;
24 fn max(self, v:Self)->Self;
25 fn clamp(self, low:Self, high:Self)->Self;
26 fn exp(self)->Self;
27 fn exp2(self)->Self;
28 fn ln(self)->Self;
29 fn log2(self)->Self;
30 fn log10(self)->Self;
31 fn powf(self, v:Self)->Self;
32 fn powi(self, p:i32)->Self;
33}
34
35impl ShaderMath for f32{
36 fn abs(self)->Self{self.abs()}
37 fn sin(self)->Self{self.sin()}
38 fn cos(self)->Self{self.cos()}
39 fn tan(self)->Self{self.tan()}
40 fn asin(self)->Self{self.asin()}
41 fn acos(self)->Self{self.acos()}
42 fn atan(self)->Self{self.atan()}
43
44 fn sinh(self)->Self{self.sinh()}
45 fn cosh(self)->Self{self.cosh()}
46 fn tanh(self)->Self{self.tanh()}
47 fn asinh(self)->Self{self.asinh()}
48 fn acosh(self)->Self{self.acosh()}
49 fn atanh(self)->Self{self.atanh()}
50
51 fn fract(self)->Self{self.fract()}
52 fn ceil(self)->Self{self.ceil()}
53 fn floor(self)->Self{self.floor()}
54 fn min(self, v:Self)->Self{self.min(v)}
55 fn max(self, v:Self)->Self{self.max(v)}
56 fn clamp(self, low:Self, high:Self)->Self{self.max(low).min(high)}
57 fn exp(self)->Self{self.exp()}
58 fn exp2(self)->Self{self.exp2()}
59 fn ln(self)->Self{self.ln()}
60 fn log2(self)->Self{self.log2()}
61 fn log10(self)->Self{self.log10()}
62 fn powf(self, v:Self)->Self{self.powf(v)}
63 fn powi(self, v:i32)->Self{self.powi(v)}
64}
65
66impl ShaderMath for f64{
67 fn abs(self)->Self{self.abs()}
68
69 fn sin(self)->Self{self.sin()}
70 fn cos(self)->Self{self.cos()}
71 fn tan(self)->Self{self.tan()}
72 fn asin(self)->Self{self.asin()}
73 fn acos(self)->Self{self.acos()}
74 fn atan(self)->Self{self.atan()}
75
76 fn sinh(self)->Self{self.sinh()}
77 fn cosh(self)->Self{self.cosh()}
78 fn tanh(self)->Self{self.tanh()}
79 fn asinh(self)->Self{self.asinh()}
80 fn acosh(self)->Self{self.acosh()}
81 fn atanh(self)->Self{self.atanh()}
82
83
84 fn fract(self)->Self{self.fract()}
85 fn ceil(self)->Self{self.ceil()}
86 fn floor(self)->Self{self.floor()}
87 fn min(self, v:Self)->Self{self.min(v)}
88 fn max(self, v:Self)->Self{self.max(v)}
89 fn clamp(self, low:Self, high:Self)->Self{self.max(low).min(high)}
90 fn exp(self)->Self{self.exp()}
91 fn exp2(self)->Self{self.exp2()}
92 fn ln(self)->Self{self.ln()}
93 fn log2(self)->Self{self.log2()}
94 fn log10(self)->Self{self.log10()}
95 fn powf(self, v:Self)->Self{self.powf(v)}
96 fn powi(self, v:i32)->Self{self.powi(v)}
97}
98
99pub fn abs<T:ShaderMath>(v:T)->T{v.abs()}
100
101pub fn sin<T:ShaderMath>(v:T)->T{v.sin()}
102pub fn cos<T:ShaderMath>(v:T)->T{v.cos()}
103pub fn tan<T:ShaderMath>(v:T)->T{v.tan()}
104pub fn asin<T:ShaderMath>(v:T)->T{v.asin()}
105pub fn acos<T:ShaderMath>(v:T)->T{v.acos()}
106pub fn atan<T:ShaderMath>(v:T)->T{v.atan()}
107
108pub fn sinh<T:ShaderMath>(v:T)->T{v.sinh()}
109pub fn cosh<T:ShaderMath>(v:T)->T{v.cosh()}
110pub fn tanh<T:ShaderMath>(v:T)->T{v.tanh()}
111pub fn asinh<T:ShaderMath>(v:T)->T{v.asinh()}
112pub fn acosh<T:ShaderMath>(v:T)->T{v.acosh()}
113pub fn atanh<T:ShaderMath>(v:T)->T{v.atanh()}
114
115pub fn fract<T:ShaderMath>(v:T)->T{v.fract()}
116pub fn ceil<T:ShaderMath>(v:T)->T{v.ceil()}
117pub fn floor<T:ShaderMath>(v:T)->T{v.floor()}
118pub fn min<T:ShaderMath>(v:T,l:T)->T{v.min(l)}
119pub fn max<T:ShaderMath>(v:T,l:T)->T{v.max(l)}
120pub fn clamp<T:ShaderMath>(v:T,l:T,h:T)->T{v.clamp(l,h)}
121pub fn exp<T:ShaderMath>(v:T)->T{v.exp()}
122pub fn exp2<T:ShaderMath>(v:T)->T{v.exp2()}
123pub fn ln<T:ShaderMath>(v:T)->T{v.ln()}
124pub fn log2<T:ShaderMath>(v:T)->T{v.log2()}
125pub fn log10<T:ShaderMath>(v:T)->T{v.log10()}
126pub fn pow<T:ShaderMath>(v:T,l:T)->T{v.powf(l)}
127pub fn powf<T:ShaderMath>(v:T,l:T)->T{v.powf(l)}
128pub fn powi<T:ShaderMath>(v:T,l:i32)->T{v.powi(l)}
129
130