[svgwg] 7.2 equivalent transform of an SVG viewport is mathematically wrong

AmeliaBR has just created a new issue for 
https://github.com/w3c/svgwg:

== 7.2 equivalent transform of an SVG viewport is mathematically wrong
 ==
Originally [filed via bugzilla by 
ccprog](https://www.w3.org/Bugs/Public/show_bug.cgi?id=29751):

I've tried to implement the algorithm described in section "7.2 
Computing the equivalent transform of an SVG viewport" and found it to
 be wrong.

> 9. Initialize translate-x to vb-x - e-x.
> 10. Initialize translate-y to vb-y - e-y.


The purpose of this is to move the viewport origin to the left/top 
coordinates of the viewBox. I. e. when the viewBox is to the right of 
the initial origin (vb-x > e-x), the origin needs to be moved to the 
right: x values get thus smaller (tx < 0).

In addition, the last sentence implies that translation is applied 
after scaling. In this case the translation values also need to be 
multiplied by the scaling values.

Therefore these steps must be

>  9. Initialize translate-x to (e-x - vb-x) * scale-x.
> 10. Initialize translate-y to (e-y - vb-y) * scale-y.


Here are a few test cases to illustrate:

x="0" y="0" width="21" height="10" viewBox="11 13 3 2" 
preserveAspectRatio="none" is equivalent to
transform="translate(-77 -65) scale(7 5)"

x="0" y="0" width="21" height="10" viewBox="11 13 3 2" 
preserveAspectRatio="xMinYMin meet" is equivalent to
transform="translate(-55 -65) scale(5 5)"

x="0" y="0" width="21" height="10" viewBox="11 13 3 2" 
preserveAspectRatio="xMidYMid meet" is equivalent to
transform="translate(-52 -65) scale(5 5)"

x="0" y="0" width="21" height="10" viewBox="11 13 3 2" 
preserveAspectRatio="xMaxYMax meet" is equivalent to
transform="translate(-49 -65) scale(5 5)"

x="0" y="0" width="21" height="10" viewBox="11 13 3 2" 
preserveAspectRatio="xMinYMin slice" is equivalent to
transform="translate(-77 -91) scale(7 7)"

x="0" y="0" width="21" height="10" viewBox="11 13 3 2" 
preserveAspectRatio="xMidYMid slice" is equivalent to
transform="translate(-77 -93) scale(7 7)"

x="0" y="0" width="21" height="10" viewBox="11 13 3 2" 
preserveAspectRatio="xMinYMin slice" is equivalent to
transform="translate(-77 -95) scale(7 7)"

Please view or discuss this issue at 
https://github.com/w3c/svgwg/issues/215 using your GitHub account

Received on Friday, 22 July 2016 22:58:44 UTC