@@ -182,22 +182,36 @@ public static bool PerformArithmetic(this SyntaxNode rootNode)
182
182
didChange = true ;
183
183
}
184
184
185
- // dot (vecN(nums), vecN(nums)) => <the result>
186
- foreach ( var dotNode in functionCalls
187
- . Where ( o => o . Name == "dot" && o . Params . Children . Any ( n => ( n . Token as TypeToken ) ? . IsVector ( ) == true ) )
185
+ // <func> (vecN(nums), vecN(nums)) => <the result>
186
+ foreach ( var functionNode in functionCalls
187
+ . Where ( o => o . Params . Children . Any ( n => ( n . Token as TypeToken ) ? . IsVector ( ) == true ) )
188
188
. ToList ( ) )
189
189
{
190
- var dotParams = dotNode . Params . GetCsv ( ) . ToList ( ) ;
190
+ var dotParams = functionNode . Params . GetCsv ( ) . ToList ( ) ;
191
191
var vectors = dotParams . Select ( o => o . First ( ) ) . Where ( o => ( o . Token as TypeToken ) ? . IsVector ( ) == true ) . ToList ( ) ;
192
192
var nums = vectors . Select ( GetVectorNumericCsv ) . ToList ( ) ;
193
193
if ( nums . All ( o => o == null ) )
194
194
continue ; // Neither arg is a simple numeric vector.
195
195
196
- if ( nums . Count ( o => o != null ) == 2 )
196
+ // Are both args vectors and simple numeric?
197
+ var isSimpleNumeric = nums . Count ( o => o != null ) == 2 ;
198
+ if ( isSimpleNumeric && functionNode . Name == "pow" )
199
+ {
200
+ // pow(vecN(nums), vecN(nums)) => <the result>
201
+ ReplaceNodeWithVector ( functionNode , nums [ 0 ] . Select ( ( _ , i ) => Math . Pow ( nums [ 0 ] [ i ] , nums [ 1 ] [ i ] ) ) . ToList ( ) ) ;
202
+ didChange = true ;
203
+ continue ;
204
+ }
205
+
206
+ // dot(vecN(nums), vecN(nums)) => <the result>
207
+ if ( functionNode . Name != "dot" )
208
+ continue ;
209
+
210
+ if ( isSimpleNumeric )
197
211
{
198
212
// Both args are vectors and simple numeric - We can calculate the result.
199
- var sum = nums [ 0 ] . Select ( ( t , i ) => t * nums [ 1 ] [ i ] ) . Sum ( ) ;
200
- dotNode . ReplaceWith ( new GenericSyntaxNode ( FloatToken . From ( sum , MaxDp ) ) ) ;
213
+ var result = nums [ 0 ] . Select ( ( t , i ) => t * nums [ 1 ] [ i ] ) . Sum ( ) ;
214
+ functionNode . ReplaceWith ( new GenericSyntaxNode ( FloatToken . From ( result , MaxDp ) ) ) ;
201
215
didChange = true ;
202
216
continue ;
203
217
}
@@ -217,7 +231,7 @@ public static bool PerformArithmetic(this SyntaxNode rootNode)
217
231
// Replace the dot().
218
232
var oneIndex = GetVectorNumericCsv ( vectorWithAOne ) . IndexOf ( 1.0 ) ;
219
233
var newNode = new GenericSyntaxNode ( $ "{ node . Token . Content } .{ "xyzw" [ oneIndex ] } ") ;
220
- dotNode . ReplaceWith ( newNode ) ;
234
+ functionNode . ReplaceWith ( newNode ) ;
221
235
didChange = true ;
222
236
}
223
237
0 commit comments