# Re: [geometry] Improving calculation performance?

From: Simon Pieters <simonp@opera.com>
Date: Tue, 19 Jan 2016 09:09:10 +0100
To: public-fx@w3.org, /#!/JoePea <trusktr@gmail.com>
Cc: "Robert O'Callahan" <rocallahan@mozilla.com>, "Jinho Bang" <jinho.bang@samsung.com>
Message-ID: <op.ybg7lkbtidj3kv@simons-mbp>
```On Tue, 05 Jan 2016 02:15:03 +0100, /#!/JoePea <trusktr@gmail.com> wrote:

> It seems like Famous 0.3.x (https://github.com/Famous/famous) does
> less calculations, and ends with the same results. When rotating
> around Z, using Famous' `Transform.rotateZ(45 * Math.PI/180)`, we get
> the same value for m11 as we do with `DOMMatrix.rotate(45)`.
>
> Here's what Famous is doing:
> https://github.com/Famous/famous/blob/develop/src/core/Transform.js#L284-L306
>
> We see the value for m11 is calculated as
>
> ```
> x * x * (1 - Math.cos(theta)) + Math.cos(theta)
> ```
>
> (inferred by replacing all the variables with their actual calculations).
>
> In DOMMatrix, the value for m11 is calculated as
>
> ```
> 1-2*(y*y + z*z)*Math.pow(Math.sin(angle/2 * Math.PI/180), 2)
> ```
>
> . If we assume radians in the calculation, that is
>
> ```
> 1-2*(y*y + z*z)*Math.pow(Math.sin(theta/2), 2)
> ```
>
> , which can be written as
>
> ```
> 1-2*(y*y + z*z)*Math.sin(theta)*Math.sin(theta)
> ```
>
> . Now, comparing the two, we see that the Famous Transform calculation
> has 6 steps and the DOMMatrix calculation has 9 steps, so the Famous
> Transform calculations may be faster.
>
> If we simplify each calculation (Trnsform and DOMMatrix m11 rotation,
> assuming we are rotating around the Z axis), then both formulas
> become, respectively:
>
> ```
> Math.cos(theta)
> ```
>
> and
>
> ```
> 1-2*Math.sin(theta/2)*Math.sin(theta/2)
> ```

When I compare these two for theta=45, the results are not the same. If
they were exactly the same, we could leave the spec as is and an
implementation could do the other thing and still comply.

They might well be close enough to not matter in practice, but for
testable interop we need to choose one or the other. I don't mind changing
this but it would be good to have browser implementors on board as well.

> There might be room for improvement on the calculations specified in
> the spec, depending on which trig identities we choose. This would be
> good considering we want graphic calculations to be as fast as
> possible.
>
> /#!/JoePea
>

--
Simon Pieters
Opera Software
```
Received on Tuesday, 19 January 2016 08:09:48 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 19 January 2016 08:09:49 UTC