@@ -182,22 +182,36 @@ public static bool PerformArithmetic(this SyntaxNode rootNode)
182182 didChange = true ;
183183 }
184184
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 ) )
188188 . ToList ( ) )
189189 {
190- var dotParams = dotNode . Params . GetCsv ( ) . ToList ( ) ;
190+ var dotParams = functionNode . Params . GetCsv ( ) . ToList ( ) ;
191191 var vectors = dotParams . Select ( o => o . First ( ) ) . Where ( o => ( o . Token as TypeToken ) ? . IsVector ( ) == true ) . ToList ( ) ;
192192 var nums = vectors . Select ( GetVectorNumericCsv ) . ToList ( ) ;
193193 if ( nums . All ( o => o == null ) )
194194 continue ; // Neither arg is a simple numeric vector.
195195
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 )
197211 {
198212 // 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 ) ) ) ;
201215 didChange = true ;
202216 continue ;
203217 }
@@ -217,7 +231,7 @@ public static bool PerformArithmetic(this SyntaxNode rootNode)
217231 // Replace the dot().
218232 var oneIndex = GetVectorNumericCsv ( vectorWithAOne ) . IndexOf ( 1.0 ) ;
219233 var newNode = new GenericSyntaxNode ( $ "{ node . Token . Content } .{ "xyzw" [ oneIndex ] } ") ;
220- dotNode . ReplaceWith ( newNode ) ;
234+ functionNode . ReplaceWith ( newNode ) ;
221235 didChange = true ;
222236 }
223237
0 commit comments