Quantcast
Channel: GameDev.net
Viewing all articles
Browse latest Browse all 17825

Manual syntax trees

$
0
0
I thought this thing I wrote might be a worthy candidate for a coding horror. Expression* SymbolicMatrix::determinant3x3() const { /* * Given the matrix * * / a b c \ * A = | d e f | * \ g h i / * * The determinant can be calculated with: * * det(A) = (aei + bfg + cdh) - (gec + hfa + idb) * * The entries in the matrix are stored such that a=0, b=1, c=2, etc. */ return Expression::make(op::sub, // (aei + bfg + cdh) - (gec + hfa + idb) Expression::make(op::add, // aei + bfg + cdh Expression::make(op::add, // aei + bfg Expression::make(op::mul, // aei Expression::make(op::mul, // ae entries_[0]->clone(), // a entries_[4]->clone()), // e entries_[8]->clone()), // i Expression::make(op::mul, // bfg Expression::make(op::mul, // bf entries_[1]->clone(), // b entries_[5]->clone()), // f entries_[6]->clone())), // g Expression::make(op::mul, // cdh Expression::make(op::mul, // cd entries_[2]->clone(), // c entries_[3]->clone()), // d entries_[2*3+1]->clone())), // h Expression::make(op::add, // gec + hfa + idb Expression::make(op::add, // gec + hfa Expression::make(op::mul, // gec Expression::make(op::mul, // ge entries_[6]->clone(), // g entries_[4]->clone()), // e entries_[2]->clone()), // c Expression::make(op::mul, // hfa Expression::make(op::mul, // hf entries_[7]->clone(), // h entries_[5]->clone()), // f entries_[0]->clone())), // a Expression::make(op::mul, // idb Expression::make(op::mul, // id entries_[8]->clone(), // i entries_[3]->clone()), // d entries_[1]->clone()))); // b } All jokes aside, how would one make this look better?

Viewing all articles
Browse latest Browse all 17825

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>