W3C home > Mailing lists > Public > whatwg@whatwg.org > September 2012

Re: [whatwg] Canvas arcTo method

From: Michael Day <mikeday@yeslogic.com>
Date: Wed, 12 Sep 2012 17:07:12 +1000
Message-ID: <505034A0.4090705@yeslogic.com>
To: Ian Hickson <ian@hixie.ch>
Cc: whatwg@lists.whatwg.org, Rik Cabanier <cabanier@gmail.com>
Hi Ian,

> Yeah, that's why the spec hand-waves to transform the line too... but I
> agree that that doesn't really work.
>
> Do you have any suggestion of how to spec this better?

This is the most general arcTo situation:

     setTransform(M0)
     lineTo(x0, y0)
     setTransform(M)
     arcTo(x1, y1, x2, y2, radius, ...)

To generate the arc we need three points: P0, P1, P2, all in the same 
coordinate system. The three points are:

P0 = inverse(M) * M0 * (x0, y0)
P1 = (x1, y1)
P2 = (x2, y2)

We are transforming (x0, y0) by M0, which is the transform current at 
the time the point was added to the path. This gives us a point in 
canvas coordinates that we can transform by the inverse of M, which is 
the transform current at the time the arc is added to the path. This 
gives us a point in the same coordinate space as P1 and P2.

In the common case where M = M0, the transforms cancel each other out 
and P0 = (x0, y0).

Once we have the three points in the same coordinate space we can 
generate the arc and then apply M to all of the points in the generated 
arc to draw the arc in canvas coordinates.

Does this make sense?

I don't think it is possible to specify this process without requiring 
an inverse transformation somewhere, to get all three points into the 
same coordinate space. If so, it is probably best to describe this 
explicitly, rather than ambiguously implying the need for it.

Best regards,

Michael
Received on Wednesday, 12 September 2012 07:07:42 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:45 UTC