So I was just writing some code for fun which required basic use of 3D vectors, quaternions and matrices.

So I was just writing some code for fun which required basic use of 3D vectors, quaternions and matrices.

Great I thought, Delphi has that in System.Math.Vectors now, thanks to FireMonkey.

Now, considering at least half of FireMonkey is about 3D rendering, it's impressive that the core math routines are written by someone who clearly does not know the first thing about linear algebra. As a result, System.Math.Vectors is one big clusterfuck of bad code.

Some highlights:

- TVector3D.CrossProduct() is deprecated apparently, telling us to use TPoint3D.CrossProduct() instead. Never mind that the cross product is only defined for vectors and not for points. In fact, TPoint3D contains several methods which simply does not make sense for points, and in reality is a vector in disguise.

- The Equal operator overloads use epsilon checking. This should not be done by default, because it may not be what the user wants. In addition, the epsilon is fixed (though fortunately not constant), requiring the user to know when it has to be adjusted, possibly on a per-comparison basis.

- TVector3D looks and acts like a homogeneous vector, one which can be transformed to cartesian space by letting x_cartesian = x/w and similar for the other components. And indeed it does this transformation when you cast a TVector3D to a TPoint3D (a mild surprise). However the TVector3D's overloaded operators do not do what one would expect at all. Homogenous vectors are used to represent vectors in cartesian space, and as such one expects adding and scaling them would behave as-if you deal with cartesian vectors. TVecto3D does not do anything remotely like that when you write "r := v + w;" or "w := v * 2;". In fact I'm not sure they do anything remotely useful at all.

- TQuaternion3D does not have operator overloads for addition or scaling (multiplication with scalar).

- TMatrix does not have a Transpose method, like TMatrix3D, but does have Adjoint, Inverse etc methods.

My suggestion would be to nuke the unit from orbit and hire an intern which has actually taken a linear algebra course to rewrite it.

Comments

  1. I think you're a bit too hard on the guys, after all, they have to deal with a ton of stuff in a very short period with little to no motivation...

    ReplyDelete
  2. Yeah... lack of motivation is well put :-D

    ReplyDelete
  3. Marco Cantù Asbjørn Heid Would it make sense to QC this issues?

    ReplyDelete
  4. Still using my own Math3D for my SOftwarerenderer. Rough implementation of the most needed things(for me) from a general dokument on 3D-Math. However, i don't hink this is a good example either^^

    ReplyDelete

Post a Comment