Yesterday I was chasing a bug for a few hours which looked like this:
let m : BABYLON.Matrix = ...
// do a few things ...
// show a debug box
let box = createBox(...);
let tf = new BABYLON.TransformNode(...);
tf.setPreTransformMatrix(m.invert());
box.parent = tf;
// actual code continues and does something with the Matrix m
This code worked with the debug box, and stopped working when I removed all my debug visualisations.
It was quite a head scratcher.
Can you see the issue immediatly?
Most InPlace mutating methods have the InPlace
suffix, like Vector3
add
vs addInPlace
.
A few exceptions are Vector3
normalizeToNew
vs normalize
or Matrix
where invert
mutates in place and there is no ToNew
, only invertToRef
.
This is made even worse by the fact that invert
mutates in place and then returns itself. If it was void-returning, I’d have noticed my mistake much earlier.
Concrete suggestion:
deprecate all similar in-place mutating methods, create new ones with InPlace
and/or ToNew
suffixes.
Please note that I’m writing this suggestion in anger after wasting half a day yesterday, but I really doubt I’m the only one stumbling over this inconsistency and it would be an improvement to normalize this.