[OpenJDK 2D-Dev] Fix for uniformly scaled dashed lines.
dlila at redhat.com
Tue Jun 15 20:53:31 UTC 2010
I think I have a fix for this bug: http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=504
The problem is caused by the "symmetric" variable in pisces/Dasher.java.
symmetric is set to (m00 == m11 && m10 == -m01), and never changed.
It is only used in one place (in lineTo) to simplify the computation of
the length of the line before an affine transformation A was applied to it.
This is why it causes a problem:
If A = [[a00, a01], [a10, a11]] and (x,y) is a point obtained by applying
A to some other point (x',y'), then what we want is the length of the vector
(x',y'), which is ||Ainv*(x,y)||. Ainv = (1/det(A)) * [[a11, -a01],[-a10, a00]],
so, after some calculations, ||Ainv*(x,y)|| ends up being equal to
sqrt(x^2*(a11^2 + a10^2) + y^2*(a00^2 + a01^2) - x*y*(a11*a01 + a00*a10)) * 1/|det(A)|.
If symmetric==true, this simplifies to:
sqrt((a11^2 + a01^2) * (x^2 + y^2)) * 1/|det(A)|, and
|det(A)| = a11^2 + a01^2, so, the final answer is:
sqrt((x^2 + y^2)) / sqrt(det(A)). Therefore the problem in Dasher.java
is that it divides by det(A), not sqrt(det(A)).
My fix for this was to remove the "symmetric" special case. Another possible fix
would have been to introduce an instance "sqrtldet" and set it to sqrt(det(A)),
and divide by that instead of det(A). This didn't seem worth it, because the only
benefit we gain by having the "symmetric" variable is to save 3 multiplications
and 1 division per iteration of the while(true) loop, at the expense of making the
code more complex, harder to read, introducing more opportunity for bugs, and adding
hundreds of operations of overhead (since PiscesMath.sqrt would have to be called to
To make up for this slight performance loss I have moved the code that computes
the transformed dash vectors outside of the while loop, since they are constant
and they only need to be computed once for any one line.
Moreover, computing the constant dash vectors inside the loop causes
them to not really be constant (since they're computed by dividing numbers that
aren't constant). This can cause irregularities in dashes (see comment 14 in
I would very much appreciate any comments/suggestions.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 4637 bytes
Desc: not available
More information about the 2d-dev