[svgwg] Issue: 7.2 equivalent transform of an SVG viewport is mathematically wrong marked as Co-ordinates chapter

AmeliaBR has just labeled an issue for https://github.com/w3c/svgwg as
 "Co-ordinates chapter":

== 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)"

See https://github.com/w3c/svgwg/issues/215

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