diff options
author | Kurt Zenker <kz@openoffice.org> | 2005-11-02 12:56:26 +0000 |
---|---|---|
committer | Kurt Zenker <kz@openoffice.org> | 2005-11-02 12:56:26 +0000 |
commit | 28abc01932c39e6e485f50273decf76494dc17e6 (patch) | |
tree | 90899e999e88ac80a270f01bc6fd1488029b95bb /basegfx/source/matrix | |
parent | 507a25b2141749c01423d882632bd28151a4e3b4 (diff) |
INTEGRATION: CWS canvas02 (1.9.2); FILE MERGED
2005/10/08 13:15:45 thb 1.9.2.3: RESYNC: (1.9-1.10); FILE MERGED
2005/08/22 15:30:17 thb 1.9.2.2: #i10000# Added comment string
2005/07/28 10:10:18 thb 1.9.2.1: Join from cws_src680_aw024: #i48939# and new rendering subsystem need AW's clipper changes
Diffstat (limited to 'basegfx/source/matrix')
-rw-r--r-- | basegfx/source/matrix/b2dhommatrix.cxx | 107 |
1 files changed, 80 insertions, 27 deletions
diff --git a/basegfx/source/matrix/b2dhommatrix.cxx b/basegfx/source/matrix/b2dhommatrix.cxx index 7330f7716321..da58918fb7a0 100644 --- a/basegfx/source/matrix/b2dhommatrix.cxx +++ b/basegfx/source/matrix/b2dhommatrix.cxx @@ -4,9 +4,9 @@ * * $RCSfile: b2dhommatrix.cxx,v $ * - * $Revision: 1.10 $ + * $Revision: 1.11 $ * - * last change: $Author: rt $ $Date: 2005-09-07 20:42:20 $ + * last change: $Author: kz $ $Date: 2005-11-02 13:56:26 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -57,6 +57,10 @@ #include <basegfx/tuple/b2dtuple.hxx> #endif +#ifndef _BGFX_VECTOR_B2DVECTOR_HXX +#include <basegfx/vector/b2dvector.hxx> +#endif + namespace basegfx { class Impl2DHomMatrix : public ::basegfx::internal::ImplHomMatrixTemplate< 3 > @@ -122,6 +126,11 @@ namespace basegfx mpM->set(nRow, nColumn, fValue); } + bool B2DHomMatrix::isLastLineDefault() const + { + return mpM->isLastLineDefault(); + } + bool B2DHomMatrix::isIdentity() const { if(mpM == &get2DIdentityMatrix()) @@ -313,6 +322,8 @@ namespace basegfx } else { + // TODO(P1): Maybe use glibc's sincos here (though + // that's kinda non-portable...) fSin = sin(fRadiant); fCos = cos(fRadiant); } @@ -396,39 +407,81 @@ namespace basegfx if(!mpM->isLastLineDefault()) return false; - // If determinant is zero, decomposition is not possible - if(0.0 == mpM->doDeterminant()) - return false; - - // copy 2x2 matrix and translate vector to 3x3 matrix - ::basegfx::B3DHomMatrix a3DHomMat; + // test for rotation and shear + if(::basegfx::fTools::equalZero(get(0, 1)) && ::basegfx::fTools::equalZero(get(1, 0))) + { + // no rotation and shear, direct value extraction + rRotate = rShearX = 0.0; - a3DHomMat.set(0, 0, get(0, 0)); - a3DHomMat.set(0, 1, get(0, 1)); - a3DHomMat.set(1, 0, get(1, 0)); - a3DHomMat.set(1, 1, get(1, 1)); - a3DHomMat.set(0, 3, get(0, 2)); - a3DHomMat.set(1, 3, get(1, 2)); + // copy scale values + rScale.setX(get(0, 0)); + rScale.setY(get(1, 1)); - ::basegfx::B3DTuple r3DScale, r3DTranslate, r3DRotate, r3DShear; + // copy translation values + rTranslate.setX(get(0, 2)); + rTranslate.setY(get(1, 2)); - if(a3DHomMat.decompose(r3DScale, r3DTranslate, r3DRotate, r3DShear)) + return true; + } + else { - // copy scale values - rScale.setX(r3DScale.getX()); - rScale.setY(r3DScale.getY()); + // test if shear is zero. That's the case, if the unit vectors in the matrix + // are perpendicular -> scalar is zero + const ::basegfx::B2DVector aUnitVecX(get(0, 0), get(1, 0)); + const ::basegfx::B2DVector aUnitVecY(get(0, 1), get(1, 1)); - // copy shear - rShearX = r3DShear.getX(); + if(::basegfx::fTools::equalZero(aUnitVecX.scalar(aUnitVecY))) + { + // calculate rotation + rRotate = atan2(aUnitVecX.getY(), aUnitVecX.getX()); - // copy rotate - rRotate = r3DRotate.getZ(); + // calculate scale values + rScale.setX(aUnitVecX.getLength()); + rScale.setY(aUnitVecY.getLength()); - // copy translate - rTranslate.setX(r3DTranslate.getX()); - rTranslate.setY(r3DTranslate.getY()); + // copy translation values + rTranslate.setX(get(0, 2)); + rTranslate.setY(get(1, 2)); - return true; + return true; + } + else + { + // If determinant is zero, decomposition is not possible + if(0.0 == mpM->doDeterminant()) + return false; + + // copy 2x2 matrix and translate vector to 3x3 matrix + ::basegfx::B3DHomMatrix a3DHomMat; + + a3DHomMat.set(0, 0, get(0, 0)); + a3DHomMat.set(0, 1, get(0, 1)); + a3DHomMat.set(1, 0, get(1, 0)); + a3DHomMat.set(1, 1, get(1, 1)); + a3DHomMat.set(0, 3, get(0, 2)); + a3DHomMat.set(1, 3, get(1, 2)); + + ::basegfx::B3DTuple r3DScale, r3DTranslate, r3DRotate, r3DShear; + + if(a3DHomMat.decompose(r3DScale, r3DTranslate, r3DRotate, r3DShear)) + { + // copy scale values + rScale.setX(r3DScale.getX()); + rScale.setY(r3DScale.getY()); + + // copy shear + rShearX = r3DShear.getX(); + + // copy rotate + rRotate = r3DRotate.getZ(); + + // copy translate + rTranslate.setX(r3DTranslate.getX()); + rTranslate.setY(r3DTranslate.getY()); + + return true; + } + } } return false; |