summaryrefslogtreecommitdiff
path: root/basegfx/source/matrix/b2dhommatrix.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'basegfx/source/matrix/b2dhommatrix.cxx')
-rw-r--r--basegfx/source/matrix/b2dhommatrix.cxx493
1 files changed, 245 insertions, 248 deletions
diff --git a/basegfx/source/matrix/b2dhommatrix.cxx b/basegfx/source/matrix/b2dhommatrix.cxx
index d2175b502db3..ae36adfd72f9 100644
--- a/basegfx/source/matrix/b2dhommatrix.cxx
+++ b/basegfx/source/matrix/b2dhommatrix.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: b2dhommatrix.cxx,v $
*
- * $Revision: 1.4 $
+ * $Revision: 1.5 $
*
- * last change: $Author: thb $ $Date: 2003-11-10 15:10:57 $
+ * last change: $Author: aw $ $Date: 2003-11-28 11:18:02 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -81,336 +81,333 @@
namespace basegfx
{
- namespace matrix
+ class Impl2DHomMatrix : public ::basegfx::internal::ImplHomMatrixTemplate< 3 >
{
- class Impl2DHomMatrix : public ::basegfx::internal::ImplHomMatrixTemplate< 3 >
- {
- };
+ };
- static Impl2DHomMatrix& get2DIdentityMatrix()
- {
- static Impl2DHomMatrix maStatic2DIdentityHomMatrix;
- return maStatic2DIdentityHomMatrix;
- }
+ static Impl2DHomMatrix& get2DIdentityMatrix()
+ {
+ static Impl2DHomMatrix maStatic2DIdentityHomMatrix;
+ return maStatic2DIdentityHomMatrix;
+ }
- void B2DHomMatrix::implPrepareChange()
+ void B2DHomMatrix::implPrepareChange()
+ {
+ if(mpM->getRefCount())
{
- if(mpM->getRefCount())
- {
- mpM->decRefCount();
- mpM = new Impl2DHomMatrix(*mpM);
- }
+ mpM->decRefCount();
+ mpM = new Impl2DHomMatrix(*mpM);
}
+ }
- B2DHomMatrix::B2DHomMatrix()
- : mpM(&get2DIdentityMatrix())
- {
- mpM->incRefCount();
- }
+ B2DHomMatrix::B2DHomMatrix()
+ : mpM(&get2DIdentityMatrix())
+ {
+ mpM->incRefCount();
+ }
- B2DHomMatrix::B2DHomMatrix(const B2DHomMatrix& rMat)
- : mpM(rMat.mpM)
- {
- mpM->incRefCount();
- }
+ B2DHomMatrix::B2DHomMatrix(const B2DHomMatrix& rMat)
+ : mpM(rMat.mpM)
+ {
+ mpM->incRefCount();
+ }
- B2DHomMatrix::~B2DHomMatrix()
- {
- if(mpM->getRefCount())
- mpM->decRefCount();
- else
- delete mpM;
- }
+ B2DHomMatrix::~B2DHomMatrix()
+ {
+ if(mpM->getRefCount())
+ mpM->decRefCount();
+ else
+ delete mpM;
+ }
- B2DHomMatrix& B2DHomMatrix::operator=(const B2DHomMatrix& rMat)
- {
- if(mpM->getRefCount())
- mpM->decRefCount();
- else
- delete mpM;
+ B2DHomMatrix& B2DHomMatrix::operator=(const B2DHomMatrix& rMat)
+ {
+ if(mpM->getRefCount())
+ mpM->decRefCount();
+ else
+ delete mpM;
- mpM = rMat.mpM;
- mpM->incRefCount();
+ mpM = rMat.mpM;
+ mpM->incRefCount();
- return *this;
- }
+ return *this;
+ }
- double B2DHomMatrix::get(sal_uInt16 nRow, sal_uInt16 nColumn) const
- {
- return mpM->get(nRow, nColumn);
- }
+ double B2DHomMatrix::get(sal_uInt16 nRow, sal_uInt16 nColumn) const
+ {
+ return mpM->get(nRow, nColumn);
+ }
- void B2DHomMatrix::set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue)
- {
- implPrepareChange();
- mpM->set(nRow, nColumn, fValue);
- }
+ void B2DHomMatrix::set(sal_uInt16 nRow, sal_uInt16 nColumn, double fValue)
+ {
+ implPrepareChange();
+ mpM->set(nRow, nColumn, fValue);
+ }
- sal_Bool B2DHomMatrix::isIdentity() const
- {
- if(mpM == &get2DIdentityMatrix())
- return sal_True;
+ sal_Bool B2DHomMatrix::isIdentity() const
+ {
+ if(mpM == &get2DIdentityMatrix())
+ return sal_True;
- return mpM->isIdentity();
- }
+ return mpM->isIdentity();
+ }
- void B2DHomMatrix::identity()
+ void B2DHomMatrix::identity()
+ {
+ if(mpM->getRefCount())
+ mpM->decRefCount();
+ else
+ delete mpM;
+
+ mpM = &get2DIdentityMatrix();
+ mpM->incRefCount();
+ }
+
+ sal_Bool B2DHomMatrix::isInvertible() const
+ {
+ return mpM->isInvertible();
+ }
+
+ sal_Bool B2DHomMatrix::invert()
+ {
+ Impl2DHomMatrix aWork(*mpM);
+ sal_uInt16* pIndex = new sal_uInt16[mpM->getEdgeLength()];
+ sal_Int16 nParity;
+
+ if(aWork.ludcmp(pIndex, nParity))
{
- if(mpM->getRefCount())
- mpM->decRefCount();
- else
- delete mpM;
+ implPrepareChange();
+ mpM->doInvert(aWork, pIndex);
+ delete pIndex;
- mpM = &get2DIdentityMatrix();
- mpM->incRefCount();
+ return sal_True;
}
- sal_Bool B2DHomMatrix::isInvertible() const
+ delete pIndex;
+ return sal_False;
+ }
+
+ sal_Bool B2DHomMatrix::isNormalized() const
+ {
+ return mpM->isNormalized();
+ }
+
+ void B2DHomMatrix::normalize()
+ {
+ if(!mpM->isNormalized())
{
- return mpM->isInvertible();
+ implPrepareChange();
+ mpM->doNormalize();
}
+ }
- sal_Bool B2DHomMatrix::invert()
- {
- Impl2DHomMatrix aWork(*mpM);
- sal_uInt16* pIndex = new sal_uInt16[mpM->getEdgeLength()];
- sal_Int16 nParity;
+ double B2DHomMatrix::determinant() const
+ {
+ return mpM->doDeterminant();
+ }
- if(aWork.ludcmp(pIndex, nParity))
- {
- implPrepareChange();
- mpM->doInvert(aWork, pIndex);
- delete pIndex;
+ double B2DHomMatrix::trace() const
+ {
+ return mpM->doTrace();
+ }
- return sal_True;
- }
+ void B2DHomMatrix::transpose()
+ {
+ implPrepareChange();
+ mpM->doTranspose();
+ }
- delete pIndex;
- return sal_False;
- }
+ B2DHomMatrix& B2DHomMatrix::operator+=(const B2DHomMatrix& rMat)
+ {
+ implPrepareChange();
+ mpM->doAddMatrix(*rMat.mpM);
- sal_Bool B2DHomMatrix::isNormalized() const
- {
- return mpM->isNormalized();
- }
+ return *this;
+ }
- void B2DHomMatrix::normalize()
- {
- if(!mpM->isNormalized())
- {
- implPrepareChange();
- mpM->doNormalize();
- }
- }
+ B2DHomMatrix& B2DHomMatrix::operator-=(const B2DHomMatrix& rMat)
+ {
+ implPrepareChange();
+ mpM->doSubMatrix(*rMat.mpM);
- double B2DHomMatrix::determinant() const
- {
- return mpM->doDeterminant();
- }
+ return *this;
+ }
- double B2DHomMatrix::trace() const
- {
- return mpM->doTrace();
- }
+ B2DHomMatrix& B2DHomMatrix::operator*=(double fValue)
+ {
+ const double fOne(1.0);
- void B2DHomMatrix::transpose()
+ if(!::basegfx::fTools::equal(fOne, fValue))
{
implPrepareChange();
- mpM->doTranspose();
+ mpM->doMulMatrix(fValue);
}
- B2DHomMatrix& B2DHomMatrix::operator+=(const B2DHomMatrix& rMat)
- {
- implPrepareChange();
- mpM->doAddMatrix(*rMat.mpM);
+ return *this;
+ }
- return *this;
- }
+ B2DHomMatrix& B2DHomMatrix::operator/=(double fValue)
+ {
+ const double fOne(1.0);
- B2DHomMatrix& B2DHomMatrix::operator-=(const B2DHomMatrix& rMat)
+ if(!::basegfx::fTools::equal(fOne, fValue))
{
implPrepareChange();
- mpM->doSubMatrix(*rMat.mpM);
-
- return *this;
+ mpM->doMulMatrix(1.0 / fValue);
}
- B2DHomMatrix& B2DHomMatrix::operator*=(double fValue)
- {
- const double fOne(1.0);
-
- if(!::basegfx::numeric::fTools::equal(fOne, fValue))
- {
- implPrepareChange();
- mpM->doMulMatrix(fValue);
- }
+ return *this;
+ }
- return *this;
- }
-
- B2DHomMatrix& B2DHomMatrix::operator/=(double fValue)
+ B2DHomMatrix& B2DHomMatrix::operator*=(const B2DHomMatrix& rMat)
+ {
+ if(!rMat.isIdentity())
{
- const double fOne(1.0);
-
- if(!::basegfx::numeric::fTools::equal(fOne, fValue))
- {
- implPrepareChange();
- mpM->doMulMatrix(1.0 / fValue);
- }
-
- return *this;
+ implPrepareChange();
+ mpM->doMulMatrix(*rMat.mpM);
}
- B2DHomMatrix& B2DHomMatrix::operator*=(const B2DHomMatrix& rMat)
- {
- if(!rMat.isIdentity())
- {
- implPrepareChange();
- mpM->doMulMatrix(*rMat.mpM);
- }
+ return *this;
+ }
- return *this;
- }
+ sal_Bool B2DHomMatrix::operator==(const B2DHomMatrix& rMat) const
+ {
+ if(mpM == rMat.mpM)
+ return sal_True;
- sal_Bool B2DHomMatrix::operator==(const B2DHomMatrix& rMat) const
- {
- if(mpM == rMat.mpM)
- return sal_True;
+ return mpM->isEqual(*rMat.mpM);
+ }
- return mpM->isEqual(*rMat.mpM);
- }
+ sal_Bool B2DHomMatrix::operator!=(const B2DHomMatrix& rMat) const
+ {
+ if(mpM == rMat.mpM)
+ return sal_False;
+
+ return !mpM->isEqual(*rMat.mpM);
+ }
- sal_Bool B2DHomMatrix::operator!=(const B2DHomMatrix& rMat) const
+ void B2DHomMatrix::rotate(double fRadiant)
+ {
+ if(!::basegfx::fTools::equalZero(fRadiant))
{
- if(mpM == rMat.mpM)
- return sal_False;
+ Impl2DHomMatrix aRotMat(get2DIdentityMatrix());
+ double fSin(sin(fRadiant));
+ double fCos(cos(fRadiant));
- return !mpM->isEqual(*rMat.mpM);
- }
+ aRotMat.set(0, 0, fCos);
+ aRotMat.set(1, 1, fCos);
+ aRotMat.set(1, 0, fSin);
+ aRotMat.set(0, 1, -fSin);
- void B2DHomMatrix::rotate(double fRadiant)
- {
- if(!::basegfx::numeric::fTools::equalZero(fRadiant))
- {
- Impl2DHomMatrix aRotMat(get2DIdentityMatrix());
- double fSin(sin(fRadiant));
- double fCos(cos(fRadiant));
-
- aRotMat.set(0, 0, fCos);
- aRotMat.set(1, 1, fCos);
- aRotMat.set(1, 0, fSin);
- aRotMat.set(0, 1, -fSin);
-
- implPrepareChange();
- mpM->doMulMatrix(aRotMat);
- }
+ implPrepareChange();
+ mpM->doMulMatrix(aRotMat);
}
+ }
- void B2DHomMatrix::translate(double fX, double fY)
+ void B2DHomMatrix::translate(double fX, double fY)
+ {
+ if(!::basegfx::fTools::equalZero(fX) || !::basegfx::fTools::equalZero(fY))
{
- if(!::basegfx::numeric::fTools::equalZero(fX) || !::basegfx::numeric::fTools::equalZero(fY))
- {
- Impl2DHomMatrix aTransMat(get2DIdentityMatrix());
+ Impl2DHomMatrix aTransMat(get2DIdentityMatrix());
- aTransMat.set(0, 2, fX);
- aTransMat.set(1, 2, fY);
+ aTransMat.set(0, 2, fX);
+ aTransMat.set(1, 2, fY);
- implPrepareChange();
- mpM->doMulMatrix(aTransMat);
- }
+ implPrepareChange();
+ mpM->doMulMatrix(aTransMat);
}
+ }
- void B2DHomMatrix::scale(double fX, double fY)
- {
- const double fOne(1.0);
+ void B2DHomMatrix::scale(double fX, double fY)
+ {
+ const double fOne(1.0);
- if(!::basegfx::numeric::fTools::equal(fOne, fX) || !::basegfx::numeric::fTools::equal(fOne, fY))
- {
- Impl2DHomMatrix aScaleMat(get2DIdentityMatrix());
+ if(!::basegfx::fTools::equal(fOne, fX) || !::basegfx::fTools::equal(fOne, fY))
+ {
+ Impl2DHomMatrix aScaleMat(get2DIdentityMatrix());
- aScaleMat.set(0, 0, fX);
- aScaleMat.set(1, 1, fY);
+ aScaleMat.set(0, 0, fX);
+ aScaleMat.set(1, 1, fY);
- implPrepareChange();
- mpM->doMulMatrix(aScaleMat);
- }
+ implPrepareChange();
+ mpM->doMulMatrix(aScaleMat);
}
+ }
- void B2DHomMatrix::shearX(double fSx)
- {
- const double fOne(1.0);
+ void B2DHomMatrix::shearX(double fSx)
+ {
+ const double fOne(1.0);
- if(!::basegfx::numeric::fTools::equal(fOne, fSx))
- {
- Impl2DHomMatrix aShearXMat(get2DIdentityMatrix());
+ if(!::basegfx::fTools::equal(fOne, fSx))
+ {
+ Impl2DHomMatrix aShearXMat(get2DIdentityMatrix());
- aShearXMat.set(0, 1, fSx);
+ aShearXMat.set(0, 1, fSx);
- implPrepareChange();
- mpM->doMulMatrix(aShearXMat);
- }
+ implPrepareChange();
+ mpM->doMulMatrix(aShearXMat);
}
+ }
- void B2DHomMatrix::shearY(double fSy)
- {
- const double fOne(1.0);
+ void B2DHomMatrix::shearY(double fSy)
+ {
+ const double fOne(1.0);
- if(!::basegfx::numeric::fTools::equal(fOne, fSy))
- {
- Impl2DHomMatrix aShearYMat(get2DIdentityMatrix());
+ if(!::basegfx::fTools::equal(fOne, fSy))
+ {
+ Impl2DHomMatrix aShearYMat(get2DIdentityMatrix());
- aShearYMat.set(1, 0, fSy);
+ aShearYMat.set(1, 0, fSy);
- implPrepareChange();
- mpM->doMulMatrix(aShearYMat);
- }
+ implPrepareChange();
+ mpM->doMulMatrix(aShearYMat);
}
+ }
- // Decomposition
- sal_Bool B2DHomMatrix::decompose(tuple::B2DTuple& rScale, tuple::B2DTuple& rTranslate, double& rRotate, double& rShearX) const
- {
- // when perspective is used, decompose is not made here
- if(!mpM->isLastLineDefault())
- return sal_False;
-
- // If determinant is zero, decomposition is not possible
- if(0.0 == mpM->doDeterminant())
- return sal_False;
+ // Decomposition
+ sal_Bool B2DHomMatrix::decompose(B2DTuple& rScale, B2DTuple& rTranslate, double& rRotate, double& rShearX) const
+ {
+ // when perspective is used, decompose is not made here
+ if(!mpM->isLastLineDefault())
+ return sal_False;
- // copy 2x2 matrix and translate vector to 3x3 matrix
- ::basegfx::matrix::B3DHomMatrix a3DHomMat;
+ // If determinant is zero, decomposition is not possible
+ if(0.0 == mpM->doDeterminant())
+ return sal_False;
- 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, 2, get(0, 3));
- a3DHomMat.set(1, 2, get(1, 3));
+ // copy 2x2 matrix and translate vector to 3x3 matrix
+ ::basegfx::B3DHomMatrix a3DHomMat;
- ::basegfx::tuple::B3DTuple r3DScale, r3DTranslate, r3DRotate, r3DShear;
+ 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, 2, get(0, 3));
+ a3DHomMat.set(1, 2, get(1, 3));
- if(a3DHomMat.decompose(r3DScale, r3DTranslate, r3DRotate, r3DShear))
- {
- // copy scale values
- rScale.setX(r3DScale.getX());
- rScale.setY(r3DScale.getY());
+ ::basegfx::B3DTuple r3DScale, r3DTranslate, r3DRotate, r3DShear;
- // copy shear
- rShearX = r3DShear.getX();
+ if(a3DHomMat.decompose(r3DScale, r3DTranslate, r3DRotate, r3DShear))
+ {
+ // copy scale values
+ rScale.setX(r3DScale.getX());
+ rScale.setY(r3DScale.getY());
- // copy rotate
- rRotate = r3DRotate.getZ();
+ // copy shear
+ rShearX = r3DShear.getX();
- // copy translate
- rTranslate.setX(r3DTranslate.getX());
- rTranslate.setY(r3DTranslate.getY());
+ // copy rotate
+ rRotate = r3DRotate.getZ();
- return sal_True;
- }
+ // copy translate
+ rTranslate.setX(r3DTranslate.getX());
+ rTranslate.setY(r3DTranslate.getY());
- return sal_False;
+ return sal_True;
}
- } // end of namespace matrix
+
+ return sal_False;
+ }
} // end of namespace basegfx
// eof