summaryrefslogtreecommitdiff
path: root/basegfx/source/vector
diff options
context:
space:
mode:
Diffstat (limited to 'basegfx/source/vector')
-rw-r--r--basegfx/source/vector/b2dvector.cxx222
-rw-r--r--basegfx/source/vector/b2ivector.cxx162
-rw-r--r--basegfx/source/vector/b3dvector.cxx118
-rw-r--r--basegfx/source/vector/b3ivector.cxx54
-rw-r--r--basegfx/source/vector/makefile.mk46
5 files changed, 602 insertions, 0 deletions
diff --git a/basegfx/source/vector/b2dvector.cxx b/basegfx/source/vector/b2dvector.cxx
new file mode 100644
index 000000000000..ad11f717fa2d
--- /dev/null
+++ b/basegfx/source/vector/b2dvector.cxx
@@ -0,0 +1,222 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_basegfx.hxx"
+#include <basegfx/vector/b2dvector.hxx>
+#include <basegfx/matrix/b2dhommatrix.hxx>
+#include <basegfx/numeric/ftools.hxx>
+
+namespace basegfx
+{
+ B2DVector& B2DVector::normalize()
+ {
+ double fLen(scalar(*this));
+
+ if(fTools::equalZero(fLen))
+ {
+ mfX = 0.0;
+ mfY = 0.0;
+ }
+ else
+ {
+ const double fOne(1.0);
+
+ if(!fTools::equal(fOne, fLen))
+ {
+ fLen = sqrt(fLen);
+
+ if(!fTools::equalZero(fLen))
+ {
+ mfX /= fLen;
+ mfY /= fLen;
+ }
+ }
+ }
+
+ return *this;
+ }
+
+ B2DVector& B2DVector::operator=( const B2DTuple& rVec )
+ {
+ mfX = rVec.getX();
+ mfY = rVec.getY();
+ return *this;
+ }
+
+
+ double B2DVector::getLength() const
+ {
+ if(fTools::equalZero(mfX))
+ {
+ return fabs(mfY);
+ }
+ else if(fTools::equalZero(mfY))
+ {
+ return fabs(mfX);
+ }
+
+ return hypot( mfX, mfY );
+ }
+
+ double B2DVector::scalar( const B2DVector& rVec ) const
+ {
+ return((mfX * rVec.mfX) + (mfY * rVec.mfY));
+ }
+
+ double B2DVector::cross( const B2DVector& rVec ) const
+ {
+ return(mfX * rVec.getY() - mfY * rVec.getX());
+ }
+
+ double B2DVector::angle( const B2DVector& rVec ) const
+ {
+ return atan2(mfX * rVec.getY() - mfY * rVec.getX(),
+ mfX * rVec.getX() + mfY * rVec.getY());
+ }
+
+ const B2DVector& B2DVector::getEmptyVector()
+ {
+ return (const B2DVector&) B2DTuple::getEmptyTuple();
+ }
+
+ B2DVector& B2DVector::operator*=( const B2DHomMatrix& rMat )
+ {
+ const double fTempX( rMat.get(0,0)*mfX +
+ rMat.get(0,1)*mfY );
+ const double fTempY( rMat.get(1,0)*mfX +
+ rMat.get(1,1)*mfY );
+ mfX = fTempX;
+ mfY = fTempY;
+
+ return *this;
+ }
+
+ B2DVector& B2DVector::setLength(double fLen)
+ {
+ double fLenNow(scalar(*this));
+
+ if(!fTools::equalZero(fLenNow))
+ {
+ const double fOne(10.0);
+
+ if(!fTools::equal(fOne, fLenNow))
+ {
+ fLen /= sqrt(fLenNow);
+ }
+
+ mfX *= fLen;
+ mfY *= fLen;
+ }
+
+ return *this;
+ }
+
+ bool B2DVector::isNormalized() const
+ {
+ const double fOne(1.0);
+ const double fScalar(scalar(*this));
+
+ return fTools::equal(fOne, fScalar);
+ }
+
+ bool areParallel( const B2DVector& rVecA, const B2DVector& rVecB )
+ {
+ const double fValA(rVecA.getX() * rVecB.getY());
+ const double fValB(rVecA.getY() * rVecB.getX());
+
+ return fTools::equal(fValA, fValB);
+ }
+
+ B2VectorOrientation getOrientation( const B2DVector& rVecA, const B2DVector& rVecB )
+ {
+ double fVal(rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX());
+
+ if(fTools::equalZero(fVal))
+ {
+ return ORIENTATION_NEUTRAL;
+ }
+
+ if(fVal > 0.0)
+ {
+ return ORIENTATION_POSITIVE;
+ }
+ else
+ {
+ return ORIENTATION_NEGATIVE;
+ }
+ }
+
+ B2DVector getPerpendicular( const B2DVector& rNormalizedVec )
+ {
+ B2DVector aPerpendicular(-rNormalizedVec.getY(), rNormalizedVec.getX());
+ return aPerpendicular;
+ }
+
+ B2DVector getNormalizedPerpendicular( const B2DVector& rVec )
+ {
+ B2DVector aPerpendicular(rVec);
+ aPerpendicular.normalize();
+ const double aTemp(-aPerpendicular.getY());
+ aPerpendicular.setY(aPerpendicular.getX());
+ aPerpendicular.setX(aTemp);
+ return aPerpendicular;
+ }
+
+ B2DVector operator*( const B2DHomMatrix& rMat, const B2DVector& rVec )
+ {
+ B2DVector aRes( rVec );
+ return aRes*=rMat;
+ }
+
+ B2VectorContinuity getContinuity(const B2DVector& rBackVector, const B2DVector& rForwardVector )
+ {
+ if(rBackVector.equalZero() || rForwardVector.equalZero())
+ {
+ return CONTINUITY_NONE;
+ }
+
+ if(fTools::equal(rBackVector.getX(), -rForwardVector.getX()) && fTools::equal(rBackVector.getY(), -rForwardVector.getY()))
+ {
+ // same direction and same length -> C2
+ return CONTINUITY_C2;
+ }
+
+ if(areParallel(rBackVector, rForwardVector) && rBackVector.scalar(rForwardVector) < 0.0)
+ {
+ // parallel and opposite direction -> C1
+ return CONTINUITY_C1;
+ }
+
+ return CONTINUITY_NONE;
+ }
+} // end of namespace basegfx
+
+// eof
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basegfx/source/vector/b2ivector.cxx b/basegfx/source/vector/b2ivector.cxx
new file mode 100644
index 000000000000..744bf8cf2ca0
--- /dev/null
+++ b/basegfx/source/vector/b2ivector.cxx
@@ -0,0 +1,162 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_basegfx.hxx"
+#include <basegfx/vector/b2ivector.hxx>
+#include <basegfx/matrix/b2dhommatrix.hxx>
+#include <basegfx/numeric/ftools.hxx>
+
+namespace basegfx
+{
+ B2IVector& B2IVector::operator=( const ::basegfx::B2ITuple& rVec )
+ {
+ mnX = rVec.getX();
+ mnY = rVec.getY();
+ return *this;
+ }
+
+
+ double B2IVector::getLength() const
+ {
+ return hypot( mnX, mnY );
+ }
+
+ double B2IVector::scalar( const B2IVector& rVec ) const
+ {
+ return((mnX * rVec.mnX) + (mnY * rVec.mnY));
+ }
+
+ double B2IVector::cross( const B2IVector& rVec ) const
+ {
+ return(mnX * rVec.getY() - mnY * rVec.getX());
+ }
+
+ double B2IVector::angle( const B2IVector& rVec ) const
+ {
+ return atan2(double( mnX * rVec.getY() - mnY * rVec.getX()),
+ double( mnX * rVec.getX() + mnY * rVec.getY()));
+ }
+
+ const B2IVector& B2IVector::getEmptyVector()
+ {
+ return (const B2IVector&) ::basegfx::B2ITuple::getEmptyTuple();
+ }
+
+ B2IVector& B2IVector::operator*=( const B2DHomMatrix& rMat )
+ {
+ mnX = fround( rMat.get(0,0)*mnX +
+ rMat.get(0,1)*mnY );
+ mnY = fround( rMat.get(1,0)*mnX +
+ rMat.get(1,1)*mnY );
+
+ return *this;
+ }
+
+ B2IVector& B2IVector::setLength(double fLen)
+ {
+ double fLenNow(scalar(*this));
+
+ if(!::basegfx::fTools::equalZero(fLenNow))
+ {
+ const double fOne(10.0);
+
+ if(!::basegfx::fTools::equal(fOne, fLenNow))
+ {
+ fLen /= sqrt(fLenNow);
+ }
+
+ mnX = fround( mnX*fLen );
+ mnY = fround( mnY*fLen );
+ }
+
+ return *this;
+ }
+
+ bool areParallel( const B2IVector& rVecA, const B2IVector& rVecB )
+ {
+ double fVal(rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX());
+ return ::basegfx::fTools::equalZero(fVal);
+ }
+
+ B2VectorOrientation getOrientation( const B2IVector& rVecA, const B2IVector& rVecB )
+ {
+ double fVal(rVecA.getX() * rVecB.getY() - rVecA.getY() * rVecB.getX());
+
+ if(fVal > 0.0)
+ {
+ return ORIENTATION_POSITIVE;
+ }
+
+ if(fVal < 0.0)
+ {
+ return ORIENTATION_NEGATIVE;
+ }
+
+ return ORIENTATION_NEUTRAL;
+ }
+
+ B2IVector getPerpendicular( const B2IVector& rNormalizedVec )
+ {
+ B2IVector aPerpendicular(-rNormalizedVec.getY(), rNormalizedVec.getX());
+ return aPerpendicular;
+ }
+
+ B2IVector operator*( const B2DHomMatrix& rMat, const B2IVector& rVec )
+ {
+ B2IVector aRes( rVec );
+ return aRes*=rMat;
+ }
+
+ B2VectorContinuity getContinuity(const B2IVector& rBackVector, const B2IVector& rForwardVector )
+ {
+ B2VectorContinuity eRetval(CONTINUITY_NONE);
+
+ if(!rBackVector.equalZero() && !rForwardVector.equalZero())
+ {
+ const B2IVector aInverseForwardVector(-rForwardVector.getX(), -rForwardVector.getY());
+
+ if(rBackVector == aInverseForwardVector)
+ {
+ // same direction and same length -> C2
+ eRetval = CONTINUITY_C2;
+ }
+ else if(areParallel(rBackVector, aInverseForwardVector))
+ {
+ // same direction -> C1
+ eRetval = CONTINUITY_C1;
+ }
+ }
+
+ return eRetval;
+ }
+} // end of namespace basegfx
+
+// eof
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basegfx/source/vector/b3dvector.cxx b/basegfx/source/vector/b3dvector.cxx
new file mode 100644
index 000000000000..67a7ef1d2215
--- /dev/null
+++ b/basegfx/source/vector/b3dvector.cxx
@@ -0,0 +1,118 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_basegfx.hxx"
+#include <basegfx/vector/b3dvector.hxx>
+#include <basegfx/matrix/b3dhommatrix.hxx>
+
+//////////////////////////////////////////////////////////////////////////////
+
+namespace basegfx
+{
+ B3DVector& B3DVector::normalize()
+ {
+ double fLen(scalar(*this));
+
+ if(!::basegfx::fTools::equalZero(fLen))
+ {
+ const double fOne(1.0);
+
+ if(!::basegfx::fTools::equal(fOne, fLen))
+ {
+ fLen = sqrt(fLen);
+
+ if(!::basegfx::fTools::equalZero(fLen))
+ {
+ mfX /= fLen;
+ mfY /= fLen;
+ mfZ /= fLen;
+ }
+ }
+ }
+
+ return *this;
+ }
+
+ B3DVector B3DVector::getPerpendicular(const B3DVector& rNormalizedVec) const
+ {
+ B3DVector aNew(*this);
+ aNew = cross(aNew, rNormalizedVec);
+ aNew.normalize();
+ return aNew;
+ }
+
+ B3DVector B3DVector::getProjectionOnPlane(const B3DVector& rNormalizedPlane) const
+ {
+ B3DVector aNew(*this);
+ aNew = cross(aNew, rNormalizedPlane);
+ aNew = cross(aNew, rNormalizedPlane);
+
+ aNew.mfX = mfX - aNew.mfX;
+ aNew.mfY = mfY - aNew.mfY;
+ aNew.mfZ = mfZ - aNew.mfZ;
+
+ return aNew;
+ }
+
+ B3DVector& B3DVector::operator*=( const ::basegfx::B3DHomMatrix& rMat )
+ {
+ const double fTempX( rMat.get(0,0)*mfX + rMat.get(0,1)*mfY + rMat.get(0,2)*mfZ );
+ const double fTempY( rMat.get(1,0)*mfX + rMat.get(1,1)*mfY + rMat.get(1,2)*mfZ );
+ const double fTempZ( rMat.get(2,0)*mfX + rMat.get(2,1)*mfY + rMat.get(2,2)*mfZ );
+ mfX = fTempX;
+ mfY = fTempY;
+ mfZ = fTempZ;
+
+ return *this;
+ }
+
+ B3DVector operator*( const ::basegfx::B3DHomMatrix& rMat, const B3DVector& rVec )
+ {
+ B3DVector aRes( rVec );
+ return aRes*=rMat;
+ }
+
+ bool areParallel( const B3DVector& rVecA, const B3DVector& rVecB )
+ {
+ // i think fastest is to compare relations, need no square or division
+ if(!fTools::equal(rVecA.getX() * rVecB.getY(), rVecA.getY() * rVecB.getX()))
+ return false;
+
+ if(!fTools::equal(rVecA.getX() * rVecB.getZ(), rVecA.getZ() * rVecB.getX()))
+ return false;
+
+ return (fTools::equal(rVecA.getY() * rVecB.getZ(), rVecA.getZ() * rVecB.getY()));
+ }
+
+} // end of namespace basegfx
+
+//////////////////////////////////////////////////////////////////////////////
+// eof
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basegfx/source/vector/b3ivector.cxx b/basegfx/source/vector/b3ivector.cxx
new file mode 100644
index 000000000000..2966a11c6921
--- /dev/null
+++ b/basegfx/source/vector/b3ivector.cxx
@@ -0,0 +1,54 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_basegfx.hxx"
+#include <basegfx/vector/b3ivector.hxx>
+#include <basegfx/matrix/b3dhommatrix.hxx>
+
+namespace basegfx
+{
+ B3IVector& B3IVector::operator*=( const B3DHomMatrix& rMat )
+ {
+ mnX = fround( rMat.get(0,0)*mnX + rMat.get(0,1)*mnY + rMat.get(0,2)*mnZ );
+ mnY = fround( rMat.get(1,0)*mnX + rMat.get(1,1)*mnY + rMat.get(1,2)*mnZ );
+ mnZ = fround( rMat.get(2,0)*mnX + rMat.get(2,1)*mnY + rMat.get(2,2)*mnZ );
+
+ return *this;
+ }
+
+ B3IVector operator*( const B3DHomMatrix& rMat, const B3IVector& rVec )
+ {
+ B3IVector aRes( rVec );
+ return aRes*=rMat;
+ }
+} // end of namespace basegfx
+
+// eof
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/basegfx/source/vector/makefile.mk b/basegfx/source/vector/makefile.mk
new file mode 100644
index 000000000000..2393e3e35ee2
--- /dev/null
+++ b/basegfx/source/vector/makefile.mk
@@ -0,0 +1,46 @@
+#*************************************************************************
+#
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+#
+# Copyright 2000, 2010 Oracle and/or its affiliates.
+#
+# OpenOffice.org - a multi-platform office productivity suite
+#
+# This file is part of OpenOffice.org.
+#
+# OpenOffice.org is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License version 3
+# only, as published by the Free Software Foundation.
+#
+# OpenOffice.org is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Lesser General Public License version 3 for more details
+# (a copy is included in the LICENSE file that accompanied this code).
+#
+# You should have received a copy of the GNU Lesser General Public License
+# version 3 along with OpenOffice.org. If not, see
+# <http://www.openoffice.org/license.html>
+# for a copy of the LGPLv3 License.
+#
+#*************************************************************************
+
+PRJ=..$/..
+PRJNAME=basegfx
+TARGET=vector
+
+# --- Settings ----------------------------------
+
+.INCLUDE : settings.mk
+
+# --- Files -------------------------------------
+
+SLOFILES= \
+ $(SLO)$/b2dvector.obj \
+ $(SLO)$/b3dvector.obj \
+ $(SLO)$/b2ivector.obj \
+ $(SLO)$/b3ivector.obj
+
+# --- Targets ----------------------------------
+
+.INCLUDE : target.mk