Re: API for matrix manipulation

On Mar 14, 2011, at 7:56 AM, Joćo Eiras wrote:

> Hi.
> Given that a number of API are being developed that require complex
> matricial calculations (transforms, device orientation, web gl), I
> would suggest that perhaps an API with a big number of common
> calculations could be made available ? And a proper way to represent
> them. Perhaps, the best way to add this would be to extend the Math
> object with things like.
> Math.mAdd(m1, m2)
> Math.mSub(m1, m2)
> Math.mMult(m1, m2)
> Math.mDiv(m1, m2)
> Math.mInverse(m1)
> Math.mGaussianReduce(m1)
> Math.mRank(m1)
> Math.mRank(m1)
> Being the matrix an array like object like (could even be one of those
> fast arrays like ArrayBuffer).
> # {
> #  w: <width>,
> #  h: <height>,
> #  length: <width * heigth>
> #  0: ...,
> #  1: ...,
> #  2: ...
> #  (...)
> # }
> Comments or is something already being worked on ?

There are already 2 such classes: SVGMatrix and CSSMatrix. The former is an affine transformation matrix (commonly misnamed a "2x3 matrix") and the latter is a 3D homogeneous transformation matrix (commonly correctly named a "4x4 matrix").

We added CSSMatrix to the CSS Transform Spec to give us the same functionality as SVG Matrix, but for 3D transforms. Therefore both of these classes are pretty light on their operators. It might be useful to discuss "one matrix to rule them all", which could be used in place of the current classes and with more functionality. But it's important not to go too far down this path, or you'll end up defining classes for Points, Lines, Planes, Bounding Boxes and View Volumes with dozens of functions. Down that path lies madness.

I think the current spec handles the more complex (inverse and multiply) and more commonly used (scale, rotate, translate) functions. I'm not sure what adding and subtracting 2 matrices means, and division is handled by inverse and multiply. The others seem pretty domain specific for a general class. And remember you can (and many people have) created JS libraries to add funcrtions to the built-in matrix classes. I wrote one:

which uses CSSMatrix if it exists and uses JS otherwise. It exposed some interesting deficiencies in the current CSSMatrix class. There are several bugs on WebKit to address these and other issues of matrix efficiency and functionality: 23799, 28850, 50633, 52488. Perhaps it would be useful to open these (or similar) bugs on the w3c bug system?

That's where I believe we are on the Matrix front.


Received on Monday, 14 March 2011 16:18:26 UTC