Re: Proposal for a new Matrix API

2011-10-25 Thread Igor Oliveira
Hello,

On Fri, Oct 21, 2011 at 8:04 PM, Cameron McCormack c...@mcc.id.au wrote:
 On 20/10/11 10:39 AM, Igor Oliveira wrote:

 Currently CSSMatrix and SVGMatrix has an immutable API. None of the
 method calls change the Matrix, instead, it creates a new Matrix with
 the changed value. It can be a problem specially when CSSMatrix is
 used together with WebGL. [1]

 SVGMatrix is not immutable.  You can modify the a, b, ..., f properties.

Yeah, i meant the rotate, multiply, inverse, translate and others methods.


 http://www.w3.org/TR/SVG/coords.html#InterfaceSVGMatrix

 However the methods that perform operations do return new matrices rather
 than modifying the one the method is called on.

 We from WebKit are proposing a new Matrix API(simple as possible), see
 below or [2], where the standard methods change the matrix(in place
 operations) and additional methods (multipliedBy, scaledBy and so on)
 create a new Matrix as is done by CSSMatrix and SVGMatrix.

 The idea is make this class accepted where CSSMatrix and SVGMatrix is
 used and be the preferred class for all Matrix needs. [3]

 I agree that unifying CSSMatrix/SVGMatrix is a good idea, if that is
 possible.  Will look at your specific proposal a bit later.


Great.

Igor



Re: Proposal for a new Matrix API

2011-10-21 Thread João Eiras
On Thu, 20 Oct 2011 16:39:56 +0200, Igor Oliveira  
igor.olive...@openbossa.org wrote:



Hello,

Currently CSSMatrix and SVGMatrix has an immutable API. None of the
method calls change the Matrix, instead, it creates a new Matrix with
the changed value. It can be a problem specially when CSSMatrix is
used together with WebGL. [1]



I would suggest that the matrix should not be a host object. Instead is  
should be a pure ecmascript object so it can run closer to the metal (be  
jitted easily).


I did suggest previously extending array a bit, like

{length: 6, height: 2, width:3, 0. ..., 1: ..., 2: ..., 3: ..., 4: ..., 5:  
...,  }


which represents a 2x3 matrix. The matrix would not have any kind of side  
effects or limitations, possibly being of any arbitrary size, hence usable  
not only by graphical APIs, but by any algebra you throw at it.


The methods you suggest, would then be on the prototype, or in the Math  
object.




Re: Proposal for a new Matrix API

2011-10-21 Thread Boris Zbarsky

On 10/21/11 11:28 AM, João Eiras wrote:

On Thu, 20 Oct 2011 16:39:56 +0200, Igor Oliveira
igor.olive...@openbossa.org wrote:


Hello,

Currently CSSMatrix and SVGMatrix has an immutable API. None of the
method calls change the Matrix, instead, it creates a new Matrix with
the changed value. It can be a problem specially when CSSMatrix is
used together with WebGL. [1]



I would suggest that the matrix should not be a host object. Instead is
should be a pure ecmascript object so it can run closer to the metal (be
jitted easily).


It may still want to be immutable.  This has certain benefits when you
want to do really high-performance computation; c.f. River Trail.

-Boris



Re: Proposal for a new Matrix API

2011-10-21 Thread Rick Waldron
On Fri, Oct 21, 2011 at 11:28 AM, João Eiras jo...@opera.com wrote:

 On Thu, 20 Oct 2011 16:39:56 +0200, Igor Oliveira 
 igor.olive...@openbossa.org wrote:

  Hello,

 Currently CSSMatrix and SVGMatrix has an immutable API. None of the
 method calls change the Matrix, instead, it creates a new Matrix with
 the changed value. It can be a problem specially when CSSMatrix is
 used together with WebGL. [1]


 I would suggest that the matrix should not be a host object. Instead is
 should be a pure ecmascript object so it can run closer to the metal (be
 jitted easily).


Assuming you mean native object when you refer to pure ecmascript
object, there is no performance benefit, JIT or otherwise. In fact, it's
possible to implement ES functionality with better performance then the
native implementations.




 I did suggest previously extending array a bit, like

 {length: 6, height: 2, width:3, 0. ..., 1: ..., 2: ..., 3: ..., 4: ..., 5:
 ...,  }

 which represents a 2x3 matrix. The matrix would not have any kind of side
 effects or limitations, possibly being of any arbitrary size, hence usable
 not only by graphical APIs, but by any algebra you throw at it.

 The methods you suggest, would then be on the prototype, or in the Math
 object.




Re: Proposal for a new Matrix API

2011-10-21 Thread Cameron McCormack

On 20/10/11 10:39 AM, Igor Oliveira wrote:

Currently CSSMatrix and SVGMatrix has an immutable API. None of the
method calls change the Matrix, instead, it creates a new Matrix with
the changed value. It can be a problem specially when CSSMatrix is
used together with WebGL. [1]


SVGMatrix is not immutable.  You can modify the a, b, ..., f properties.

http://www.w3.org/TR/SVG/coords.html#InterfaceSVGMatrix

However the methods that perform operations do return new matrices 
rather than modifying the one the method is called on.



We from WebKit are proposing a new Matrix API(simple as possible), see
below or [2], where the standard methods change the matrix(in place
operations) and additional methods (multipliedBy, scaledBy and so on)
create a new Matrix as is done by CSSMatrix and SVGMatrix.

The idea is make this class accepted where CSSMatrix and SVGMatrix is
used and be the preferred class for all Matrix needs. [3]


I agree that unifying CSSMatrix/SVGMatrix is a good idea, if that is 
possible.  Will look at your specific proposal a bit later.




Proposal for a new Matrix API

2011-10-20 Thread Igor Oliveira
Hello,

Currently CSSMatrix and SVGMatrix has an immutable API. None of the
method calls change the Matrix, instead, it creates a new Matrix with
the changed value. It can be a problem specially when CSSMatrix is
used together with WebGL. [1]

We from WebKit are proposing a new Matrix API(simple as possible), see
below or [2], where the standard methods change the matrix(in place
operations) and additional methods (multipliedBy, scaledBy and so on)
create a new Matrix as is done by CSSMatrix and SVGMatrix.

The idea is make this class accepted where CSSMatrix and SVGMatrix is
used and be the preferred class for all Matrix needs. [3]

Any comments or suggestions?

[1] http://www.khronos.org/webgl/public-mailing-list/archives/1006/msg00171.html
[2] https://gist.github.com/1301236
[3] https://bugs.webkit.org/show_bug.cgi?id=50633

-

IDL file for WebKitMatrix:

module css {

 // Introduced in DOM Level ?:
interface [
CanBeConstructed,
JSCustomConstructor,
ConstructorParameters=1,
Constructor(in [Optional=CallWithNullValue] DOMString cssValue),
ConstructorRaisesException,
] WebKitMatrix {

// These attributes are simple aliases for certain elements of
the 4x4 matrix
attribute double a; // alias for m11
attribute double b; // alias for m12
attribute double c; // alias for m21
attribute double d; // alias for m22
attribute double e; // alias for m41
attribute double f; // alias for m42

attribute double m11;
attribute double m12;
attribute double m13;
attribute double m14;
attribute double m21;
attribute double m22;
attribute double m23;
attribute double m24;
attribute double m31;
attribute double m32;
attribute double m33;
attribute double m34;
attribute double m41;
attribute double m42;
attribute double m43;
attribute double m44;

void setMatrixValue(in [Optional=CallWithDefaultValue]
DOMString string) raises (DOMException);

// Copy the matrix elements for a single precision float point array
void toArray(in Float32Array array);
// Copy the matrix elements for a double precision float point array
void toArray(in Float64Array array);

// Multiply this matrix by secondMatrix, on the right (result
= this * secondMatrix)
[Immutable] WebKitMatrix multipliedBy(in
[Optional=CallWithDefaultValue] WebKitMatrix secondMatrix);

// Multiply itself by a secondMatrix, on the right (this =
this * secondMatrix)
void multiply(in [Optional=CallWithDefaultValue] WebKitMatrix
secondMatrix);

// Inverse this matrix. Throw an exception if the matrix is not 
invertible
void inverse() raises (DOMException)

// Return the inverse of this matrix. Throw an exception if
the matrix is not invertible
[Immutable] WebKitMatrix inversedBy() raises (DOMException);

// Return this matrix translated by the passed values.
// Passing a NaN will use a value of 0. This allows the 3D
form to used for 2D operations
[Immutable] WebKitMatrix translatedBy(in
[Optional=CallWithDefaultValue] double x,
  in
[Optional=CallWithDefaultValue] double y,
  in
[Optional=CallWithDefaultValue] double z);

// Translate itself using the passed values.
// Passing a NaN will use a value of 0. This allows the 3D
form to used for 2D operations
void translate(in [Optional=CallWithDefaultValue] double x,
   in [Optional=CallWithDefaultValue] double y,
   in [Optional=CallWithDefaultValue] double z);

// Returns this matrix scaled by the passed values.
// Passing scaleX or scaleZ as NaN uses a value of 1, but
passing scaleY of NaN
// makes it the same as scaleX. This allows the 3D form to
used for 2D operations
[Immutable] WebKitMatrix scaledBy(in
[Optional=CallWithDefaultValue] double scaleX,
  in
[Optional=CallWithDefaultValue] double scaleY,
  in
[Optional=CallWithDefaultValue] double scaleZ);

// Scale itself using the passed values.
// Passing scaleX or scaleZ as NaN uses a value of 1, but
passing scaleY of NaN
// makes it the same as scaleX. This allows the 3D form to
used for 2D operations
void scale(in [Optional=CallWithDefaultValue] double scaleX,
   in [Optional=CallWithDefaultValue] double scaleY,
   in [Optional=CallWithDefaultValue] double scaleZ);

// Returns this matrix rotated by the passed values.
// If rotY and rotZ are NaN, rotate about Z (rotX=0,
rotateY=0, rotateZ=rotX).
// Otherwise use a rotation value of 0 for any passed