Hello,
I am going through Day74 where Casey Muratori is defining the stairs and in that vein he implements Barycentric coordinates for the stairwell.
Now in this, when he wrote the GetBarycentric
function I couldn't help but notice that its basically 3 vector equations that have to be written out because of the pesky division. If only it was a multiplication we could have used the Hadamard
function that was already written earlier and be done with 1 equation.
so... "I focussed on that", and I found on wikipedia that there is a thing called Hadamard division as well. Then I implemented it:
inline v3 HadamardDivide(v3 A, v3 B) { v3 Result = V3(SafeRatio0(A.X, B.X), SafeRatio0(A.Y, B.Y), SafeRatio0(A.Z, B.Z)); return Result; }
And this "compressed" my GetBarycentric
function into a single line like this:
inline v3 GetBarycentric(rectangle3 A, v3 P) { v3 Result = HadamardDivide(P - A.Min, A.Max - A.Min); return Result; }
Now, I am not even sure if Casey Muratori will even call this compression (hence my quotes before). Because its not like I am seeing this pattern repeat and using this to make things efficient. I'm simply doing a cute thing I found intriguing.
If I was still a haskell dude, I would take this even farther and say, well, why do I even have to call SafeRatio0
3 times when implementing the HadamardDivide
? I could somehow apply that as a functor on the vector right? Some kind of fmap
would do that job nicely... But I see that this is a slipperly slope and I'm not gaining anything here except maybe making code that feels cute to me right now.
So, my question is, how do you decide when to stop?. Its not that hard for me to convince myself to do all this "fancy" stuff. Certainly before I found handmade hero, I would have absolutely done this. And I would have tried to "rewrite the whole thing in rust". So, does this judgement only come through experience or has Casey Muratori shown somewhere how to decide when its time to stop?