summaryrefslogtreecommitdiff
path: root/basegfx
diff options
context:
space:
mode:
authorThorsten Behrens <tbehrens@suse.com>2012-01-18 14:52:20 -0500
committerKohei Yoshida <kohei.yoshida@suse.com>2012-01-18 14:52:20 -0500
commit9925d8023102d9b1c21da74faca829a61102da6a (patch)
treea8b8fb152f100951eead5707c8960929183f5c2f /basegfx
parent23fa04ddda57f710c01f96113cb1b17ff4eafa77 (diff)
decompose() should return the original rotation angle and scales.
decompose() would return incorrect rotation angle and scales when the angle was exactly 180 degrees, due to FPU rounding error. This commit fixes it. This problem would manifest itself when inserting an image into Calc/Draw, cropping it, and flipping it vertically or rotating it at exactly 180 degrees. Before the fix the image would simply disappear.
Diffstat (limited to 'basegfx')
-rw-r--r--basegfx/source/matrix/b2dhommatrix.cxx8
-rw-r--r--basegfx/test/basegfx2d.cxx17
2 files changed, 25 insertions, 0 deletions
diff --git a/basegfx/source/matrix/b2dhommatrix.cxx b/basegfx/source/matrix/b2dhommatrix.cxx
index adc984340b9a..4ec49e926e3e 100644
--- a/basegfx/source/matrix/b2dhommatrix.cxx
+++ b/basegfx/source/matrix/b2dhommatrix.cxx
@@ -320,6 +320,14 @@ namespace basegfx
// no rotation and shear, copy scale values
rScale.setX(get(0, 0));
rScale.setY(get(1, 1));
+
+ // or is there?
+ if( rScale.getX() < 0 && rScale.getY() < 0 )
+ {
+ // there is - 180 degree rotated
+ rScale *= -1;
+ rRotate = 180*F_PI180;
+ }
}
else
{
diff --git a/basegfx/test/basegfx2d.cxx b/basegfx/test/basegfx2d.cxx
index d0251aae9013..005a9bb348e8 100644
--- a/basegfx/test/basegfx2d.cxx
+++ b/basegfx/test/basegfx2d.cxx
@@ -36,6 +36,7 @@
#include "cppunit/extensions/HelperMacros.h"
#include <basegfx/matrix/b2dhommatrix.hxx>
+#include <basegfx/matrix/b2dhommatrixtools.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <basegfx/curve/b2dcubicbezier.hxx>
@@ -927,6 +928,22 @@ public:
CPPUNIT_ASSERT_MESSAGE("decompose: error test I2", impDecomposeComposeTest(-fSX, fSY, tan(-fS), -fR));
CPPUNIT_ASSERT_MESSAGE("decompose: error test I3", impDecomposeComposeTest(fSX, -fSY, tan(-fS), -fR));
CPPUNIT_ASSERT_MESSAGE("decompose: error test I4", impDecomposeComposeTest(-fSX, -fSY, tan(-fS), -fR));
+
+ // cover special case of 180 degree rotation
+ B2DHomMatrix aTest=tools::createScaleShearXRotateTranslateB2DHomMatrix(
+ 6425,3938,
+ 0,
+ 180*F_PI180,
+ 10482,4921);
+ // decompose that matrix
+ B2DTuple aDScale;
+ B2DTuple aDTrans;
+ double fDRot;
+ double fDShX;
+ aTest.decompose(aDScale, aDTrans, fDRot, fDShX);
+ CPPUNIT_ASSERT_MESSAGE("decompose: error test J1", aDScale.getX() == 6425 && aDScale.getY() == 3938);
+ CPPUNIT_ASSERT_MESSAGE("decompose: error test J1", aDTrans.getX() == 10482 && aDTrans.getY() == 4921);
+ CPPUNIT_ASSERT_MESSAGE("decompose: error test J1", fDRot == 180*F_PI180);
}
// Change the following lines only, if you add, remove or rename